Describe the bug
When a code block uses the Rmd/Quarto-style language identifier (e.g. ```{python}), addToCodeBlock rewrites the classes of the parent <pre> element by assignment:
// src/RunButton.ts:126 (addToCodeBlock)
codeBlock.parentElement.className = codeBlock.className;
This replaces the entire class list of the <pre> instead of adding to it. Any classes previously added to the <pre> by Obsidian core or other plugins are silently removed.
To Reproduce
- Install a plugin that decorates code blocks at the
<pre> level (e.g. Code Styler, which adds code-styler-pre and fold-state classes).
- Create a note with a
```{python} block.
- Switch to reading mode.
Expected behavior
The plugin should only adjust the classes it needs (e.g. via classList.add / classList.replace), preserving classes set by Obsidian or other plugins.
Actual behavior
All pre-existing <pre> classes are wiped. Downstream effects observed with Code Styler (reported as mayurankv/Obsidian-Code-Styler#334):
- Code block styling and folding state are lost for
{lang} blocks.
- The copy button ends up mis-positioned / broken because the CSS selectors that place it depend on the removed classes.
- Unload/cleanup routines of the other plugin can no longer find the block (
pre.code-styler-pre selector misses), leaving stale header elements behind.
Suggested fix
// Instead of overwriting:
codeBlock.parentElement.className = codeBlock.className;
// Only add what's needed, e.g.:
codeBlock.classList.forEach((cls) => codeBlock.parentElement.classList.add(cls));
(or the minimal equivalent that adds the rewritten language-x { classes without clearing the rest.)
Environment
- Plugin version: 2.1.2
- Obsidian version: 1.8+
- OS: macOS (likely affects all platforms)
Describe the bug
When a code block uses the Rmd/Quarto-style language identifier (e.g.
```{python}),addToCodeBlockrewrites the classes of the parent<pre>element by assignment:This replaces the entire class list of the
<pre>instead of adding to it. Any classes previously added to the<pre>by Obsidian core or other plugins are silently removed.To Reproduce
<pre>level (e.g. Code Styler, which addscode-styler-preand fold-state classes).```{python}block.Expected behavior
The plugin should only adjust the classes it needs (e.g. via
classList.add/classList.replace), preserving classes set by Obsidian or other plugins.Actual behavior
All pre-existing
<pre>classes are wiped. Downstream effects observed with Code Styler (reported as mayurankv/Obsidian-Code-Styler#334):{lang}blocks.pre.code-styler-preselector misses), leaving stale header elements behind.Suggested fix
(or the minimal equivalent that adds the rewritten
language-x {classes without clearing the rest.)Environment