lzanini / mdbook-katex

A preprocessor for mdBook, rendering LaTex equations to HTML at build time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When a delimiter starts with backtick (`), katex renders inside code blocks

josebama opened this issue · comments

When a custom delimiter, either inline or block, starts with backtick (`), the katex syntax is rendered even if it's inside a code block.

For example, given block-delimiter = { left = "```math", right = "```" }, `$\omega$` should not be rendered with katex, as the katex syntax is inside inline code, but it does.

This has the potential of affecting many people, as that kind of block delimiter is needed to replicate GitLab Flavoured Markdown syntax.

The issue can be reproduced with the following test:

#[test]
fn test_rendering_delimiter_in_inline_code_when_block_delimiter_starts_with_backtick() {
    let raw_content = r"`$\omega$`";
    let cfg = KatexConfig {
        block_delimiter: Delimiter {
            left: "```math".into(),
            right: "```".into(),
        },
        ..KatexConfig::default()
    };
    let (stylesheet_header, mut rendered_content) =
        test_render_with_cfg(&[raw_content], HashMap::new(), cfg);
    let expected_output = stylesheet_header + raw_content;
    debug_assert_eq!(expected_output, rendered_content.pop().unwrap());
}

image

I did some quick tests and the results seem correct; math blocks inside code blocks are not rendered ⬆.

Could you share some screenshots where the incorrect behavior happen?

Could you provide the version and environment information?

Thanks,
Steven Hé (Sīchàng)