项目作者: novacbn

项目描述 :
Simple Snowpack plugin for preprocessing Markdown files to HTML via rehype / remark
高级语言: TypeScript
项目地址: git://github.com/novacbn/snowpack-plugin-markdown.git
创建时间: 2020-12-03T21:53:40Z
项目社区:https://github.com/novacbn/snowpack-plugin-markdown

开源协议:MIT License

下载


snowpack-plugin-markdown

NOTE: This plugin comes preconfigured to parse JSON, TOML, and YAML Frontmatter!

Description

Simple Snowpack plugin for preprocessing Markdown files to HTML via rehype / remark

Sample

  1. // Below, we're importing `remark`-based plugins that will give our
  2. // header text GitHub-style `id=""` slugs. And then automatically wrap them
  3. // in hoverable links
  4. const headings = require("remark-autolink-headings");
  5. const slug = require("remark-slug");
  6. // Next, we'll tell Snowpack to use the Markdown plugin and utilize
  7. // the `remark`-based plugins
  8. module.exports = {
  9. plugins: [
  10. [
  11. "snowpack-plugin-markdown",
  12. {
  13. remark: [slug, headings],
  14. },
  15. ],
  16. ],
  17. mount: {
  18. public: "/",
  19. src: "/_dist_",
  20. },
  21. };

unified.js Plugins

You can find plugins from the unified.js ecosystem that can work with this Snowpack plugin:

Options

  1. /**
  2. * Represents the options passable to `snowpack-plugin-markdown`
  3. */
  4. interface IMarkdownPluginOptions extends ICompileOptions {
  5. /**
  6. * Represents the file extensions used for denote which files
  7. * will be parsed by the plugin
  8. */
  9. extensions: string[];
  10. /**
  11. * Represents options passable to `remark-rehype` for Markdown (MDAST) -> HTML (HAST) conversion
  12. * See more information at: https://github.com/remarkjs/remark-rehype#api
  13. */
  14. mdast2hast: IMDASTToHASTOptions;
  15. /**
  16. * Represents options passable to `@starptech/prettyhtml-hast-to-html` for HTML stringification
  17. * See more information at: https://github.com/Prettyhtml/prettyhtml/tree/master/packages/prettyhtml-hast-to-html#api
  18. */
  19. stringify: IHASTToHTMLOptions;
  20. /**
  21. * Represents that options frontmatter types configured for parsing to `remark-frontmatter`
  22. * See more information at: https://github.com/remarkjs/remark-frontmatter#api
  23. */
  24. frontmatter: IFrontMatterOptions[];
  25. /**
  26. * Represents `rehype`-based plugins to be configured with a `unified.Processor`
  27. */
  28. rehype: IRehypePlugin[];
  29. /**
  30. * Represents `remark`-based plugins to be configured with a `unified.Processor`
  31. */
  32. remark: IRemarkPlugin[];
  33. }
  34. interface IMDASTToHASTOptions {
  35. /**
  36. * Represents whether the Compiler should drop raw HTML markup from
  37. * the Markdown document
  38. */
  39. allowDangerousHtml: boolean;
  40. }
  41. interface IHASTToHTMLOptions {
  42. /**
  43. * When this property true the node is skipped for attribute collapsing.
  44. */
  45. ignore: boolean;
  46. /**
  47. * When this property true the node is skipped for attribute collapsing.
  48. */
  49. preserveAttrWrapping: boolean;
  50. }
  51. interface IFrontMatterOptions<T = {[key: string]: any}> {
  52. /**
  53. * Represents how the Frontmatter type should be identified as. Usually
  54. * it should be the the shortname of your syntax type, e.g. json, yaml, etc...
  55. */
  56. type: string;
  57. /**
  58. * Represents the character used to construct fences. By providing an object with open
  59. * and close. different characters can be used for opening and closing fences. For example
  60. * * the character '-' will result in '---' being used as the fence.
  61. */
  62. marker: string | {open: string; close: string};
  63. /**
  64. * Represents the string used as the complete fence. By providing an object with open and
  65. * close different values can be used for opening and closing fences. This can be used too
  66. * if fences contain different characters or lengths other than 3
  67. */
  68. fence: string | {open: string; close: string};
  69. /**
  70. * Represents if the Frontmatter can be anywhere in the Markdown document,
  71. * or only at the top of the document
  72. */
  73. anywhere: boolean;
  74. /**
  75. * Represents a callback to parse frontmatter identified string into a
  76. * JSON-serializable Javascript data structure
  77. */
  78. parser: (string: string) => T;
  79. }

Developer

Installation

Open your terminal and install via npm:

  1. npm install git+https://github.com/novacbn/snowpack-plugin-markdown#0.0.1 -D

Install current in-development code:

  1. npm install git+https://github.com/novacbn/snowpack-plugin-markdown -D