瀏覽代碼

Fixed the conversion of todo lists to match the default HTML generated by CKEditor.

fredck 5 年之前
父節點
當前提交
9c55502bdd
共有 1 個文件被更改,包括 18 次插入1 次删除
  1. 18 1
      packages/ckeditor5-markdown-gfm/src/html2markdown/html2markdown.js

+ 18 - 1
packages/ckeditor5-markdown-gfm/src/html2markdown/html2markdown.js

@@ -11,8 +11,25 @@ import { gfm } from 'turndown-plugin-gfm';
 // import converters from './lib/to-markdown/converters';
 
 const turndownService = new TurndownService();
-turndownService.use( gfm );
+turndownService.use( [
+	gfm,
+	todoList
+] );
 
 export default function html2markdown( html ) {
 	return turndownService.turndown( html );
 }
+
+// This is a copy of the original from turdown-plugin-gfm, with minor changes.
+function todoList( turndownService ) {
+	turndownService.addRule( 'taskListItems', {
+		filter( node ) {
+			return node.type === 'checkbox' &&
+				// Changes here as CKEditor outputs a deeper structure.
+				( node.parentNode.nodeName === 'LI' || node.parentNode.parentNode.nodeName === 'LI' );
+		},
+		replacement( content, node ) {
+			return ( node.checked ? '[x]' : '[ ]' ) + ' ';
+		}
+	} );
+}