index.ts 1003 B

1234567891011121314151617181920212223242526272829303132
  1. import { markdown as markdownLanguage } from '@codemirror/lang-markdown'
  2. import { shortcuts } from './shortcuts'
  3. import { languages } from '../index'
  4. import { Strikethrough, Table } from '@lezer/markdown'
  5. import { Math } from './math'
  6. import {
  7. HighlightStyle,
  8. LanguageSupport,
  9. syntaxHighlighting,
  10. } from '@codemirror/language'
  11. import { tags } from '@lezer/highlight'
  12. export const markdown = () => {
  13. const { language, support } = markdownLanguage({
  14. codeLanguages: languages,
  15. extensions: [Strikethrough, Table, Math],
  16. })
  17. return new LanguageSupport(language, [
  18. support,
  19. shortcuts(),
  20. syntaxHighlighting(markdownHighlightStyle),
  21. ])
  22. }
  23. const markdownHighlightStyle = HighlightStyle.define([
  24. { tag: tags.link, textDecoration: 'underline' },
  25. { tag: tags.heading, textDecoration: 'underline', fontWeight: 'bold' },
  26. { tag: tags.emphasis, fontStyle: 'italic' },
  27. { tag: tags.strong, fontWeight: 'bold' },
  28. { tag: tags.strikethrough, textDecoration: 'line-through' },
  29. ])