mgmeyers / obsidian-contextual-typography

GNU General Public License v3.0
163 stars 9 forks source link

Add attribute describing current heading level #3

Open tarheels100 opened 3 years ago

tarheels100 commented 3 years ago

Would it be possible to slightly extend this plugin to also add an attribute to the div tags specifying the current heading level? This would be very helpful in being able to apply specific CSS styling to text in specific heading levels. Here is an example:

# H1
Some text at H1 level.

## H2
Some text at H2 level.

# H1 again
Some more test at H1 level.

would produce

<div heading-level="h1"><h1>H1</h1></div>
<div heading-level="h1"><p>Some text at H1 level.</p></div>
<div heading-level="h2"><h2>H2</h2></div>
<div heading-level="h2"><p>Some text at H2 level.</p></div>
<div heading-level="h1"><h1>H1 again</h1></div>
<div heading-level="h1"><p>Some more text at H1 level.</p></div>
mgmeyers commented 3 years ago

@tarheels100 I looked into this, and unfortunately it doesn't seem like it's currently possible, at least not in any way that would be reliable in the long term. Obsidian only provides an individual block to process and I don't have any access to information about the block's siblings. I'll keep an eye out for some other way I might achieve this.

tarheels100 commented 3 years ago

@mgmeyers Thanks for looking into it. Based on what you've already implemented, I figured you would have a good idea of how feasible this would be. It's a little unfortunate how headings are handled in Obsidian, and more generally in HTML and CSS, because this sort of "style an element based on its heading" issue becomes very difficult to solve outside of manually assigning heading-level classes to every element.

On a side note, do know of any good resources to learn about Obsidian's plugin system and what aspects of its internals are exposed through the API? Do you just learn by inspecting obsidian.d.ts and poking around?

Thanks again for the feedback; feel free to close this issue if you'd like.