stargrey / obsidian-better-codeblock

Add title, line number to Obsidian code block
MIT License
109 stars 10 forks source link

fix: use textContext for calculate line num height with escaped HTML characters #15

Closed edentsai closed 1 year ago

edentsai commented 1 year ago

use Node.textContext instead of Element.innerHTML for calculate line num height with escaped HTML characters.

Fix the issues: https://github.com/stargrey/obsidian-better-codeblock/issues/12

When code block contains HTML characters, the code-block-linenum span will be set wrong height: 0px, for example:

the Markdown code block in Obsidian:

```html
<!-- Hello World -->
<div>
    Hello World
</div>

the rendered HTML result in Reading view:

```html
<span class="code-block-linenum-wrap">
    <span class="code-block-linenum" style="height: 0px;"></span>
    <span class="code-block-linenum" style="height: 0px;"></span>
    <span class="code-block-linenum" style="height: 24px;"></span>
    <span class="code-block-linenum" style="height: 0px;"></span>
</span>

Reference: