A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
1.6 KiB

  1. import { MarkdownParser } from "prosemirror-markdown";
  2. import markdownit from "markdown-it";
  3. import { writeFreelySchema } from "./schema";
  4. export const writeFreelyMarkdownParser = new MarkdownParser(
  5. writeFreelySchema,
  6. markdownit("commonmark", { html: true }),
  7. {
  8. blockquote: { block: "blockquote" },
  9. paragraph: { block: "paragraph" },
  10. list_item: { block: "list_item" },
  11. bullet_list: { block: "bullet_list" },
  12. ordered_list: {
  13. block: "ordered_list",
  14. getAttrs: (tok) => ({ order: +tok.attrGet("start") || 1 }),
  15. },
  16. heading: {
  17. block: "heading",
  18. getAttrs: (tok) => ({ level: +tok.tag.slice(1) }),
  19. },
  20. code_block: { block: "code_block", noCloseToken: true },
  21. fence: {
  22. block: "code_block",
  23. getAttrs: (tok) => ({ params: tok.info || "" }),
  24. noCloseToken: true,
  25. },
  26. hr: { node: "horizontal_rule" },
  27. image: {
  28. node: "image",
  29. getAttrs: (tok) => ({
  30. src: tok.attrGet("src"),
  31. title: tok.attrGet("title") || null,
  32. alt: (tok.children !== null && typeof tok.children[0] !== 'undefined' ? tok.children[0].content : null),
  33. }),
  34. },
  35. hardbreak: { node: "hard_break" },
  36. em: { mark: "em" },
  37. strong: { mark: "strong" },
  38. link: {
  39. mark: "link",
  40. getAttrs: (tok) => ({
  41. href: tok.attrGet("href"),
  42. title: tok.attrGet("title") || null,
  43. }),
  44. },
  45. code_inline: { mark: "code", noCloseToken: true },
  46. html_block: {
  47. node: "readmore",
  48. getAttrs(token) {
  49. // TODO: Give different attributes depending on the token content
  50. return {};
  51. },
  52. },
  53. }
  54. );