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

HTML output of input with frontmatter strip first newline in first paragraph #143

Closed
martinhath opened this issue Sep 21, 2024 · 2 comments

Comments

@martinhath
Copy link

martinhath commented Sep 21, 2024

I have markdown files with frontmatter that I convert to HTML using to_html_with_options. If the first item after the frontmatter is a paragraph, there's a missing newline in the HTML output.

Here's a failing test to show what I mean:

#[test]
fn to_html() {
    let opt: Options = Default::default();
    let opt_with_frontmatter = Options {
        parse: ParseOptions {
            constructs: Constructs {
                frontmatter: true,
                ..Default::default()
            },
            ..Default::default()
        },
        compile: Default::default(),
    };

    let input = "one.\ntwo.\nthree.\nfour.";
    let output = to_html_with_options(&input, &opt).unwrap();
    assert_eq!(output, "<p>one.\ntwo.\nthree.\nfour.</p>"); // No frontmatter. This passes.

    let output = to_html_with_options(&input, &opt_with_frontmatter).unwrap();
    assert_eq!(output, "<p>one.\ntwo.\nthree.\nfour.</p>"); // Frontmatter in config but not in the markdown. This passes.

    let input = "---\nnumber: 0\n---\none.\ntwo.\nthree.\nfour.";
    let output = to_html_with_options(&input, &opt_with_frontmatter).unwrap();
    assert_eq!(output, "<p>one.\ntwo.\nthree.\nfour.</p>"); // This fails 💥
}

which outputs

---- test::to_html stdout ----
thread 'test::to_html' panicked at src/lib.rs:190:9:
assertion `left == right` failed
  left: "<p>one.two.\nthree.\nfour.</p>"
 right: "<p>one.\ntwo.\nthree.\nfour.</p>"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The test was ran on 4ad5342.

@wooorm
Copy link
Owner

wooorm commented Sep 23, 2024

Interesting, PR welcome!

@martinhath
Copy link
Author

It seems context.slurp_one_line_ending = true in on_exit_frontmatter is what's causing it. I tried simply removing it, and all tests, including the one from this issue, passes. Depending on your testing philosophy, this either means the change is okay, or that there's already a tests missing for the behavior of settings slurp_one_line_ending = true.

@wooorm wooorm closed this as completed in e9d53d2 Jan 30, 2025
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

2 participants