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

Trim blank lines around verbatim text #6

Merged
merged 1 commit into from
Oct 12, 2017
Merged

Trim blank lines around verbatim text #6

merged 1 commit into from
Oct 12, 2017

Conversation

aantron
Copy link
Contributor

@aantron aantron commented Oct 11, 2017

Odoc currently produces output for code blocks that looks like this:


captura de pantalla 2017-10-11 a la s 15 34 44


Note the blank line at the top of the code block.

By comparison, ocamldoc produces the expected:


captura de pantalla 2017-10-11 a la s 15 34 11


It is common to have the starting delimiter of a raw code or verbatim text block on a separate line; likewise the ending delimiter:

{[
val parse_html : char stream   -> signal stream
val write_html : signal stream -> char stream
val parse_xml  : char stream   -> signal stream
val write_xml  : signal stream -> char stream
]}

The two extra newlines should not affect the interpretation or presentation of the code block. To get this, the commit in this PR passes the accumulated text through the existing remove_opening_blanks and remove_closing_blanks.

The result is


captura de pantalla 2017-10-11 a la s 15 33 59


In addition to code blocks, this bug is also present for verbatim text blocks, but it is more difficult to observe because leading line breaks are ignored in pre content when parsing HTML (reference, see 'A start tag whose tag name is one of: "pre", "listing"'). For code blocks, the leading token generated by odoc in pre elements ends up being a nested <code> tag, not a line break, resulting in the visual bug.

Even though it's not visible, I fixed the bug in verbatim blocks as well, so that any future introduction of nested markup for verbatim blocks does not cause visual artifacts.

@dbuenzli
Copy link
Contributor

This should fix ocaml/odoc#39

@lpw25
Copy link
Collaborator

lpw25 commented Oct 12, 2017

This looks correct to me. I was going to say that it should only remove blanks up to and including the first newline, but it seems that is exactly what remove_opening_blanks does (modulo a bug I just spotted in it which I will fix shortly).

@lpw25 lpw25 merged commit b6bd829 into ocaml-doc:master Oct 12, 2017
@aantron
Copy link
Contributor Author

aantron commented Oct 12, 2017

I suggest also changing the function names to be more self-descriptive. I also didn't realize that remove_opening_blanks and its sibling remove one line each. Fortunately, I read them before starting to write my own :)

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

Successfully merging this pull request may close these issues.

None yet

3 participants