mersinvald / aquamarine

Inline diagrams for rustdoc with mermaid.js
MIT License
508 stars 28 forks source link

Mermaid code blocks break rendering of footnotes #23

Open CJKay opened 2 years ago

CJKay commented 2 years ago

Comment blocks that utilise Mermaid's code blocks break footnote rendering, e.g.:

#[cfg_attr(doc, aquamarine::aquamarine)]
/// This is a comment.
///
/// This is a diagram[^1]:
/// ```mermaid
/// flowchart LR
///     A --> B
/// ```
///
/// [^1]: This is a footnote.

Found:

Screenshot 2022-08-16 at 18 24 49

Expected (not including rendered diagram):

Screenshot 2022-08-16 at 18 26 08

frehberg commented 1 year ago

The implementation of aquamarine is using the macro quote!{ #[doc = ...} to embed into the rustdoc section the newly generated mermaid rendering script-hooks. This quote! macro is embedding as block-comment instead of using line-comments. The expanded result of Aquamarine will look similar to the following minimized example:

/// This is a comment.
///
/// This is a diagram[^1]:
/**
 <script> const x = 1;</script>
*/
/// [^1]: This is a footnote.
pub fn example_with_footnote() {}

It seem this block-comment is interrupting the line-comments and causing the footnote-feature to get out of sync.

If the html-code would be added using line-comments, the footnote feature would keep working as expected

/// This is a comment.
///
/// This is a diagram[^1]:
///
/// <script> const x = 1;</script>
/// 
/// [^1]: This is a footnote.
pub fn example_with_footnote() {}

image

Either the quote! macro needs to be modified to produce line-comments or the rustdoc footnote-feature needs to be improved to cope with the switch between different comment styles.

frehberg commented 1 year ago

It seems to be an issue with parsing of multi-line comments, so if the generated code would be a single line, the parser will be fine and footnotes rae respected

/// This is a comment.
///
/// This is a diagram[^1]:
/// <script src="https://unpkg.com/mermaid@9.3.0/dist/mermaid.min.js"> </script> <div>dff</div> 
/// [^1]: This is a footnote.

But this does not go well with the mermaid markdown language, requiring multiline text within div-element