Code block parsing
This commit is contained in:
parent
a6ee6bfbde
commit
4431a3ad62
|
@ -331,6 +331,45 @@ impl Context {
|
|||
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>> {
|
||||
let start = &tag("\\[");
|
||||
let end = &tag("\\]");
|
||||
|
|
Loading…
Reference in New Issue