Hide comments in live preview but not in source mode (including headings)

Same question as in Hide comment in live preview but not in source mode

The solution presented there only seems to work for single line comments.
It will not work work for paragraphs with headings.
Is this possible ?

I found the solution and here it is for those interested :

/* Hide single-line comments in live preview mode */
.is-live-preview .cm-line:not(.cm-active):has(.cm-comment-start, .cm-comment-end) * {
    visibility: hidden;
}

/* Hide multi-line comments in live preview mode */
.is-live-preview .cm-line:not(.cm-active):has(.cm-comment-start) ~ .cm-line:not(.cm-active):has(.cm-comment-end) * {
    visibility: hidden;
}

/* Hide intermediate lines of multi-line comments in live preview mode */
.is-live-preview .cm-line:not(.cm-active):has(.cm-comment-start) ~ .cm-line:not(.cm-active):not(:has(.cm-comment-end)) * {
    visibility: hidden;
}

/* Show comments when the line is active or in source mode */
.cm-active .cm-comment-start, .cm-active .cm-comment-end,
.cm-s-obsidian .cm-comment-start, .cm-s-obsidian .cm-comment-end {
    visibility: visible;
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.