Hide comment 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?

This is the solution :

/* 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;
}