Embed file as a code/pre block (i.e. contents, with no processing)

Things I have tried

I can tranclude using ![[ ]] easily enough. But that actually renders the file, i.e. processes the markdown.

I want to include the raw content of the file, as if it were inside a pre/code block. Is there a way to do that?

(PS: how do I get a preview when posting a topic?)

What I’m trying to do

Hi @ksdavidc

The raw transclusion I am not sure if that can be done without a plugin, I also don’t know if a plugin that does that exists.

But for the posting, does you post window have a set of chevrons on the lower right side? if so click that and it should open a side window with a preview.

Chevrons circled in red:

Example of side preview pane:

1 Like

On mobile, the preview button looks for me like a computer screen rather than the arrows, but it is in the same lower right-hand corner location that JimK pointed out!

I don’t have a great answer to your question @ksdavidc but here are some things to check out and experiment with:

  • I just discovered the “Hover Editor” community plugin, which seems like it can maybe be tweaked to help: It can be set to open things in edit mode by default. The embed would still be rendered MD in your page, but you could have a (potentially pinned) hover window open next to it with the source.
  • Do you want the page rendered sometimes, or do you always want the source? Could you put the source you want to not render inside a codeblock?
# My markdown source that will not get rendered.
## The headings stay small. 
Labeling my codeblock as markdown (by putting the word "markdown" next to the starting back-ticks) seems to help the forum know what formatting to apply.
``` %% That was the end of the code block, but I put the codeblock inside another codeblock to make it display in the forum, so this comment is still being treated like code. %%
1 Like

thanks, found the preview button, obscured by a forum welcome message.

I want to be able to do both, by default render as is, but via some means to have it just output the raw, and in such as way that that can be inside of another container, e.g. a blockquote.

For example, I might want a render, and then show the code that generated that rendering.

1 Like

Thank you for the reply. I don’t think your suggestions are quite what I am looking for.

What I am asking is, if in obsidian is it possible, or has someone has found a way, to do something like (i.e. NOT this, but a modification of this, i.e. the transclusion [[ and ]] markers)


but have it output the unprocessed contents of the file.

Right now, if the contents of <filename.md> are:

*this text*




this text

If my modified “unprocessed transcluder” were, say “[! !]” I could the type this in Obsidian:

outputs as follows:

to get:

**this text**
outputs as follows:
this text

Effectively, since I am new to Obsidian, I wondered if there is already a way to do this. Of course there may be other ways to achieve the effect other than a “modified transcluder”. That is just one approach that I imagine, and maybe someone else has come up with a completely different, probably smarter, way to do it.

In fact, there could be other desirable features (like being able to put it into a blockquote, or other processing step) that I could imagine being useful.

Of course it might be something I would have to code myself, but I would rather not reinvent the wheel.

1 Like

Hi ksdavidc, yes you are right that I do not know how to do what you are looking for. One more piece that might be related, however: the output of Obsidian’s built-in search gives the unprocessed contents of files, and you can embed those via query blocks. I do not know if you can get the full portion of the file that you want to display to show up as a search result, though. There are community plugins that expand the query functionality, which may or may not be helpful here.

Otherwise, you can search the “Feature Requests” category of this forum for words like “unrendered” or “not rendered” “transclusion” and make your own with your [! !] example if you do not see what you are looking for.
Good luck!

Thanks for the reply and suggestions. I’ll see if it something I end up needing often, and them maybe take the next step…

1 Like

Please have a look at this https://github.com/almariah/embed-code-file

1 Like

Thanks. It might be useful for others, but in my case I am not trying to transclude code, but markdown file into a pre block.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.