浏览代码

Importing 'marked' as an npm module and separate it into it's own code.

fredck 5 年之前
父节点
当前提交
ecd001f697

+ 1 - 0
packages/ckeditor5-markdown-gfm/package.json

@@ -11,6 +11,7 @@
   ],
   "dependencies": {
     "@ckeditor/ckeditor5-engine": "^21.0.0",
+    "marked": "^0.7.0",
     "turndown": "^5.0.3",
     "turndown-plugin-gfm": "^1.0.2"
   },

+ 2 - 15
packages/ckeditor5-markdown-gfm/src/gfmdataprocessor.js

@@ -7,13 +7,9 @@
  * @module markdown-gfm/gfmdataprocessor
  */
 
-import marked from './lib/marked/marked';
 import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
-import GFMRenderer from './lib/marked/renderer';
-
-// import toMarkdown from './lib/to-markdown/to-markdown';
-// import converters from './lib/to-markdown/converters';
 
+import markdown2html from './markdown2html/markdown2html';
 import html2markdown from './html2markdown/html2markdown';
 
 /**
@@ -46,14 +42,7 @@ export default class GFMDataProcessor {
 	 * @returns {module:engine/view/documentfragment~DocumentFragment} The converted view element.
 	 */
 	toView( data ) {
-		const html = marked.parse( data, {
-			gfm: true,
-			breaks: true,
-			tables: true,
-			xhtml: true,
-			renderer: new GFMRenderer()
-		} );
-
+		const html = markdown2html( data );
 		return this._htmlDP.toView( html );
 	}
 
@@ -66,8 +55,6 @@ export default class GFMDataProcessor {
 	 */
 	toData( viewFragment ) {
 		const html = this._htmlDP.toData( viewFragment );
-
 		return html2markdown( html );
-		// return toMarkdown( html, { gfm: true, converters } );
 	}
 }

+ 4 - 0
packages/ckeditor5-markdown-gfm/src/html2markdown/html2markdown.js

@@ -6,6 +6,10 @@
 import TurndownService from 'turndown';
 import { gfm } from 'turndown-plugin-gfm';
 
+// TODO: Implement converters (now "rules") (if necessary).
+// TODO: Delete the legacy lib/to-markdown directory.
+// import converters from './lib/to-markdown/converters';
+
 const turndownService = new TurndownService();
 turndownService.use( gfm );
 

+ 19 - 0
packages/ckeditor5-markdown-gfm/src/markdown2html/markdown2html.js

@@ -0,0 +1,19 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import marked from 'marked';
+
+// TODO: Implement the Renderer (if necessary).
+// TODO: Delete the legacy lib/marked directory..
+// import GFMRenderer from './lib/marked/renderer';
+
+export default function markdown2html( markdown ) {
+	return marked.parse( markdown, {
+		gfm: true,
+		breaks: true,
+		tables: true,
+		xhtml: true
+	} );
+}