mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Include directives don't like being within blockquotes

Open carols10cents opened this issue 5 years ago • 1 comments

I'm using mdbook v0.3.5.

Here's the markdown I tried to write:

## Blockquote with included code inside

Lorum ipsum dolor sit amet.

> But do included code blocks...?
>
> ```rust
> {{#include another-included-test.rs}}
> ```
>
> By Quote Author

And here's the HTML I get when doing mdbook build, note the multiple <blockquote>s (I'd expect only one opening and one closing):

<h2><a class="header" href="#blockquote-with-included-code-inside" id="blockquote-with-included-code-inside">Blockquote with included code inside</a></h2>
<p>Lorum ipsum dolor sit amet.</p>
<blockquote>
<p>But do included code blocks...?</p>
<pre><pre class="playpen"><code class="language-rust">fn main() {
</code></pre></pre>
</blockquote>
<pre><code>println!(&quot;This is a file!&quot;);
</code></pre>
<p>}</p>
<blockquote>
<pre><code>
By Quote Author
</code></pre>
</blockquote>

And a screenshot of this:

Screen Shot of unexpected rendered HTML

If I use the markdown renderer instead, I see that after processing the include, the markdown looks like this:

## Blockquote with included code inside

Lorum ipsum dolor sit amet.

> But do included code blocks...?
>
> ```rust
> fn main() {
    println!("This is a file!");
}
> ```
>
> By Quote Author

but the markdown that needs to be generated is this:

## Blockquote with included code inside

Lorum ipsum dolor sit amet.

> But do included code blocks...?
>
> ```rust
> fn main() {
>     println!("This is a file!");
> }
> ```
>
> By Quote Author

I was going to try to fix this by taking whatever text appears on the same line before the include directive (so in this case > ) and then repeating that text before each line of the included file, but tests like this one show that inline includes are supported (that example would mean "Some random text with " would be prepended to every included line :().

Limiting the recognized text to something like only > would miss cases where there's a blockquote inside a blockquote or a blockquote inside a list or other edge cases I'm not thinking of.

So I don't know how to fix this, and I'm opening this to see if anyone else has ideas, or at least to document that this doesn't work :(

carols10cents avatar Jan 16 '20 21:01 carols10cents

Much-delayed follow-up (after getting here via the source for TRPL): since rust-lang/mdBook#1003 landed, is this tractable? I ask just in case someone already knows off the top of their head; otherwise I will just poke at it and figure it out!

chriskrycho avatar May 13 '24 12:05 chriskrycho