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

Markdown blockquote parsing issue with inline tags #2317

Open
MR-Addict opened this issue Feb 14, 2024 · 4 comments
Open

Markdown blockquote parsing issue with inline tags #2317

MR-Addict opened this issue Feb 14, 2024 · 4 comments
Labels
C-bug Category: A bug, incorrect or unintended behavior

Comments

@MR-Addict
Copy link

MR-Addict commented Feb 14, 2024

Problem

When I upgrade to 0.4.37, some of my custom tags was broken, and I find that this was releated to mdbook blockqote parsing issue.

It will treat below right opening tag as blockquote while rending:

<button
  type="button"
  class="scroll-to-top"
  onclick="scrollToTop()"
>
  <i class="fas fa-arrow-up"></i>
</button>

And turn it into:

<p>&lt;button
type="button"
class="scroll-to-top"
onclick="scrollToTop()"</p>
<blockquote>
</blockquote>
<p><i class="fas fa-arrow-up"></i>
</button></p>

Steps

For example, I have below custom button element in my markdown:

<button
  type="button"
  class="scroll-to-top"
  onclick="scrollToTop()"
>
  <i class="fas fa-arrow-up"></i>
</button>

And turn it into:

<p>&lt;button
type="button"
class="scroll-to-top"
onclick="scrollToTop()"</p>
<blockquote>
</blockquote>
<p><i class="fas fa-arrow-up"></i>
</button></p>

Possible Solution(s)

However if I move button right opening tag > upper, it will render properly:

<button
  type="button"
  class="scroll-to-top"
  onclick="scrollToTop()" >
  <i class="fas fa-arrow-up"></i>
</button>

Notes

So I think mdbook treat button right opening tag as blockquote.

And I also find that, this issue only appers in button tag, it renders script, style, iframe, footer and div all properly, even these tags have some strange right opening tag positions.

This is okay, which > was separately put under a new line:

<script
>
  const scrollToTop = window.scroll({ top: 0, behavior: "smooth" });
</script>

And this is okay too, which > has a space with closing tag which is every similar to markdown blockquote syntax:

<iframe
  allowfullscreen
  loading="lazy"
  src="https://www.youtube.com/embed/DyTCOwB0DVw"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
> </iframe>

So I think this is releated only to button and some other inline tags like span. It won't able to render below custom element properly too:

<span
> hello world</span>

Even with mdbook 0.4.36, it cannot pase it properly too.

Though above span example is strange and rarely there got any people would write raw html in markdown, but I think it's important to improve mdbook markdown parsing.

Version

0.4.37
@MR-Addict MR-Addict added the C-bug Category: A bug, incorrect or unintended behavior label Feb 14, 2024
@ehuss
Copy link
Contributor

ehuss commented Feb 14, 2024

Thanks for the report! I believe this is working as intended. The parser tries to adhere to commonmark as closely as possible, and the reference implementation agrees here. My guess is that the precedence rules take over here, causing > to be treated as a blockquote (I believe block-structure elements take precedence over inline ones).

@MR-Addict
Copy link
Author

With your reference, it makes sense that block-structure elements take precedence over inline ones. But in version 0.4.36, mdboook is able to correctly parse below custom html:

<button
  type="button"
  class="scroll-to-top"
  onclick="scrollToTop()"
>
  <i class="fas fa-arrow-up"></i>
</button>

So, I think there maybe some changes between 0.4.36 and 0.4.37.

@shenef
Copy link

shenef commented Feb 15, 2024

Going by the changelog, that seems expected.
#2308 fixed some deviations from the spec and was included in 0.4.37

@MR-Addict
Copy link
Author

I agree that keeping this behavior is acceptable. Thank you for your assistance in clarifying this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: A bug, incorrect or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants