remark-growi-plugin.js 962 B

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * @typedef {import('mdast').Root} Root
  3. *
  4. * @typedef {import('mdast-util-directive')} DoNotTouchAsThisImportIncludesDirectivesInTree
  5. */
  6. import { directiveFromMarkdown, directiveToMarkdown } from './mdast-util-growi-plugin/index.js';
  7. import { directive } from './micromark-extension-growi-plugin/index.js';
  8. /**
  9. * Plugin to support GROWI plugin (`$lsx(/path, depth=2)`).
  10. *
  11. * @type {import('unified').Plugin<void[], Root>}
  12. */
  13. export function remarkGrowiPlugin() {
  14. const data = this.data();
  15. add('micromarkExtensions', directive());
  16. add('fromMarkdownExtensions', directiveFromMarkdown);
  17. add('toMarkdownExtensions', directiveToMarkdown);
  18. /**
  19. * @param {string} field
  20. * @param {unknown} value
  21. */
  22. function add(field, value) {
  23. const list = /** @type {unknown[]} */ (
  24. // Other extensions
  25. /* c8 ignore next 2 */
  26. data[field] ? data[field] : (data[field] = [])
  27. );
  28. list.push(value);
  29. }
  30. }