Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
fix on off in content and markup
Browse files Browse the repository at this point in the history
  • Loading branch information
astrale-sharp committed Sep 9, 2023
1 parent 00066b3 commit a801c78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion lib/src/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub(crate) fn format_content_blocks(
for (s, node) in children.iter().zip(parent.children()) {
match node.kind() {
_ if ctx.off => res.push_str(node.text()),
LineComment | BlockComment => {
let buf = format_comment_handling_disable(&node, &[], ctx);
ctx.push_raw_in(&buf, &mut res);
}
RightBracket if spaced => {
let space_type = if first_space.unwrap().text().contains('\n') {
'\n'
Expand Down Expand Up @@ -48,8 +52,23 @@ pub(crate) fn format_markup(parent: &LinkedNode, children: &[String], ctx: &mut

for (idx, (s, node)) in children.iter().zip(parent.children()).enumerate() {
match node.kind() {
_ if ctx.off => res.push_str(node.text()), // todo, interaction with line below?
_ if ctx.off => res.push_str(&deep_no_format(&node)), // todo, interaction with line below?
_ if skip_until.is_some_and(|skip| idx <= skip) => {}
LineComment | BlockComment => {
let buf = format_comment_handling_disable(&node, &[], ctx);
if ctx.off
&& [Space, Parbreak]
.map(Some)
.contains(&utils::get_prev_ignoring(&node, &[]).map(|x| x.kind()))
{
let s = utils::get_prev_ignoring(&node, &[])
.map(|x| x.text().to_string())
.unwrap_or_default();
let s = s.split('\n').last().unwrap_or_default();
ctx.push_raw_in(s, &mut res);
}
ctx.push_raw_in(&buf, &mut res);
}
Space => {
if idx == 0
|| idx == children.len()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: lib/src/tests/snippets.rs
description: "INPUT\n===\n\"// typstfmt::off\\n#{{4}}\\n// typstfmt::on\\n#{{4}}\\n\"\n===\n// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{{4}}\n\n===\nFORMATTED\n===\n// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{ { 4 } }\n"
description: "INPUT\n===\n\"// typstfmt::off\\n#{{4}}\\n// typstfmt::on\\n#{{4}}\\n\"\n===\n// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{{4}}\n\n===\nFORMATTED\n===\n// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{{4}}\n"
expression: formatted
---
"// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{ { 4 } }\n"
"// typstfmt::off\n#{{4}}\n// typstfmt::on\n#{{4}}\n"

0 comments on commit a801c78

Please sign in to comment.