Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Toggle Render Mode" deletes attributes in second IMG tag #15

Open
sabre23t opened this issue Dec 22, 2021 · 1 comment
Open

"Toggle Render Mode" deletes attributes in second IMG tag #15

sabre23t opened this issue Dec 22, 2021 · 1 comment

Comments

@sabre23t
Copy link

sabre23t commented Dec 22, 2021

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.
@PostMonsterG
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants