Code block parsing

This commit is contained in:
Natty 2023-10-05 22:25:29 +02:00
parent a6ee6bfbde
commit 4431a3ad62
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
1 changed files with 39 additions and 0 deletions

View File

@ -331,6 +331,45 @@ impl Context {
Ok((input, boxing_sequence(Token::Center)(tokens))) Ok((input, boxing_sequence(Token::Center)(tokens)))
} }
fn tag_block_code<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token<'a>> {
let delim = &tag("```");
let (input, _) = opt(line_ending)(input)?;
if input.get_column() != 0 {
return fail(input);
}
let (input, _) = delim(input)?;
let (input, lang) = opt(map(
recognize(many1(tuple((not(delim), not_line_ending)))),
Span::into_fragment,
))(input)?;
let (input, _) = line_ending(input)?;
let (input, code) = map(
recognize(many1_count(tuple((
not(tuple((line_ending, delim))),
anychar,
)))),
Span::into_fragment,
)(input)?;
let (input, _) = line_ending(input)?;
let (input, _) = delim(input)?;
let (input, _) = many0(space)(input)?;
let (input, _) = not(not_line_ending)(input)?;
let (input, _) = opt(line_ending)(input)?;
Ok((
input,
Token::BlockCode {
lang: lang.map(<&str>::into),
inner: code.into(),
},
))
}
fn tag_block_math<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token<'a>> { fn tag_block_math<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token<'a>> {
let start = &tag("\\["); let start = &tag("\\[");
let end = &tag("\\]"); let end = &tag("\\]");