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

HTML Writer: LineBlock should use <br>, not <div> with CSS white-space property #4162

Closed
hftf opened this issue Dec 16, 2017 · 8 comments
Closed

Comments

@hftf
Copy link
Contributor

hftf commented Dec 16, 2017

Related:

  1. Read and write LineBlock elements #3072 22cb9e3 New LineBreak AST element
    HTML Writer converts LineBreak to <div> with style attribute
  2. feature request: html output, div around line block #1623 66b0839
    HTML Writer converts LineBreak to <div> with class instead of style attribute
  3. Summary of a discussion about rendering RST line blocks to HTML in the Docutils project

There are problems with using a div with style to indicate a line block. First, it is presentational, not semantic: HTML's <div> does not have the meaning of preserving line breaks, but HTML already does have a semantic element to indicate line breaks: <br>. When CSS is disabled or broken, the block is rendered incorrectly without any line breaks. It also cannot be round-trip converted back into LineBlock:

echo '[LineBlock [[Str "A"],[Str "B"]]]' | pandoc -f native

<div class="line-block">A
B</div>
echo '[LineBlock [[Str "A"],[Str "B"]]]' | pandoc -f native | pandoc -f html -t native

[Div ("",["line-block"],[])
[Plain [Str "A",SoftBreak,Str "B"]]]

I would like to propose that the HTML Writer be modified like so:

echo '[LineBlock [[Str "A"],[Str "B"]]]' | pandoc -f native

<div class="line-block">A<br />
B</div>

and that the HTML Reader also be modified to recognize such markup as LineBlock.

I could also not find any HTML tests for LineBlock (but there are a few in the unmerged PR #1545).

@jgm
Copy link
Owner

jgm commented Dec 17, 2017

The change was made in #1623. I guess I don't see any reason to prefer using CSS to just putting br tags in there, as long as we still have a div with the special class. But maybe @uvtc or @mb21 would like to comment?

@mb21
Copy link
Collaborator

mb21 commented Dec 18, 2017

It seems we have being going back and forth on this one a couple of times (e.g. here)... but in principle, I agree, we could just emit <br>s as well -- as long as we also keep the div with the class so people can apply their custom styling with CSS.

Then again, I don't really see much of an advantage for the change either. The two reasons mentioned above seem fairly theoretical. But yes, we could get rid of a few lines of CSS in the templates.

What does @tarleb think, who introduced the LineBlock element?

@uvtc
Copy link

uvtc commented Dec 18, 2017

If I understand this correctly, the question is whether to use inline css styling "style="white-space: pre-line"", versus <br/>. Regardless we still have the div class=line-block around them.

Since there is no "line block" element in html, I think it makes sense to produce them with <br/>'s. That's exactly what br's are for. I presume each output format has its own "br" for that purpose as well.

@tarleb
Copy link
Collaborator

tarleb commented Dec 18, 2017

Cutting out any semantical correctnes arguments in this case, I agree that br elements are easier to work with. I slightly favor HTML elements over line break characters, but don't feel stronly either way.

@mb21
Copy link
Collaborator

mb21 commented Dec 19, 2017

If I understand this correctly, the question is whether to use inline css styling "style="white-space: pre-line"", versus <br/>.

Almost. It's about whether to use <div class="line-block"> and .line-block { white-space: pre-line; } in the template (current implementation), versus <div class="line-block"> with text and <br/>s inside.

@uvtc
Copy link

uvtc commented Dec 19, 2017

Thanks for the clarification, @mb21 !

@jgm jgm closed this as completed in 718b2c5 Dec 26, 2017
@hftf
Copy link
Contributor Author

hftf commented Dec 26, 2017

Thanks, John.
Fwiw, I also suggested that the HTML Reader recognize <div class="line-block"> as LineBlock.

@jgm
Copy link
Owner

jgm commented Dec 27, 2017 via email

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

No branches or pull requests

5 participants