Add custom tag for markdown codeblocks

This commit is contained in:
Guillaume Gomez 2023-08-28 15:03:40 +02:00
parent 113220b970
commit f038f180fd
2 changed files with 41 additions and 3 deletions

View File

@ -1166,6 +1166,7 @@ fn parse(
let allow_error_code_check = allow_error_code_check.as_bool(); let allow_error_code_check = allow_error_code_check.as_bool();
let mut seen_rust_tags = false; let mut seen_rust_tags = false;
let mut seen_other_tags = false; let mut seen_other_tags = false;
let mut seen_custom_tag = false;
let mut data = LangString::default(); let mut data = LangString::default();
let mut ignores = vec![]; let mut ignores = vec![];
@ -1195,6 +1196,9 @@ fn parse(
data.rust = true; data.rust = true;
seen_rust_tags = true; seen_rust_tags = true;
} }
LangStringToken::LangToken("custom") => {
seen_custom_tag = true;
}
LangStringToken::LangToken("test_harness") => { LangStringToken::LangToken("test_harness") => {
data.test_harness = true; data.test_harness = true;
seen_rust_tags = !seen_other_tags || seen_rust_tags; seen_rust_tags = !seen_other_tags || seen_rust_tags;
@ -1264,7 +1268,6 @@ fn parse(
data.unknown.push(x.to_owned()); data.unknown.push(x.to_owned());
} }
LangStringToken::KeyValueAttribute(key, value) => { LangStringToken::KeyValueAttribute(key, value) => {
seen_other_tags = true;
if key == "class" { if key == "class" {
data.added_classes.push(value.to_owned()); data.added_classes.push(value.to_owned());
} else if let Some(extra) = extra { } else if let Some(extra) = extra {
@ -1273,7 +1276,6 @@ fn parse(
} }
} }
LangStringToken::ClassAttribute(class) => { LangStringToken::ClassAttribute(class) => {
seen_other_tags = true;
data.added_classes.push(class.to_owned()); data.added_classes.push(class.to_owned());
} }
} }
@ -1284,7 +1286,7 @@ fn parse(
data.ignore = Ignore::Some(ignores); data.ignore = Ignore::Some(ignores);
} }
data.rust &= !seen_other_tags || seen_rust_tags; data.rust &= !seen_custom_tag && (!seen_other_tags || seen_rust_tags);
data data
} }

View File

@ -64,6 +64,12 @@ fn t(lg: LangString) {
t(LangString { original: "{rust}".into(), rust: true, ..Default::default() }); t(LangString { original: "{rust}".into(), rust: true, ..Default::default() });
t(LangString { t(LangString {
original: "{.rust}".into(), original: "{.rust}".into(),
rust: true,
added_classes: vec!["rust".into()],
..Default::default()
});
t(LangString {
original: "custom,{.rust}".into(),
rust: false, rust: false,
added_classes: vec!["rust".into()], added_classes: vec!["rust".into()],
..Default::default() ..Default::default()
@ -154,12 +160,24 @@ fn t(lg: LangString) {
t(LangString { t(LangString {
original: "{class=test}".into(), original: "{class=test}".into(),
added_classes: vec!["test".into()], added_classes: vec!["test".into()],
rust: true,
..Default::default()
});
t(LangString {
original: "custom,{class=test}".into(),
added_classes: vec!["test".into()],
rust: false, rust: false,
..Default::default() ..Default::default()
}); });
t(LangString { t(LangString {
original: "{.test}".into(), original: "{.test}".into(),
added_classes: vec!["test".into()], added_classes: vec!["test".into()],
rust: true,
..Default::default()
});
t(LangString {
original: "custom,{.test}".into(),
added_classes: vec!["test".into()],
rust: false, rust: false,
..Default::default() ..Default::default()
}); });
@ -172,12 +190,24 @@ fn t(lg: LangString) {
t(LangString { t(LangString {
original: "{class=test:with:colon .test1}".into(), original: "{class=test:with:colon .test1}".into(),
added_classes: vec!["test:with:colon".into(), "test1".into()], added_classes: vec!["test:with:colon".into(), "test1".into()],
rust: true,
..Default::default()
});
t(LangString {
original: "custom,{class=test:with:colon .test1}".into(),
added_classes: vec!["test:with:colon".into(), "test1".into()],
rust: false, rust: false,
..Default::default() ..Default::default()
}); });
t(LangString { t(LangString {
original: "{class=first,class=second}".into(), original: "{class=first,class=second}".into(),
added_classes: vec!["first".into(), "second".into()], added_classes: vec!["first".into(), "second".into()],
rust: true,
..Default::default()
});
t(LangString {
original: "custom,{class=first,class=second}".into(),
added_classes: vec!["first".into(), "second".into()],
rust: false, rust: false,
..Default::default() ..Default::default()
}); });
@ -206,6 +236,12 @@ fn t(lg: LangString) {
t(LangString { t(LangString {
original: r#"{class="first"}"#.into(), original: r#"{class="first"}"#.into(),
added_classes: vec!["first".into()], added_classes: vec!["first".into()],
rust: true,
..Default::default()
});
t(LangString {
original: r#"custom,{class="first"}"#.into(),
added_classes: vec!["first".into()],
rust: false, rust: false,
..Default::default() ..Default::default()
}); });