mProjectsCode / obsidian-js-engine-plugin

https://www.moritzjung.dev/obsidian-js-engine-plugin-docs/
GNU General Public License v3.0
66 stars 4 forks source link

Is it possible to embed code blocks inside tables? #17

Closed claremacrae closed 3 weeks ago

claremacrae commented 3 months ago

I have been using DataView to generate tables that contain code blocks. The code blocks are of course Tasks searches.

I am hoping to replace this with using js-engine to generate tables with code blocks.

Table with single-line cells

This js-engine code block creates a trivial table:

let markdownBuilder = engine.markdown.createBuilder();
markdownBuilder.createTable(['col1', 'col2'], [['value 1', 'value 2']]);
return markdownBuilder;

image

Attempt at creating table with a code block in

I've tried various iterations of this js-engine code block to create a table with a code block in:

let markdownBuilder = engine.markdown.createBuilder();
let codeBlock = `~~~text
Hello World
~~~`
markdownBuilder.createTable(['col1', 'col2'], [['value 1', codeBlock]]);
return markdownBuilder;

They all seem to display some of the code block text outside the table...

image

The question!

Is it currently possible to put (rendered) code blocks inside js-engine tables please?

mProjectsCode commented 3 months ago

No, the markdown spec does not allow that. The markdown builder generates an actual markdown string which is then passed to Obsidians markdown renderer.

claremacrae commented 3 months ago

Ah right, OK thanks.

Is there a way to use js-engine to build raw HTML then?

mProjectsCode commented 3 months ago

It's JavaScript, so you can use the normal web APIs. Global Obsidian helper functions and prototype extensions should work as well.

mProjectsCode commented 3 months ago

Things exported under the obsidian namespace should be available via the obsidian object, so e.g. new obsidian.Notice("hello")

claremacrae commented 3 months ago

Ah well, thank you very much for the replies.

mProjectsCode commented 3 weeks ago

The only way I see to get code blocks into tables would be to use HTML tables, but then the codeblocks would need to be created with HTML as well and markdown post processors wouldn't run on those.

claremacrae commented 3 weeks ago

Understood. I have no idea how dataview manages it, but it does. So that is always available as a fall-back.

claremacrae commented 3 weeks ago

Any chance you could change this from completed to won’t fix, though please, for transparency.