onlyafly / number-headings-obsidian

Automatically number headings in a document in Obsidian
MIT License
104 stars 11 forks source link

[Suggestion] A simpler solution with css-counters #51

Closed anandkumar89 closed 11 months ago

anandkumar89 commented 1 year ago
/** Numbered Headings **/
.cm-content { counter-reset: h1counter h2counter h3counter h4counter h5counter h6counter; }

.HyperMD-header-1 { counter-reset: h2counter; }
.HyperMD-header-2 { counter-reset: h3counter; }
.HyperMD-header-3 { counter-reset: h4counter; }
.HyperMD-header-4 { counter-reset: h5counter; }
.HyperMD-header-5 { counter-reset: h6counter; }

.HyperMD-header-1::before {
counter-increment: h1counter;
content: counter(h1counter) ".\0000a0\0000a0";
}

.HyperMD-header-2:before {
    counter-increment: h2counter;
    content: counter(h1counter) "." counter(h2counter) ".\0000a0\0000a0";
}
.HyperMD-header-3:before {
    counter-increment: h3counter;
    content: counter(h1counter) "." counter(h2counter) "." counter(h3counter) ".\0000a0\0000a0";
}

.HyperMD-header-4:before {
    counter-increment: h4counter;
    content: counter(h1counter) "." counter(h2counter) "." counter(h3counter) "." counter(h4counter) ".\0000a0\0000a0";
}

.HyperMD-header-5:before {
    counter-increment: h5counter;
    content: counter(h1counter) "." counter(h2counter) "." counter(h3counter) "." counter(h4counter) "." counter(h5counter) ".\0000a0\0000a0";
}

.HyperMD-header-6:before {
    counter-increment: h6counter;
    content: counter(h1counter) "." counter(h2counter) "." counter(h3counter) "." counter(h4counter) "." counter(h5counter) "." counter(h6counter) ".\0000a0\0000a0";
}

preview :

Screenshot 2023-06-13 at 4 19 44 AM
anandkumar89 commented 1 year ago

Realized obsidian loads only the part of file that is visible. Rest all are hidden from DOM. So, this will not work in longer documents for which you have to scroll.

onlyafly commented 11 months ago

I've looked into this option before, but the purpose of this plugin is to put the numbers in the text.

Could be an interesting idea for a different plugin, however!