index.ts 953 B

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