{
  "name": "vue-example-save-markdown",
  "title": "vue-example-save-markdown",
  "type": "registry:block",
  "description": "Save and load documents as Markdown format.",
  "registryDependencies": [],
  "dependencies": [
    "prosekit@^0.23.2",
    "rehype-parse",
    "rehype-remark",
    "remark-gfm",
    "remark-html",
    "remark-parse",
    "remark-stringify",
    "unified"
  ],
  "files": [
    {
      "path": "registry/src/vue/examples/save-markdown/editor.vue",
      "type": "registry:component",
      "target": "components/editor/examples/save-markdown/editor.vue",
      "content": "<script setup lang=\"ts\">\nimport 'prosekit/basic/style.css'\nimport 'prosekit/basic/typography.css'\n\nimport { defineBasicExtension } from 'prosekit/basic'\nimport { createEditor, jsonFromHTML } from 'prosekit/core'\nimport { ProseKit, useDocChange } from 'prosekit/vue'\nimport { ref } from 'vue'\n\nimport { htmlFromMarkdown, markdownFromHTML } from './markdown.ts'\n\n// A list of saved documents, stored as Markdown strings\nconst records = ref<string[]>([])\n// Whether there are unsaved changes\nconst hasUnsavedChange = ref(false)\n// A key to force a re-render of the editor\nconst key = ref(1)\n\nconst extension = defineBasicExtension()\nconst editor = createEditor({ extension })\n\nfunction handleDocChange() {\n  hasUnsavedChange.value = true\n}\nuseDocChange(handleDocChange, { editor })\n\nfunction handleSave() {\n  const html = editor.getDocHTML()\n  const record = markdownFromHTML(html)\n  records.value = [...records.value, record]\n  hasUnsavedChange.value = false\n}\n\nfunction handleLoad(record: string) {\n  const html = htmlFromMarkdown(record)\n  editor.setContent(jsonFromHTML(html, { schema: editor.schema }))\n  hasUnsavedChange.value = false\n  key.value += 1\n}\n</script>\n\n<template>\n  <div class=\"box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-[canvas] text-black dark:text-white\">\n    <button\n      :disabled=\"!hasUnsavedChange\"\n      class=\"m-1 border border-solid bg-white px-2 py-1 text-sm text-black disabled:cursor-not-allowed disabled:text-gray-500\"\n      @click=\"handleSave\"\n    >\n      {{ hasUnsavedChange ? 'Save' : 'No changes to save' }}\n    </button>\n    <ul class=\"border-b border-t border-solid text-sm\">\n      <li\n        v-for=\"(record, index) in records\"\n        :key=\"index\"\n        class=\"m-1 flex gap-2\"\n      >\n        <button\n          class=\"border border-solid bg-white px-2 py-1 text-black\"\n          @click=\"handleLoad(record)\"\n        >\n          Load\n        </button>\n        <span class=\"flex-1 overflow-x-scroll p-2\">\n          <pre>{{ record }}</pre>\n        </span>\n      </li>\n    </ul>\n    <ProseKit :key=\"key\" :editor=\"editor\">\n      <div class=\"relative w-full flex-1 box-border overflow-y-auto\">\n        <div :ref=\"(el) => editor.mount(el as HTMLElement | null)\" class=\"ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500\"></div>\n      </div>\n    </ProseKit>\n  </div>\n</template>\n"
    },
    {
      "path": "registry/src/vue/examples/save-markdown/index.ts",
      "type": "registry:component",
      "target": "components/editor/examples/save-markdown/index.ts",
      "content": "export { default as ExampleEditor } from './editor.vue'\n"
    },
    {
      "path": "registry/src/vue/examples/save-markdown/markdown.ts",
      "type": "registry:component",
      "target": "components/editor/examples/save-markdown/markdown.ts",
      "content": "import rehypeParse from 'rehype-parse'\nimport rehypeRemark from 'rehype-remark'\nimport remarkGfm from 'remark-gfm'\nimport remarkHtml from 'remark-html'\nimport remarkParse from 'remark-parse'\nimport remarkStringify from 'remark-stringify'\nimport { unified } from 'unified'\n\nexport function markdownFromHTML(html: string): string {\n  return unified()\n    .use(rehypeParse)\n    .use(rehypeRemark)\n    .use(remarkGfm)\n    .use(remarkStringify)\n    .processSync(html)\n    .toString()\n}\n\nexport function htmlFromMarkdown(markdown: string): string {\n  return unified()\n    .use(remarkParse)\n    .use(remarkGfm)\n    .use(remarkHtml)\n    .processSync(markdown)\n    .toString()\n}\n"
    }
  ],
  "meta": {
    "hasIcons": false,
    "hidden": false,
    "story": "save-markdown",
    "framework": "vue",
    "accumulatedFiles": [
      "registry/src/vue/examples/save-markdown/editor.vue",
      "registry/src/vue/examples/save-markdown/index.ts",
      "registry/src/vue/examples/save-markdown/markdown.ts"
    ],
    "internalDependencies": []
  },
  "$schema": "https://ui.shadcn.com/schema/registry-item.json"
}
