You are here: Foswiki>Tasks Web>Item10107 (05 Jul 2015, GeorgeClark)Edit Attach

Item10107: WYSIWYG editor protects macros inside tags by inserting spans, which then breaks the enclosing tag.

Priority: Normal
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: WysiwygPlugin
Branches: Release01x01 trunk master
Reported By: BrianMathis
Waiting For:
Last Change By: GeorgeClark
In some cases the WYSIWYG editor is incorrectly replacing HTML entities.

  • From a default Foswiki install (1.1.2), browse to WebPreferences
  • Take note of text and formatting for "web-specific background color, current color"
  • Edit page with WYSIWYG editor. Change something (or not), then save.

Result: Above noted text has changed to:
  • web-specific background color, #D2D2FF" _mce_style="background-color: <span class="wysiwyg_protected">%webbgcolor%</span>;" class='TMLhtml' > current color

I hope that comes across OK in this report. The less-than and greater-than signs in the 'span's have been replaced with their HTML entities

-- BrianMathis - 02 Dec 2010

Preserving macros inside HTML tags is very difficult. I don't think we support this. In fact I thought we had changes all these occurances to be wrapped with <sticky>...</sticky> tags? Are you perhaps editing a WebPreferences topic which came from an older Foswiki?

-- PaulHarvey - 02 Dec 2010

Sorry, I see that you said you're editing a standard topic. Will investigate.

-- PaulHarvey - 02 Dec 2010

Yes this is editing an older version of WebPreferences - we no longer include the span with the example color. The original topic contained:
<span style='background-color: %WEBBGCOLOR%'> current color </span>

Inline here: current color

Setting to confirmed.

-- GeorgeClark - 21 Sep 2011

Crawford, I think I have a possible (but not great) fix:

The fix is down in /WysiwygPlugin/ sub _processTags We need to detect that we are inside an HTML tag, and not protect macros there. Some tags are already protected as they are removed earlier in the code, but span makes it through and gets munged up, so you end up with a <span inside the class= of a span, which is completely illegal.

Here is a fix, but probably not 100%, as it doesn't really correctly parse out tags, but it works for the unit tests. It would fail if there are multiple html tags on a single line. We need to detect that we are inside a tag itself, but not inside the contents of the span.

Here is a much better fix I think. It just hides % tags when found inside an <..html...> tag Unit tests all pass with this.

diff --git a/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/ b/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/
index a5f1da9..22ac320 100644
--- a/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/
+++ b/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/
@@ -459,6 +459,8 @@ s/<([A-Za-z]+[^>]*?)((?:\s+\/)?)>/'<' . $this->_protectTag($1, 'TMLhtml') . $2 .
     $text =~ s/\[\[([^\]]*)\]\]/$this->_protectMacrosInSquab($1)/ge;
+    $text =~ s/(<[^>]+>)/$this->_protectMacrosInHTML($1)/ge;
     # Convert Foswiki tags to spans outside protected text
     $text = $this->_processTags($text);
@@ -983,6 +985,14 @@ m/$startww(($Foswiki::regex{webNameRegex}\.)?$Foswiki::regex{wikiWordRegex}($Fos
+sub _protectMacrosInHTML {
+    my $this = shift;
+    my $tag = shift;
+    $tag =~ s/%/$TT3/g;
+    return $tag;
 sub _protectMacrosInSquab {
     my $this = shift;
     my $url  = shift;

-- GeorgeClark - 22 Jan 2015

I decided to check this in... Fix looks good, tests all pass. Please set waiting for release if you concur.

-- GeorgeClark - 22 Jan 2015

ItemTemplate edit

Summary WYSIWYG editor protects macros inside tags by inserting spans, which then breaks the enclosing tag.
ReportedBy BrianMathis
Codebase 1.1.3, 1.1.2
SVN Range
AppliesTo Engine
Component WysiwygPlugin
Priority Normal
CurrentState Closed
Checkins distro:58a7800672e2 distro:db03497080c9 distro:8e22a9dc3ecc distro:932c1ec35f29
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches Release01x01 trunk master
trunkCheckins distro:8e22a9dc3ecc
masterCheckins distro:932c1ec35f29
Release01x01Checkins distro:58a7800672e2 distro:db03497080c9
Topic revision: r11 - 05 Jul 2015, GeorgeClark - This page was cached on 17 Sep 2021 - 08:54.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy