fix: parser pre ignore in proc_str parsers
This commit is contained in:
parent
d9be04a6fe
commit
de720d301d
2 changed files with 32 additions and 8 deletions
|
@ -630,21 +630,28 @@ macro_rules! parser_ignores_pre {
|
|||
output
|
||||
}};
|
||||
|
||||
($body:ident, $input:ident, ..) => {{
|
||||
($body:ident, $input:ident, $id:literal, ..) => {{
|
||||
let mut in_pre_block = false;
|
||||
let mut output = String::new();
|
||||
let mut buffer = String::new();
|
||||
let mut proc_str = String::new();
|
||||
let mut pre_blocks = Vec::new();
|
||||
let mut pre_idx = 0;
|
||||
|
||||
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"));
|
||||
|
||||
pre_idx += 1;
|
||||
pre_blocks.push(String::new());
|
||||
pre_blocks[pre_idx - 1] += &(line.to_string() + "\n");
|
||||
|
||||
proc_str += &format!("$pre:{}.{pre_idx}\n", $id);
|
||||
continue;
|
||||
}
|
||||
|
||||
if in_pre_block {
|
||||
output.push_str(&format!("{line}\n"));
|
||||
pre_blocks[pre_idx - 1] += &(line.to_string() + "\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -654,20 +661,32 @@ macro_rules! parser_ignores_pre {
|
|||
$body(&mut output, &mut buffer, &proc_str);
|
||||
output.push_str(&format!("{buffer}\n"));
|
||||
buffer.clear();
|
||||
|
||||
for (mut i, block) in pre_blocks.iter().enumerate() {
|
||||
i += 1;
|
||||
|
||||
if block == "```\n" {
|
||||
output = output.replacen(&format!("$pre:{}.{i}", $id), "", 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
output = output.replacen(&format!("$pre:{}.{i}", $id), &format!("{block}```\n"), 1);
|
||||
}
|
||||
|
||||
output
|
||||
}};
|
||||
}
|
||||
|
||||
pub fn parse_text_color(input: &str) -> String {
|
||||
parser_ignores_pre!(parse_text_color_line, input, ..)
|
||||
parser_ignores_pre!(parse_text_color_line, input, 0, ..)
|
||||
}
|
||||
|
||||
pub fn parse_highlight(input: &str) -> String {
|
||||
parser_ignores_pre!(parse_highlight_line, input, ..)
|
||||
parser_ignores_pre!(parse_highlight_line, input, 1, ..)
|
||||
}
|
||||
|
||||
pub fn parse_underline(input: &str) -> String {
|
||||
parser_ignores_pre!(parse_underline_line, input, ..)
|
||||
parser_ignores_pre!(parse_underline_line, input, 2, ..)
|
||||
}
|
||||
|
||||
pub fn parse_comment(input: &str) -> String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue