Skip to content

Commit d096911

Browse files
authored
Today's updates (#106)
* make tests pass
1 parent 0033c1a commit d096911

File tree

108 files changed

+107969
-102251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+107969
-102251
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pico-quarto-render/src/main.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ fn main() -> Result<()> {
4848
}
4949

5050
// Create output directory if it doesn't exist
51-
fs::create_dir_all(&args.output_dir)
52-
.context(format!("Failed to create output directory: {:?}", args.output_dir))?;
51+
fs::create_dir_all(&args.output_dir).context(format!(
52+
"Failed to create output directory: {:?}",
53+
args.output_dir
54+
))?;
5355

5456
// Find all .qmd files
5557
let qmd_files: Vec<PathBuf> = WalkDir::new(&args.input_dir)
@@ -87,8 +89,12 @@ fn main() -> Result<()> {
8789
}
8890
}
8991

90-
eprintln!("\nProcessed {} files: {} succeeded, {} failed",
91-
success_count + error_count, success_count, error_count);
92+
eprintln!(
93+
"\nProcessed {} files: {} succeeded, {} failed",
94+
success_count + error_count,
95+
success_count,
96+
error_count
97+
);
9298

9399
if error_count > 0 {
94100
std::process::exit(1);
@@ -104,8 +110,8 @@ fn process_qmd_file(
104110
verbose: u8,
105111
) -> Result<PathBuf> {
106112
// Read the input file
107-
let input_content = fs::read(qmd_path)
108-
.context(format!("Failed to read file: {:?}", qmd_path))?;
113+
let input_content =
114+
fs::read(qmd_path).context(format!("Failed to read file: {:?}", qmd_path))?;
109115

110116
// Parse QMD to AST
111117
// Enable parser verbose mode at level 2+
@@ -120,6 +126,7 @@ fn process_qmd_file(
120126
false, // loose mode
121127
qmd_path.to_str().unwrap_or("<unknown>"),
122128
&mut output_stream,
129+
true,
123130
)
124131
.map_err(|diagnostics| {
125132
// Format error messages using DiagnosticMessage API

crates/qmd-syntax-helper/src/conversions/attribute_ordering.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ pub struct AttributeOrderingConverter {
1515

1616
#[derive(Debug, Clone)]
1717
struct AttributeOrderingViolation {
18-
start_offset: usize, // Offset of '{'
19-
end_offset: usize, // Offset of '}' + 1
20-
original: String, // Original attrs including braces
18+
start_offset: usize, // Offset of '{'
19+
end_offset: usize, // Offset of '}' + 1
20+
original: String, // Original attrs including braces
2121
error_location: Option<SourceLocation>, // For reporting
2222
}
2323

2424
impl AttributeOrderingConverter {
2525
pub fn new() -> Result<Self> {
26-
let pandoc_output_regex = Regex::new(r"^\[\]\{(.+)\}\s*$")
27-
.context("Failed to compile pandoc output regex")?;
26+
let pandoc_output_regex =
27+
Regex::new(r"^\[\]\{(.+)\}\s*$").context("Failed to compile pandoc output regex")?;
2828

2929
Ok(Self {
3030
pandoc_output_regex,
@@ -48,6 +48,7 @@ impl AttributeOrderingConverter {
4848
false, // not loose mode
4949
&filename,
5050
&mut sink,
51+
true,
5152
);
5253

5354
let diagnostics = match result {
@@ -101,7 +102,11 @@ impl AttributeOrderingConverter {
101102
let bytes = content.as_bytes();
102103

103104
if error_offset >= bytes.len() {
104-
return Err(anyhow!("Error offset {} is beyond content length {}", error_offset, bytes.len()));
105+
return Err(anyhow!(
106+
"Error offset {} is beyond content length {}",
107+
error_offset,
108+
bytes.len()
109+
));
105110
}
106111

107112
// Search backward for '{'
@@ -110,7 +115,10 @@ impl AttributeOrderingConverter {
110115
start -= 1;
111116
}
112117
if bytes[start] != b'{' {
113-
return Err(anyhow!("Could not find opening brace before offset {}", error_offset));
118+
return Err(anyhow!(
119+
"Could not find opening brace before offset {}",
120+
error_offset
121+
));
114122
}
115123

116124
// Search forward for '}'
@@ -119,7 +127,10 @@ impl AttributeOrderingConverter {
119127
end += 1;
120128
}
121129
if end >= bytes.len() || bytes[end] != b'}' {
122-
return Err(anyhow!("Could not find closing brace after offset {}", error_offset));
130+
return Err(anyhow!(
131+
"Could not find closing brace after offset {}",
132+
error_offset
133+
));
123134
}
124135

125136
Ok((start, end + 1)) // +1 to include the '}'
@@ -142,20 +153,22 @@ impl AttributeOrderingConverter {
142153
.context("Failed to spawn pandoc. Is pandoc installed?")?;
143154

144155
if let Some(mut stdin) = child.stdin.take() {
145-
stdin.write_all(input.as_bytes())
156+
stdin
157+
.write_all(input.as_bytes())
146158
.context("Failed to write to pandoc stdin")?;
147159
}
148160

149-
let output = child.wait_with_output()
161+
let output = child
162+
.wait_with_output()
150163
.context("Failed to wait for pandoc")?;
151164

152165
if !output.status.success() {
153166
let stderr = String::from_utf8_lossy(&output.stderr);
154167
return Err(anyhow!("Pandoc failed: {}", stderr));
155168
}
156169

157-
let stdout = String::from_utf8(output.stdout)
158-
.context("Pandoc output is not valid UTF-8")?;
170+
let stdout =
171+
String::from_utf8(output.stdout).context("Pandoc output is not valid UTF-8")?;
159172

160173
// Extract normalized attrs from "[]{...}"
161174
if let Some(caps) = self.pandoc_output_regex.captures(stdout.trim()) {
@@ -181,14 +194,14 @@ impl AttributeOrderingConverter {
181194
let mut result = content.to_string();
182195

183196
for violation in violations {
184-
let normalized = self.normalize_with_pandoc(&violation.original)
185-
.with_context(|| format!("Failed to normalize attributes: {}", violation.original))?;
197+
let normalized = self
198+
.normalize_with_pandoc(&violation.original)
199+
.with_context(|| {
200+
format!("Failed to normalize attributes: {}", violation.original)
201+
})?;
186202

187203
// Replace original with normalized
188-
result.replace_range(
189-
violation.start_offset..violation.end_offset,
190-
&normalized
191-
);
204+
result.replace_range(violation.start_offset..violation.end_offset, &normalized);
192205
}
193206

194207
Ok(result)
@@ -201,7 +214,10 @@ impl AttributeOrderingConverter {
201214

202215
/// Convert byte offset to column number (0-indexed)
203216
fn offset_to_column(&self, content: &str, offset: usize) -> usize {
204-
let line_start = content[..offset].rfind('\n').map(|pos| pos + 1).unwrap_or(0);
217+
let line_start = content[..offset]
218+
.rfind('\n')
219+
.map(|pos| pos + 1)
220+
.unwrap_or(0);
205221
offset - line_start
206222
}
207223
}
@@ -225,10 +241,7 @@ impl Rule for AttributeOrderingConverter {
225241
file_path: file_path.to_string_lossy().to_string(),
226242
has_issue: true,
227243
issue_count: 1,
228-
message: Some(format!(
229-
"Attribute ordering violation: {}",
230-
v.original
231-
)),
244+
message: Some(format!("Attribute ordering violation: {}", v.original)),
232245
location: v.error_location,
233246
error_code: None,
234247
error_codes: None,

0 commit comments

Comments
 (0)