"Toggle Render Mode" deletes attributes in second IMG tag
Opened this issue · 1 comments
sabre23t commented
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" ><img="">
Further notes
- I previously reported this in DrummerSupport repo as "Show or Hide HTML code in text" deletes attributes in second IMG tag.
- I confirmed this bug in Concord's Example 1 app given in the README.md.
- Unfortunately Example 1's
Outliner > Toggle Render Mode
menu command doesn't work. Console log shows error messagetoggleRenderMode is not defined
. Keyboard commandCtrl-`
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). - It appears this bug is related to the bug reported by AndrewSchell concord.escape function img regex shouldn't be greedy.
- Andrew suggested a change to Line 996 of concord.js that includes
new RegExp("<"+tag+"((?!>).+)(/)?>","gi")
. It appears that is now at Line 1016 of concord.js. - Caveat: I'm more of a poet than a plumber, nowadays.
PostMonsterG commented
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("<"+tag+"((?!>).+)(/)?>","gi"),"<"+tag+"$1"+"/>");
to
h = h.replace(new RegExp("<"+tag+"((?!>).+?)(/)?>","gi"),"<"+tag+"$1"+"/>");
I've added a ?
. Attached is a quick harness to exercise the fix.