diff --git a/inventory/static/js/components/markdown.js b/inventory/static/js/components/markdown.js new file mode 100644 index 0000000..29c8cbc --- /dev/null +++ b/inventory/static/js/components/markdown.js @@ -0,0 +1,30 @@ +const MarkDown = { + parseOptions: { gfm: true, breaks: false }, + sanitizeOptions: { ADD_ATTR: ['target', 'rel'] }, + + toHTML(md) { + const raw = marked.parse(md || "", this.parseOptions); + return DOMPurify.sanitize(raw, this.sanitizeOptions); + }, + + enhance(root) { + if (!root) return; + for (const a of root.querySelectorAll('a[href]')) { + a.setAttribute('target', '_blank'); + a.setAttribute('rel', 'noopener noreferrer nofollow'); + a.classList.add('link-success', 'link-underline', 'link-underline-opacity-0', 'fw-semibold'); + } + for (const t of root.querySelectorAll('table')) { + t.classList.add('table', 'table-sm', 'table-striped', 'table-bordered'); + } + for (const q of root.querySelectorAll('blockquote')) { + q.classList.add('blockquote', 'border-start', 'border-5', 'border-success', 'mt-3', 'ps-3'); + } + }, + + renderInto(el, md) { + if (!el) return; + el.innerHTML = this.toHTML(md); + this.enhance(el); + } +}; diff --git a/inventory/static/js/utils/json.js b/inventory/static/js/utils/json.js new file mode 100644 index 0000000..44edcba --- /dev/null +++ b/inventory/static/js/utils/json.js @@ -0,0 +1,7 @@ +function readJSONScript(id, fallback = "") { + const el = document.getElementById(id); + if (!el) return fallback; + const txt = el.textContent?.trim(); + if (!txt) return fallback; + try { return JSON.parse(txt); } catch { return fallback; } +} diff --git a/inventory/templates/inventory_note.html b/inventory/templates/inventory_note.html index 89f1df6..90bf445 100644 --- a/inventory/templates/inventory_note.html +++ b/inventory/templates/inventory_note.html @@ -28,89 +28,76 @@ + + \ No newline at end of file + function escapeForTextarea(s) { + return (s ?? "").replace(/&/g,'&').replace(//g,'>'); + } + diff --git a/inventory/templates/update_list.html b/inventory/templates/update_list.html index 3fb0973..582442e 100644 --- a/inventory/templates/update_list.html +++ b/inventory/templates/update_list.html @@ -16,7 +16,7 @@