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

Whitespace in code blocks is not properly preserved #508

Open
SteffenDE opened this issue Nov 10, 2024 · 0 comments
Open

Whitespace in code blocks is not properly preserved #508

SteffenDE opened this issue Nov 10, 2024 · 0 comments

Comments

@SteffenDE
Copy link

Hi there,

I'm parsing markdown files with earkmark and hooking into the postprocess to highlight the code with makeup. I noticed that the code earmark parsed does not properly preserve whitespace and therefore also the highlighted code doesn't render correctly:

"""
```xml
<!-- Basic element with attributes -->
<book id="b1" category="fiction" inStock="yes">
  <title>The Great Gatsby</title>
  <!-- Multiple elements of same type -->
  <author>F. Scott Fitzgerald</author>
  <published>1925</published>
  <!-- CDATA section for text with special characters -->
  <description><![CDATA[A story about the American Dream & society in the 1920s]]></description>
</book>
```
"""
|> Earmark.as_html!(
  escape: false,
  postprocessor: fn
    {"code", _attrs, [body], _meta} = node ->
      IO.puts(body)
      node    

    node ->
      node
  end
)

This outputs

<!-- Basic element with attributes -->

<book id="b1" category="fiction" inStock="yes">
  <title>The Great Gatsby</title>
<!-- Multiple elements of same type -->

  <author>F. Scott Fitzgerald</author>
  <published>1925</published>
<!-- CDATA section for text with special characters -->

  <description><![CDATA[A story about the American Dream & society in the 1920s]]></description>
</book>

while it should output

<!-- Basic element with attributes -->
<book id="b1" category="fiction" inStock="yes">
  <title>The Great Gatsby</title>
  <!-- Multiple elements of same type -->
  <author>F. Scott Fitzgerald</author>
  <published>1925</published>
  <!-- CDATA section for text with special characters -->
  <description><![CDATA[A story about the American Dream & society in the 1920s]]></description>
</book>

Using earmark 1.4.47.

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

1 participant