Skip to content

Commit 6cde9d1

Browse files
committed
inline code cell syntax (#4)
1 parent f0c9d5e commit 6cde9d1

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

crates/quarto_markdown_pandoc/src/pandoc/treesitter.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ fn native_visitor<T: Write>(
980980
"code_span" => (|| {
981981
let mut is_raw: Option<String> = None;
982982
let mut attr = ("".to_string(), vec![], HashMap::new());
983+
let mut language_attribute: Option<String> = None;
983984
let mut inlines: Vec<_> = children
984985
.into_iter()
985986
.map(|(node_name, child)| {
@@ -1001,7 +1002,18 @@ fn native_visitor<T: Write>(
10011002
PandocNativeIntermediate::IntermediateUnknown(range),
10021003
)
10031004
}
1004-
_ => (node_name, child),
1005+
PandocNativeIntermediate::IntermediateBaseText(text, range) => {
1006+
if node_name == "language_attribute" {
1007+
language_attribute = Some(text);
1008+
// IntermediateUnknown here "consumes" the node
1009+
(node_name, PandocNativeIntermediate::IntermediateUnknown(range))
1010+
} else {
1011+
(node_name, PandocNativeIntermediate::IntermediateBaseText(text, range))
1012+
}
1013+
}
1014+
_ => {
1015+
(node_name, child)
1016+
},
10051017
}
10061018
})
10071019
.filter(|(_, child)| {
@@ -1048,7 +1060,14 @@ fn native_visitor<T: Write>(
10481060
text,
10491061
}))
10501062
} else {
1051-
PandocNativeIntermediate::IntermediateInline(Inline::Code(Code { attr, text }))
1063+
match language_attribute {
1064+
Some(lang) => {
1065+
PandocNativeIntermediate::IntermediateInline(Inline::Code(Code { attr, text: lang + &" " + &text }))
1066+
}
1067+
None => {
1068+
PandocNativeIntermediate::IntermediateInline(Inline::Code(Code { attr, text }))
1069+
}
1070+
}
10521071
}
10531072
})(),
10541073
"latex_span" => {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`hello`{r}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ Para [Code ( "" , [] , [] ) "{r} hello"] ]

0 commit comments

Comments
 (0)