Skip to content

Commit 6fa00c8

Browse files
committed
fix: error on missing include file
1 parent f4dc8ec commit 6fa00c8

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

Diff for: components/markdown/src/codeblock/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,13 @@ impl<'config> CodeBlock<'config> {
129129
))
130130
}
131131

132-
pub fn include(&self, base: Option<&PathBuf>) -> Option<String> {
133-
let path = base?.join(self.include.as_ref()?);
134-
let res = read_file(&path);
135-
match res {
136-
Ok(content) => Some(content),
137-
Err(e) => {
138-
eprintln!("Warning: Failed to include {:?}: {}", path, e);
139-
None
140-
}
132+
pub fn include(&self, base: Option<&PathBuf>) -> Result<Option<String>> {
133+
if let Some(base) = base {
134+
let path = base.join(&self.include.as_ref().expect("No include path"));
135+
let content = read_file(&path)?;
136+
Ok(Some(content))
137+
} else {
138+
Ok(None)
141139
}
142140
}
143141

Diff for: components/markdown/src/markdown.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -577,19 +577,25 @@ pub fn markdown_to_html(
577577
}
578578
Event::End(TagEnd::CodeBlock { .. }) => {
579579
if let Some(ref mut code_block) = code_block {
580-
let inner = code_block
581-
.include(
582-
context
583-
.parent_absolute
584-
.map(|e| {
585-
path.map(|p| e.join(PathBuf::from(p).parent().unwrap()))
586-
})
587-
.flatten()
588-
.as_ref(),
589-
)
590-
.unwrap_or(accumulated_block.clone());
591-
let html = code_block.highlight(&inner);
592-
events.push(Event::Html(html.into()));
580+
let maybe_inner = code_block.include(
581+
context
582+
.parent_absolute
583+
.map(|e| path.map(|p| e.join(PathBuf::from(p).parent().unwrap())))
584+
.flatten()
585+
.as_ref(),
586+
);
587+
match maybe_inner {
588+
Ok(i) => {
589+
let inner = i.as_ref().unwrap_or(&accumulated_block);
590+
let html = code_block.highlight(&inner);
591+
events.push(Event::Html(html.into()));
592+
}
593+
Err(e) => {
594+
error = Some(e);
595+
break;
596+
}
597+
}
598+
593599
accumulated_block.clear();
594600
}
595601

0 commit comments

Comments
 (0)