rasendubi / uniorg

An accurate Org-mode parser for JavaScript/TypeScript
https://oleksii.shmalko.com/uniorg
GNU General Public License v3.0
249 stars 23 forks source link

extending export-block to support more backends #101

Open ispringle opened 5 months ago

ispringle commented 5 months ago

https://github.com/rasendubi/uniorg/blob/466fd42940cd2f83d6ccdd888c1d5938b8f572eb/packages/uniorg-rehype/src/org-to-hast.ts#L335

Currently the export-block supports only HTML. It'd be great if this was extensible so additional backends could be provided and handled. For example, I'd like to be able to use an export block to generate graphs with MermaidJS. It'd be great if we could extend this with an object of other backends and then a function that would return the proper ast object.

rasendubi commented 4 months ago

Hey. uniorg-rehype is specifically an org-to-html converter (rehype/hast is an AST representation of HTML), so I'm not sure what you mean by supporting more backends. There are multiple ways to plug-in more functionality like mermaidjs though.

First, it's possible to add more unified plugins that would transform AST before (or after) uniorg-rehype. So, for example one could add a plugin that transforms #+begin_src mermaid or #+begin_mermaid ("special block") blocks to a proper export-block (which would then get exported by uniorg-rehype).

Second, uniorg-rehype accepts a handlers option, which allows to override how certain blocks are exported. So you can override how export-block is handled

Hope this helps

venikx commented 3 months ago

https://github.com/rasendubi/uniorg/blob/466fd42940cd2f83d6ccdd888c1d5938b8f572eb/packages/uniorg-rehype/src/org-to-hast.ts#L335

Currently the export-block supports only HTML. It'd be great if this was extensible so additional backends could be provided and handled. For example, I'd like to be able to use an export block to generate graphs with MermaidJS. It'd be great if we could extend this with an object of other backends and then a function that would return the proper ast object.

Do you export these mermaids with org-export? If you just want your pages to convert mermaid code to diagrams. You should be able to embed the mermaid.js script on your page, and then run mermaid.initialize() which will transform all mermaid code to diagrams.