Hiding YAML in Edit Mode

What specifically are you pasting?

This is Markdown - eg a .md file not a .js file:

<%*
// Get the current cursor location
const cursor = app.workspace.activeLeaf.view.editor.getCursor()
// Move the cursor to the start of the document
app.workspace.activeLeaf.view.editor.setCursor({line: 0, ch: 0})
// Fold/unfold the YAML
app.commands.executeCommandById('editor:toggle-fold')
// Move the cursor back to the original location
app.workspace.activeLeaf.view.editor.setCursor(cursor)
%>

If you’re creating the Javascript file for use in tp.user, it would this format:

function main() {
    const cursor = app.workspace.activeLeaf.view.editor.getCursor()
    app.workspace.activeLeaf.view.editor.setCursor({line: 0, ch: 0})
    app.commands.executeCommandById('editor:toggle-fold')
    app.workspace.activeLeaf.view.editor.setCursor(cursor)
    return ''
}
module.exports = main
1 Like


What do you mean I am in the live mode, but yaml still there

This is great stuff, thank you @AlanG !

1 Like

can i also just hide the banner while i keep my YAML tags ? I like the metadata in the view mode, but hate that the banner is part of that

2 Likes

It can be implemented like “Backlinks Panel” & “Toggle backlinks in document”.
Same thing, two view, being able to choose the experience.

Also, being able to choose showing YAML at the bottom or top of the document (on Live Preview) would be VERY welcomed.

1 Like

Thank you! It worked for me :D!

1 Like

Agreed, I even think there should be a separate section in the UI for note metadata so it isn’t in the main note. It could in reality be at the header still, but the UI could stick it in the sidebar for a much cleaner appearance.

2 Likes

This was very helpful, thank you.

Hiding YAML with CSS seemed a bit aggressive to me and was looking for an alternative.

Thanks much for the fold/unfold Templater tip @AlanG! It’s :kissing_smiling_eyes::pinched_fingers:

3 Likes

I had this issue and here’s how I solved it. The problem was that I created the .js file in Obsidian as an .md file, and then renamed the extension .js using the file explorer. That caused an issue, perhaps something to do with how the spaces/new-lines were garbled. When instead I pasted the code into a blank .js file, it worked fine.

This will be possible in v1.4. Settings->Editor->Show File Properties

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