Hide comment in live preview but not in source mode

I’d like to hide comments. It would be nice if they reappeared when the cursor is on them, but just having them viewable in source mode would be OK. Any ideas?

This CSS snippet hides the comment markers (%%) but not the whole comment. It’s nice that the full comment syntax reappears when the cursor is on them:

cm-line:not(.cm-active) .cm-comment.cm-comment-start,
.cm-line:not(.cm-active) .cm-comment.cm-comment-end {
display: none;
}

I can totally hide comments everywhere with this:

.cm-line:not(.cm-active) .cm-comment
{ display: none; }

But it also hides them in source mode.

I thought that I might be able to limit source mode hiding by specifying the live preview mode, as in the two snippets below, but they also hide comments everywhere:

Hides everywhere:

.markdown-preview-view .cm-line .cm-comment {
display: none;
}

Hides everywhere:

.cm-s-obsidian .cm-line .cm-comment {
display: none;
}

Give this a try:

.is-live-preview .cm-line:not(.cm-active):has(.cm-comment-start, .cm-comment-end) * {
    visibility: hidden;
}

CleanShot 2024-03-23 at 09.16.43

// moved to custom CSS

1 Like

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