瀏覽代碼

Added simple manual test for data processor.

Szymon Kupś 9 年之前
父節點
當前提交
27110f5758

+ 8 - 0
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/manual/gfmdataprocessor.html

@@ -0,0 +1,8 @@
+<h2>GitHub Flavored Markdown</h2>
+<textarea id="markdown" placeholder="Enter markdown..." style="width: 50%; height: 100px"></textarea>
+<br/>
+<button id="button_to_view">Convert to view</button>
+<h2>View</h2>
+<textarea  id="view" placeholder="Enter view string..." style="width: 50%; height: 100px"></textarea>
+<br/>
+<button id="button_to_md">Convert to markdown</button>

+ 31 - 0
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/manual/gfmdataprocessor.js

@@ -0,0 +1,31 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document */
+
+import MarkdownDataProcessor from '/ckeditor5/markdown-gfm/gfmdataprocessor.js';
+import { stringify, parse } from '/ckeditor5/engine/dev-utils/view.js';
+
+const markdownTextArea = document.getElementById( 'markdown' );
+const viewTextArea = document.getElementById( 'view' );
+const dataProcessor = new MarkdownDataProcessor();
+
+document.getElementById( 'button_to_view' ).addEventListener( 'click', convertToView );
+document.getElementById( 'button_to_md' ).addEventListener( 'click', convertToMarkdown );
+
+markdownTextArea.value = '### Header\n\nFoo bar baz biz.';
+convertToView();
+
+function convertToView() {
+	const markdown = markdownTextArea.value;
+
+	viewTextArea.value =  stringify( dataProcessor.toView( markdown ) );
+}
+
+function convertToMarkdown() {
+	const viewText = viewTextArea.value;
+
+	markdownTextArea.value = dataProcessor.toData( parse( viewText ) );
+}

+ 7 - 0
packages/ckeditor5-markdown-gfm/tests/gfmdataprocessor/manual/gfmdataprocessor.md

@@ -0,0 +1,7 @@
+@bender-ui: collapsed
+
+#### GitHub Flavored Markdown DataProcessor
+
+- Test conversion from markdown to view by typing markdown inside first textarea and pressing `Convert to view` button.
+- Test conversion from view by typing view string inside second textarea and pressing `Convert to markdown` button.
+View string should be compatible with view's `parse` method from `ckeditor5-engine` package.