Code blocks in Obsidian notes automatically render with line wrapping. A sensible default of course, but in some cases the line wrapping can ruin the look or legibility of a code snippet. Here is an approach to disable line wrapping on selected notes (using Obsidian 1.6.5 here).
Create a new (or use an existing)
CSS snippet
in your Obsidian vault's snippets folder (.obsidian/snippets
),
for example code-blocks.css
, with this CSS rule:
/* Don't wrap codeblocks */
.code-nowrap .HyperMD-codeblock,
.code-nowrap pre > code {
white-space: pre;
}
(To activate this snippet, you first might have to reload/enable it as explained in the CSS snippet docs)
Then, on a note where you want to disable line wrapping of code blocks: add a property named "cssclasses" with value "code-nowrap".
That should do the trick.