How to hide HTML code or Markdown source code in Obsidian?

In edit mode, when you click on a tag or move the cursor to a tag, the Markdown or HTML source code is displayed in the editor, such as # ## ** ** . How can you hide the source code in edit mode and only display the Markdown or HTML source code when clicking with Ctrl?

You’ve got three modes to play around with:

  • Source mode – Where it always shows everything as markdown
  • Live preview – Where the current line (or tag) is viewed as markdown
  • Reading view – Where everything is always shown as html

So is the solution to your issue to just use Reading view? And then switch to Source mode (and not live preview) when you want to see the markdown text?

1 Like

I would like the current line (or tag) in Live preview mode not to display markdown, and only show the markdown when the left mouse button and ctrl keys are pressed simultaneously. I have attempted to write a plugin that partially achieves this functionality (markdown source code does not appear when clicking on a tag with the left mouse button), but the markdown source code still appears when the cursor is moved to the target tag. I would like to know how to prevent the markdown source code from showing at all times in Live preview mode, except when the left mouse button and ctrl keys are pressed together.

Here is the main code of my plugin:

editor.addEventListener("click", (evt: MouseEvent) => {
    this.evt = evt;
    if (this.isOpen) {

        let target = evt.target as HTMLLinkElement;

        if (!evt.altKey) {

            evt.preventDefault();

            target.setAttribute("contenteditable", "true");
            target.focus();

            // keep link function
            if (
                target.tagName === "A" &&
                target.href &&
                evt.ctrlKey
            ) {
                window.open(target.href, "_blank");
            }
        }
    } else {
        evt = this.evt;
    }
});

Did you end up finding a workaround? I’m facing the same problem right now, and my approach was to just hide the tags by setting their display to none.

.cm-tag {
    display: none !important;
}

but the problem is obsidian still thinks that they exists so they’re just invisible and when you move the cursor to the tags, it appears as it’s not moving. I presume it’s because the tags are still there and obsidian still moves the cursor through the tags, we can’t just see them.

Demonstration of this behavior:
24-02-09 - Lif - x

Original Text before hiding the tags:
image

ps. “o” tags doesn’t exist and it’s for demonstration purposes only

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