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

Multiline comment formatting broken by table #78

Closed
gji opened this issue Mar 4, 2021 · 5 comments
Closed

Multiline comment formatting broken by table #78

gji opened this issue Mar 4, 2021 · 5 comments

Comments

@gji
Copy link
Contributor

gji commented Mar 4, 2021

Multiline comments aren't displayed properly, e.g.:

multiline

The produced markup looks like:

<table class="hljs"><tr><td class="line-number">1</td><td class="line-text"><span class="hljs-string">&#x27;&#x27;&#x27;test</td></tr>
<tr><td class="line-number">2</td><td class="line-text">test</td></tr>
<tr><td class="line-number">3</td><td class="line-text">test&#x27;&#x27;&#x27;</span></td></tr></table>

I believe the issue is that highlightjs adds the span with class hljs-string, but since the text which is inside the class contains newlines the text naturally gets split across table trs. As a result, the span tag gets split across multiple lines, which leads to invalid markup (tags not nested) and the wrong output. This probably affects multiline strings as well.

I did a quick fix of this issue by using pre and span for whitespace formatting and line numbering instead of tables. The resulting markup is:

<pre class="hljs"><span class="lineno">0</span><span class="hljs-string">&#x27;&#x27;&#x27;test
<span class="lineno">1</span>test
<span class="lineno">2</span>test&#x27;&#x27;&#x27;</span></pre>

Since lines aren't contained inside their own tags, the resulting markup is valid. This is a pretty big change that might break a bunch of other stuff, but if this seems like a good direction I can submit a PR.

@PeterWone
Copy link
Collaborator

PeterWone commented Mar 4, 2021

Too much day job pressure to get this the head-space it deserves but your overall approach does seem like it will bear fruit. If you can get it to fly we can see what if any collateral damage this produces. I have some hope that we can integrate this.

(Crikey how's that for a mixed metaphor? I imagine flying fruit trees would produce quite a lot of collateral damage!)

@gji
Copy link
Contributor Author

gji commented Mar 13, 2021

Sorry, also been a bit busy lately. The fix I implemented above leads to code wrapping not being properly indented and also to manually set the column width for the line numbers. I think the second issue is fixable (possibly by adding a hidden "000" to each line number span) but the first one is a bit of a dealbreaker - I can't think of a fix besides adding JavaScript to find the wrapping locations and manually add in indentation. What may be better is simply finding all instances of span tags that wrap across multiple lines and adding in extra ones, which is what's done e.g. here - I can try to do something like that instead.

@PeterWone
Copy link
Collaborator

I've been pretty busy too. Are you having any success? I've had a new feature by PR and closed a bug myself (poor initial stylesheet) so I'll be doing a release soon. I haven't yet updated the documentation so you do have some time. Do you think you are likely to get this sorted in the next week or so?

@gji
Copy link
Contributor Author

gji commented Mar 17, 2021

Yeah, I have some free time finally - I'll try to put something together, should be doable in the next few days.

@gji
Copy link
Contributor Author

gji commented Mar 18, 2021

Should be fixed by #85.

@gji gji closed this as completed Mar 18, 2021
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