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
|
@ -357,7 +357,7 @@ p:last-child {
|
||||||
|
|
||||||
ul,
|
ul,
|
||||||
ol {
|
ol {
|
||||||
margin-left: var(--pad-4);
|
margin: var(--pad-2) 0 var(--pad-2) var(--pad-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
|
@ -365,6 +365,7 @@ pre {
|
||||||
border-left: solid 5px var(--color-primary);
|
border-left: solid 5px var(--color-primary);
|
||||||
background: var(--color-surface);
|
background: var(--color-surface);
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
|
margin-bottom: var(--pad-4);
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
|
@ -474,7 +475,7 @@ h3,
|
||||||
h4,
|
h4,
|
||||||
h5,
|
h5,
|
||||||
h6 {
|
h6 {
|
||||||
margin: 0;
|
margin: var(--pad-4) 0;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
width: -moz-max-content;
|
width: -moz-max-content;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
@ -645,6 +646,10 @@ blockquote {
|
||||||
color: var(--color-green) !important;
|
color: var(--color-green) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hljs-link {
|
||||||
|
color: var(--color-link) !important;
|
||||||
|
}
|
||||||
|
|
||||||
.CodeMirror-scroll {
|
.CodeMirror-scroll {
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -630,21 +630,28 @@ macro_rules! parser_ignores_pre {
|
||||||
output
|
output
|
||||||
}};
|
}};
|
||||||
|
|
||||||
($body:ident, $input:ident, ..) => {{
|
($body:ident, $input:ident, $id:literal, ..) => {{
|
||||||
let mut in_pre_block = false;
|
let mut in_pre_block = false;
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let mut proc_str = 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") {
|
for line in $input.split("\n") {
|
||||||
if line.starts_with("```") | (line == "<style>") | (line == "</style>") {
|
if line.starts_with("```") | (line == "<style>") | (line == "</style>") {
|
||||||
in_pre_block = !in_pre_block;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if in_pre_block {
|
if in_pre_block {
|
||||||
output.push_str(&format!("{line}\n"));
|
pre_blocks[pre_idx - 1] += &(line.to_string() + "\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,20 +661,32 @@ macro_rules! parser_ignores_pre {
|
||||||
$body(&mut output, &mut buffer, &proc_str);
|
$body(&mut output, &mut buffer, &proc_str);
|
||||||
output.push_str(&format!("{buffer}\n"));
|
output.push_str(&format!("{buffer}\n"));
|
||||||
buffer.clear();
|
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
|
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, 0, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
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, 1, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
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, 2, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
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