Skip to content

Spot it. Save it. Free, local-first Chrome extension for images, videos and prompts. Explore 2,000+ curated cases and connect your library to AI Agents via MCP. 提示词导演

1.2 KB
Raw Blame
import { articleBlockIsMarkdown } from "./article-document.js";
import { renderMarkdownDocument } from "./markdown-renderer.js";

// Reading markup must never become the source saved by the editor.
export function renderArticleBlockText(node, block, { editing = false, entry, markdownOptions } = {}) {
  const markdown = articleBlockIsMarkdown(block, entry);
  node.classList.toggle("markdown-reader", markdown && !editing);
  if (markdown && editing) {
    const editor = node.ownerDocument.createElement("textarea");
    editor.className = "prompt-editor article-markdown-editor";
    editor.value = block.text;
    node.replaceChildren(editor);
    return;
  }
  if (markdown && !editing) {
    node.replaceChildren(...renderMarkdownDocument(block.text, markdownOptions).childNodes);
    return;
  }
  if (block.kind !== "list" || editing) {
    node.textContent = block.text;
    return;
  }
  const list = node.ownerDocument.createElement(block.ordered ? "ol" : "ul");
  for (const text of block.text.split("\n").filter(line => line.trim())) {
    const item = node.ownerDocument.createElement("li");
    item.textContent = text;
    list.append(item);
  }
  node.replaceChildren(list);
}