Skip to content

Inline Rule end delimiter is treated the same as start delimiter when delimiters come in pairs (e.g. '{' and '}') #44

Description

@SleeplessOne1917

I have the following code:

struct RubyScanner;

impl InlineRule for RubyScanner {
    const MARKER: char = '{';

    fn run(state: &mut InlineState) -> Option<(Node, usize)> {
        println!("START POS {}", state.pos);
        println!(
            "Relevant slice {}",
            unescape_all(&state.src[state.pos..state.pos_max])
        );

        let end_pos = state.src[state.pos..state.pos_max]
            .char_indices()
            .find_map(|(i, c)| (c == '}').then_some(i))?
            + state.pos;
        let (base_text, ruby_text) = state.src[state.pos + 1..end_pos].split_once('|')?;

        Some((
            Node::new(Ruby {
                base_text: base_text.trim().into(),
                ruby_text: ruby_text.trim().into(),
            }),
            (end_pos - state.pos) + 1,
        ))
    }
}

If I try parsing the following string with this ("\\{foo|bar}{baz|qux}"), the escape is correctly honored, but for some reason '}' is treated as a marker to start at the same as '{' is. The error output shows this:

START POS 9
Relevant slice }{baz|qux}
thread 'test::test::case_2' panicked at crates/markdown-it-ruby/src/lib.rs:66:47:
begin <= end (10 <= 9) when slicing `\{foo|bar}{baz|qux}`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I also tested this replacing '{' and '}' with '[' and ']' respectively and ran into the same issue. Interestingly, I didn't have this issue when I replaced the curly braces with parentheses.

Is this an error on my part? Because I expect MARKER - and only MARKER - to trigger the start of the scanner.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions