Show markdown only when there is content

This commit is contained in:
Magnus Åhall 2026-05-20 18:49:43 +02:00
parent 45cbd49345
commit 84181858c8

View file

@ -41,6 +41,7 @@ export class N2NodeUI extends CustomHTMLElement {
_mbus.subscribe('NODE_UI_OPEN', event => { _mbus.subscribe('NODE_UI_OPEN', event => {
this.node = event.detail.data this.node = event.detail.data
this.showMarkdown(true)
this.render() this.render()
}) })
@ -68,10 +69,8 @@ export class N2NodeUI extends CustomHTMLElement {
this.elNodeMarkdown.innerHTML = this.marked.parse(this.elNodeContent.value) this.elNodeMarkdown.innerHTML = this.marked.parse(this.elNodeContent.value)
}// }}} }// }}}
takeFocus() {// {{{ takeFocus() {// {{{
console.log('taking focus', this.showMarkdown())
if (this.showMarkdown()) { if (this.showMarkdown()) {
this.elNodeMarkdown.focus() this.elNodeMarkdown.focus()
console.log(this.elNodeMarkdown)
} else } else
this.elNodeContent.focus() this.elNodeContent.focus()
}// }}} }// }}}
@ -83,7 +82,12 @@ export class N2NodeUI extends CustomHTMLElement {
return this.node?.isModified() return this.node?.isModified()
}// }}} }// }}}
showMarkdown(state) {// {{{ showMarkdown(state) {// {{{
switch (state) { // No point in showing markdown if there is no data.
// If there is no data, it will show a blank page regardless, and the user will most
// likely want to edit content, which can't be done in markdown.
const show = this.node.content().trim() !== '' && state
switch (show) {
case true: case true:
this.elNodeMarkdown.innerHTML = this.marked.parse(this.elNodeContent.value) this.elNodeMarkdown.innerHTML = this.marked.parse(this.elNodeContent.value)
this.elIconMarkdown.src = `/images/${_VERSION}/icon_markdown.svg` this.elIconMarkdown.src = `/images/${_VERSION}/icon_markdown.svg`