obsidian-export-to-tex icon indicating copy to clipboard operation
obsidian-export-to-tex copied to clipboard

Export to sanitized (Pandoc-ready) markdown file

Open psyguy opened this issue 4 years ago • 3 comments

I recently was able to run Pandoc on to generate PDF right off the markdown notes in my vault.

With a bit of modification to the .md note, one can—using pandoc-xnos filter—add figure/table/equation/section numbers (and image captions). This is hugely helpful in cross-referencing within the text, and there would be no need to add a figure environment (#19). (There was an issue I had with equation environment when aligned environment was used in math blocks, and it screwed the rendered math in the compiled PDF.)

Moreover, footnotes are supported, too, and Pandoc takes care of citations (haven't tried yet) and makes quotes with curly quotation marks.

It would be great if the plugin had a command to export to a sanitized markdown file, wherein embedded notes were "flattened" (the way the plugin currently pastes the content of the embedded note), links sanitized, and image (relative) paths were corrected—both of which are taken care of already.

Pandoc requires an additional change to the way images are embedded:

The embedded image ![[figure.png]] should be converted to ![Alt text](/path/to/figure.png "Caption") or ![Caption](/path/to/figure.png). Adding {#fig:some-label} after the image would allow cross-referencing possible by calling @fig:some-label in the text.

Solutions I have in mind

Since Obsidian supports ^ for block referencing, (and given that it now supports %%comments that are not rendered in the View mode%%), I suggest using the following syntaxes that are compatible with Obsidian's View mode, thus not screwing the rendered text of the original note:

Desired feature behavior for figures

I personally would love if I can embed an image as

%%My caption here%%![[figure.png]]^my-sad-label

And it is converted to the following in the exported .md file:

![My caption here](/path/to/figure.png){#fig:my-sad-label}

Desired feature behavior for equations

One can append {#eq:my-label} at the end of the math block in the original note, which breaks the rendered math in View mode

$$
\Gamma = \sum_{i=1}^N i^2
$${#eq:a-terrible-equation}

Alternatively, if the ^ referencing (with a line break after the closing $$) would help, without making any problem in View mode:

$$
\Gamma = \sum_{i=1}^N i^2
$$
^a-terrible-equation

Are these feasible features?


(I truly appreciate your efforts and quick fixes, and I wish I could contribute by forking and pull requests. Though I have no knowledge of TypeScript and js, unfortunately. ❤️ )

psyguy avatar Feb 16 '21 20:02 psyguy

Sorry for the delayed response. I've been very busy.

Yeah I originally looked at using psn doc but wanted a more integrated workflow. Nonetheless I think this is a good feature. I'm torn on whether this belongs in this plugin or whether it should be its own and the common logic should be refactored into a library. I'll try to take a look this weekend if I can.

In the meanwhile I recall there being a markdown sanitizer plugin but I don't remember what it was called.

raineszm avatar Mar 03 '21 14:03 raineszm

Hi again and no worries—and sorry that I wasn't getting the notification for some reason.

You might be referring to the Markdown Prettifier plugin (right?), which only cleans the formatting (double spaces, coherent bullet points, etc.) What I meant by sanitization, however, was about "flattening" the embedded notes, cleaning links (such that [[ ... ]] do not appear in the output, i.e., changing [[note1.md|some note]] to some note), and correcting the path to embedded images.

I see your point on Pandoc, and that is a fair point – I can imagine Pandoc would perhaps disrupt the workflow. Though, making a Pandoc-ready markdown output shouldn't cause disruptions I guess (no? 🤔)

psyguy avatar Mar 15 '21 10:03 psyguy

Yeah. I think there's a definite use for this feature. I think it would make sense to separate into two plugins sharing a common background. I'm unfortunately very busy right now. But I'll try to get started on it when I can.

raineszm avatar Mar 16 '21 13:03 raineszm