fix: parser pre ignore in proc_str parsers

This commit is contained in:
trisua 2025-07-26 12:54:27 -04:00
parent d9be04a6fe
commit de720d301d
2 changed files with 32 additions and 8 deletions

View file

@ -357,7 +357,7 @@ p:last-child {
ul,
ol {
margin-left: var(--pad-4);
margin: var(--pad-2) 0 var(--pad-2) var(--pad-4);
}
pre {
@ -365,6 +365,7 @@ pre {
border-left: solid 5px var(--color-primary);
background: var(--color-surface);
border-radius: var(--radius);
margin-bottom: var(--pad-4);
}
code {
@ -474,7 +475,7 @@ h3,
h4,
h5,
h6 {
margin: 0;
margin: var(--pad-4) 0;
font-weight: 700;
width: -moz-max-content;
position: relative;
@ -645,6 +646,10 @@ blockquote {
color: var(--color-green) !important;
}
.hljs-link {
color: var(--color-link) !important;
}
.CodeMirror-scroll {
height: 100% !important;
}

View file

@ -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 {