converters.js 737 B

1234567891011121314151617181920212223242526
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. // Exports an array with custom converters used by to-markdown library.
  6. export default [
  7. // Converting code blocks with class name matching output from marked library.
  8. {
  9. filter: (node) => {
  10. const regexp = /lang-(.+)/;
  11. return node.nodeName === 'PRE' &&
  12. node.firstChild &&
  13. node.firstChild.nodeName === 'CODE' &&
  14. regexp.test( node.firstChild.className );
  15. },
  16. replacement: ( content, node ) => {
  17. const regexp = /lang-(.+)/;
  18. const lang = regexp.exec( node.firstChild.className )[ 1 ];
  19. return '\n\n``` ' + lang + '\n' + node.firstChild.textContent + '\n```\n\n';
  20. }
  21. },
  22. ];