gfm-growi.mode.js 737 B

12345678910111213141516171819
  1. // https://discuss.codemirror.net/t/cm-header-margin-padding-height/75/5
  2. window.CodeMirror.defineMode('gfm-growi', (cmConfig, modeCfg) => {
  3. // based on Markdown (GitHub-flavour) mode
  4. // https://codemirror.net/doc/manual.html#option_mode
  5. // https://codemirror.net/mode/index.html
  6. modeCfg.name = 'gfm';
  7. modeCfg.highlightFormatting = true;
  8. const mode = window.CodeMirror.getMode(cmConfig, modeCfg);
  9. const origToken = mode.token;
  10. mode.token = function(stream, state) {
  11. let classes = origToken(stream, state) || '';
  12. // https://regex101.com/r/Fep0w2/1
  13. classes = classes.replace(/(^| )header(\S*)/g, '$1header$2 line-grw-cm-header-line');
  14. return /^\s*$/.test(classes) ? null : classes;
  15. };
  16. return mode;
  17. });