add: multiline parsers
This commit is contained in:
parent
5d4e94575b
commit
5f2864e6b6
1 changed files with 31 additions and 3 deletions
|
@ -94,6 +94,7 @@ fn parse_text_color_line(output: &mut String, buffer: &mut String, line: &str) {
|
||||||
let ahead = slice(line, i..);
|
let ahead = slice(line, i..);
|
||||||
if !ahead.contains("%%") {
|
if !ahead.contains("%%") {
|
||||||
// no closing sequence, we're done
|
// no closing sequence, we're done
|
||||||
|
buffer.push(char);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,18 +626,45 @@ macro_rules! parser_ignores_pre {
|
||||||
|
|
||||||
output
|
output
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
($body:ident, $input:ident, ..) => {{
|
||||||
|
let mut in_pre_block = false;
|
||||||
|
let mut output = String::new();
|
||||||
|
let mut buffer = String::new();
|
||||||
|
let mut proc_str = String::new();
|
||||||
|
|
||||||
|
for line in $input.split("\n") {
|
||||||
|
if line.starts_with("```") | (line == "<style>") | (line == "</style>") {
|
||||||
|
in_pre_block = !in_pre_block;
|
||||||
|
output.push_str(&format!("{line}\n"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if in_pre_block {
|
||||||
|
output.push_str(&format!("{line}\n"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc_str += &(line.to_string() + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
$body(&mut output, &mut buffer, &proc_str);
|
||||||
|
output.push_str(&format!("{buffer}\n"));
|
||||||
|
buffer.clear();
|
||||||
|
output
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_text_color(input: &str) -> String {
|
pub fn parse_text_color(input: &str) -> String {
|
||||||
parser_ignores_pre!(parse_text_color_line, input)
|
parser_ignores_pre!(parse_text_color_line, input, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_highlight(input: &str) -> String {
|
pub fn parse_highlight(input: &str) -> String {
|
||||||
parser_ignores_pre!(parse_highlight_line, input)
|
parser_ignores_pre!(parse_highlight_line, input, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_underline(input: &str) -> String {
|
pub fn parse_underline(input: &str) -> String {
|
||||||
parser_ignores_pre!(parse_underline_line, input)
|
parser_ignores_pre!(parse_underline_line, input, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_comment(input: &str) -> String {
|
pub fn parse_comment(input: &str) -> String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue