Skip to content

Spurious newline in generated literal_block nodes #407

Open
@cpitclaudel

Description

@cpitclaudel

Describe the problem

The result of main.to_docutils include an extra newline in each literal_block node.

Link to your repository or website

No response

Steps to reproduce

Script:

from myst_parser.main import to_docutils
from docutils.core import publish_doctree

doc = to_docutils("```\ncode\n```\n")
print(doc, end="\n\n")

ref = publish_doctree("::\n\n   code\n\n")
print(ref, end="\n\n")

from docutils.core import publish_from_doctree
print(publish_from_doctree(doc, writer_name="html4css1", settings_overrides={"embed_stylesheet": False}).decode("utf-8"), end="\n\n")
print(publish_from_doctree(ref, writer_name="html4css1", settings_overrides={"embed_stylesheet": False}).decode("utf-8"), end="\n\n")

Output:

<document source="notset"><literal_block language="" xml:space="preserve">code
</literal_block></document>

<document source="<string>"><literal_block xml:space="preserve">code</literal_block></document>

…
<body>
<div class="document">


<pre class="literal-block">
code

</pre>
</div>
</body>
</html>

…
<body>
<div class="document">


<pre class="literal-block">
code
</pre>
</div>
</body>
</html>

Notice the extra newlines in the output of MyST (compared to the expected docutils output ref)

The version of Python you're using

3.8

Versions of your packages

MyST: 5fd4c51

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions