Fix output of the WYSIWYG plugin - mostly invisible plugin calls, also failure to link on each hotword occurence
Foncierpedia request #5813, #5995
Based on Tiki issue #6551 patch. CKEditor surprinsingly apparently does not support being given the content in 2 different formats without the tiny hack in tiki-ckeditor.js.
Index: MERN/lib/ckeditor_tiki/tiki-ckeditor.js
===================================================================
--- MERN.orig/lib/ckeditor_tiki/tiki-ckeditor.js
+++ MERN/lib/ckeditor_tiki/tiki-ckeditor.js
@@ -207,6 +207,7 @@ $.fn.wysiwygPlugin = function (execution
 							return;
 						}
 
+						$this.html($this.data("source"));
 						CKEDITOR.replace($this.attr("id"), ckoption);
 						CKEDITOR.on("instanceReady", function (event) {
 							// close others
Index: MERN/lib/wiki-plugins/wikiplugin_wysiwyg.php
===================================================================
--- MERN.orig/lib/wiki-plugins/wikiplugin_wysiwyg.php
+++ MERN/lib/wiki-plugins/wikiplugin_wysiwyg.php
@@ -82,13 +82,10 @@ function wikiplugin_wysiwyg($data, $para
 	} else {
 		$is_html = true;
 	}
-	$html = TikiLib::lib('edit')->parseToWysiwyg( $data, true, $is_html, array('page' => $sourcepage) ); // Les plugins tels que DIV à l'intérieur du plugin ne sont pas analysés ou s'affichent comme vides (bogue #6551).
-	//$html = TikiLib::lib('tiki')->parse_data($data, array('is_html' => $is_html)); // Voir https://sourceforge.net/p/tikiwiki/mailman/message/35872294/
 
-	// Sert seulement à populer FOOTNOTEAREA
 	$subContext = new WikiParser_Context_PluginCall('wysiwyg', 'body');
 	$content = new WikiParser_Parsable($data, $subContext, $context);
-	$content->parse(array('is_html' => $is_html));
+	$visibleHTML = $content->parse(array('is_html' => $is_html));
 	
 	if (TikiLib::lib('tiki')->user_has_perm_on_object( $user, $sourcepage, 'wiki page', 'tiki_p_edit')) {
 		$class = "wp_wysiwyg";
@@ -112,7 +109,10 @@ function wikiplugin_wysiwyg($data, $para
 		}
 		$namespace = htmlspecialchars($namespace);
 
-		$html = "<div id='$exec_key' class='{$class}'$style data-initial='$namespace' data-html='{$params['use_html']}'>" . $html . '</div>';
+		// Re-parse source for WYSIWYG edition. Pass it via an HTML data attribute.
+		// This parse could be done via AJAX for better performance.
+		$editableSource = TikiLib::lib('edit')->parseToWysiwyg( $data, true, $is_html, array('page' => $sourcepage) ); // Not suitable for display. Les plugins tels que DIV à l'intérieur du plugin ne sont pas analysés ou s'affichent comme vides (bogue #6551).
+		$visibleHTML = "<div id='$exec_key' class='{$class}'$style data-initial='$namespace' data-html='{$params['use_html']}' data-source='" . smarty_modifier_escape($editableSource, 'attr') . "'>" . $visibleHTML . '</div>';
 
 		$js = '$("#' . $exec_key . '").wysiwygPlugin("' . $execution . '", "' . $sourcepage . '", ' . $ckoption . ');';
 		if (empty($wikiplugin_included_page)) { // Contourner bogue #6476 en attendant Tiki 18
@@ -121,7 +121,7 @@ function wikiplugin_wysiwyg($data, $para
 				->add_jq_onready($js);
 		}
 	}
-	return $html;
+	return $visibleHTML;
 
 }
 
