scripting/concord

"Toggle Render Mode" deletes attributes in second IMG tag

Opened this issue · 1 comments

If you have the following HTML in a Concord Example 1 v0.5.3 headline:
<img src="img_girl.jpg" width="500"><img src="img_girl2.jpg" width="500">

When you go into Concord render mode the second IMG tag will have all attributes deleted.
<img src="img_girl.jpg" width="500" &gt;&lt;img="">

Further notes

  1. I previously reported this in DrummerSupport repo as "Show or Hide HTML code in text" deletes attributes in second IMG tag.
  2. I confirmed this bug in Concord's Example 1 app given in the README.md.
  3. Unfortunately Example 1's Outliner > Toggle Render Mode menu command doesn't work. Console log shows error message toggleRenderMode is not defined. Keyboard command Ctrl-` also didn't work. However, reloading Example 1 webpage, does reload its outline in render mode. Inspecting DOM elements shows the current transfomed content of that headline (with all attributes deleted for the second IMG tag).
  4. It appears this bug is related to the bug reported by AndrewSchell concord.escape function img regex shouldn't be greedy.
  5. Andrew suggested a change to Line 996 of concord.js that includes new RegExp("&lt;"+tag+"((?!&gt;).+)(/)?&gt;","gi"). It appears that is now at Line 1016 of concord.js.
  6. Caveat: I'm more of a poet than a plumber, nowadays.

I believe this can be fixed by making one of the matches less greedy. Specifically, changing this pattern, at line 1016 in master, from

h = h.replace(new RegExp("&lt;"+tag+"((?!&gt;).+)(/)?&gt;","gi"),"<"+tag+"$1"+"/>");
to
h = h.replace(new RegExp("&lt;"+tag+"((?!&gt;).+?)(/)?&gt;","gi"),"<"+tag+"$1"+"/>");

I've added a ?. Attached is a quick harness to exercise the fix.

test.txt