Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #31 from ckeditor/i/6091
Browse files Browse the repository at this point in the history
Other: Adjusted the data processor implementation to changes in `ckeditor5-engine`. See ckeditor/ckeditor5#6091.

MAJOR BREAKING CHANGES: The `GFMDataProcessor()` requires the view document instance as its first parameter.
  • Loading branch information
Reinmar committed Mar 3, 2020
2 parents 416d184 + 32ce36f commit ce2cc01
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/_snippets/features/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud
import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataprocessor';

function Markdown( editor ) {
editor.data.processor = new GFMDataProcessor();
editor.data.processor = new GFMDataProcessor( editor.editing.view.document );
}

ClassicEditor
Expand Down
2 changes: 1 addition & 1 deletion docs/features/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import GFMDataProcessor from '@ckeditor/ckeditor5-markdown-gfm/src/gfmdataproces

// Simple plugin which loads the data processor.
function Markdown( editor ) {
editor.data.processor = new GFMDataProcessor();
editor.data.processor = new GFMDataProcessor( editor.editing.view.document );
}

ClassicEditor
Expand Down
10 changes: 7 additions & 3 deletions src/gfmdataprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ import converters from './lib/to-markdown/converters';
* @implements module:engine/dataprocessor/dataprocessor~DataProcessor
*/
export default class GFMDataProcessor {
constructor() {
/**
* Creates a new instance of the Markdown data processor class.
*
* @param {module:engine/view/document~Document} document
*/
constructor( document ) {
/**
* HTML data processor used to process HTML produced by the Markdown-to-HTML converter and the other way.
*
* @private
* @member {module:engine/dataprocessor/htmldataprocessor~HtmlDataProcessor}
*/
this._htmlDP = new HtmlDataProcessor();
this._htmlDP = new HtmlDataProcessor( document );
}

/**
Expand Down Expand Up @@ -62,4 +67,3 @@ export default class GFMDataProcessor {
return toMarkdown( html, { gfm: true, converters } );
}
}

5 changes: 4 additions & 1 deletion tests/_utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import MarkdownDataProcessor from '../../src/gfmdataprocessor';
import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view.js';
import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';

/**
* Tests MarkdownDataProcessor.
Expand All @@ -15,7 +17,8 @@ import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view.js';
* markdown string (which will be used if this parameter is not provided).
*/
export function testDataProcessor( markdown, viewString, normalizedMarkdown ) {
const dataProcessor = new MarkdownDataProcessor();
const viewDocument = new ViewDocument( new StylesProcessor() );
const dataProcessor = new MarkdownDataProcessor( viewDocument );
const viewFragment = dataProcessor.toView( markdown );

// Check if view has correct data.
Expand Down
5 changes: 4 additions & 1 deletion tests/gfmdataprocessor/escaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import MarkdownDataProcessor from '../../src/gfmdataprocessor';
import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';

const testCases = {
'backslash': { test: '\\\\', result: '\\' },
Expand All @@ -27,7 +29,8 @@ describe( 'GFMDataProcessor', () => {
let dataProcessor;

beforeEach( () => {
dataProcessor = new MarkdownDataProcessor();
const viewDocument = new ViewDocument( new StylesProcessor() );
dataProcessor = new MarkdownDataProcessor( viewDocument );
} );

describe( 'escaping', () => {
Expand Down

0 comments on commit ce2cc01

Please sign in to comment.