Fix infinite recursion bug with references to current file.

This commit is contained in:
Joshua Coles 2021-02-09 11:32:10 +00:00
parent 60d41672a5
commit f76fc22312
1 changed files with 8 additions and 4 deletions

View File

@ -459,10 +459,14 @@ impl<'a> Exporter<'a> {
fn embed_file<'b>(&self, link_text: &'a str, context: &'a Context) -> Result<MarkdownTree<'a>> { fn embed_file<'b>(&self, link_text: &'a str, context: &'a Context) -> Result<MarkdownTree<'a>> {
let note_ref = ObsidianNoteReference::from_str(link_text); let note_ref = ObsidianNoteReference::from_str(link_text);
let path = note_ref let path = match note_ref.file {
.file Some(file) => lookup_filename_in_vault(file, &self.vault_contents.as_ref().unwrap()),
.map(|file| lookup_filename_in_vault(file, &self.vault_contents.as_ref().unwrap()))
.unwrap_or_else(|| Some(context.current_file())); // If we have None file it is either to a section or id within the same file and thus
// the current embed logic will fail, recurssing until it reaches it's limit.
// For now we just bail early.
None => return Ok(self.make_link_to_file(note_ref, &context)),
};
if path.is_none() { if path.is_none() {
// TODO: Extract into configurable function. // TODO: Extract into configurable function.