With code styler if you have a codeblock with only one line, the indentation is reduced.
Describe the bug
I had a border of 6px for codeblocks and if I had a block with only one line, I noticed that part of the first letter got "eaten" (see screenshot in the screenshot section).
I asked Google Gemini (pro) and it identified these bits as the cause. Of course it's AI and might not be right, but it generally finds the cause even if doesn't give you the right way to fix it. So, I thought I'd add them here if they're helpful.
When a block has only one line, the logic that slices the array:
return { codeSection: lines.slice(startIndex, endIndex + 1).join("\n"), startLine: startIndex + 1 };
Often fails to preserve leading whitespace if startIndex and endIndex are identical, especially if a .trim() call is being inherited from the global string processing.
The plugin uses a regex to separate the "language/parameters" line from the "content." In the parseReferenceParameters function, there is a replacement happening:
source = source.replace(/^([^:]+):(.+)\n/, "$1: $2\n")
If you have a single line like: print("hello") the regex engine might misinterpret the leading spaces as part of a potential YAML key-value pair if there are colons in the line, causing it to "reformat" the indentation away.
Steps to reproduce
- Create a codeblock with 1 line.
- Observe behavior:
a) Add a thick border (6px or more) and it starts eating away your code on one-line blocks
b) Add a second line -> you see the indent being increased.
Example codeblock where the behavior is clear (it's a powershell codeblock, but the language is irrelevant, the capital C just get's "eaten" easier than for example i in import in python):
C:\Windows\System32\cmd.exe /k "%USERPROFILE%\.windot\term_cmd\profile.cmd"
Expected behaviour
Code blocks with one line should have the same indentation than blocks with multiple lines.
Current behaviour
One line code blocks have visibly less indentation than multiple line codeblocks
Environment
- Plugin Version: 1.1.7
- Obsidian Version: 1.11.7
- Platform: Desktop
- OS: Windows
- Theme: My personal theme, but I've tested this with default theme and the behavior is the same
- CSS Snippets: Yes, but like for theme, this behavior persists without snippets.
Screenshots
Additional context
There are no console errors: this seems to be a behavioral thing in the plugin, not caused by an error.
With code styler if you have a codeblock with only one line, the indentation is reduced.
Describe the bug
I had a border of 6px for codeblocks and if I had a block with only one line, I noticed that part of the first letter got "eaten" (see screenshot in the screenshot section).
I asked Google Gemini (pro) and it identified these bits as the cause. Of course it's AI and might not be right, but it generally finds the cause even if doesn't give you the right way to fix it. So, I thought I'd add them here if they're helpful.
When a block has only one line, the logic that slices the array:
Often fails to preserve leading whitespace if
startIndexandendIndexare identical, especially if a.trim()call is being inherited from the global string processing.The plugin uses a regex to separate the "language/parameters" line from the "content." In the
parseReferenceParametersfunction, there is a replacement happening:If you have a single line like:
print("hello")the regex engine might misinterpret the leading spaces as part of a potential YAML key-value pair if there are colons in the line, causing it to "reformat" the indentation away.Steps to reproduce
a) Add a thick border (6px or more) and it starts eating away your code on one-line blocks
b) Add a second line -> you see the indent being increased.
Example codeblock where the behavior is clear (it's a powershell codeblock, but the language is irrelevant, the capital C just get's "eaten" easier than for example i in import in python):
C:\Windows\System32\cmd.exe /k "%USERPROFILE%\.windot\term_cmd\profile.cmd"Expected behaviour
Code blocks with one line should have the same indentation than blocks with multiple lines.
Current behaviour
One line code blocks have visibly less indentation than multiple line codeblocks
Environment
Screenshots
Additional context
There are no console errors: this seems to be a behavioral thing in the plugin, not caused by an error.