Преглед изворни кода

Match code style to the rest of the modules.

Maciej Gołaszewski пре 5 година
родитељ
комит
36c0f9c4de

+ 34 - 31
packages/ckeditor5-markdown-gfm/src/html2markdown/html2markdown.js

@@ -10,48 +10,51 @@ import TurndownService from 'turndown';
 import { gfm } from 'turndown-plugin-gfm';
 
 // Overrides the escape() method, enlarging it.
-{
-	const originalEscape = TurndownService.prototype.escape;
-	TurndownService.prototype.escape = function( string ) {
-		// Urls should not be escaped. Our strategy is using a regex to find them and escape everything
-		// which is out of the matches parts.
 
-		// eslint-disable-next-line max-len
-		const regex = /\b(?:https?:\/\/|www\.)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()[\]{};:'".,<>?«»“”‘’])/g;
+const originalEscape = TurndownService.prototype.escape;
 
-		let escaped = '';
-		let lastIndex = 0;
-		let m;
-		do {
-			m = regex.exec( string );
+function escape( string ) {
+	string = originalEscape( string );
 
-			// The substring should to to the matched index or, if nothing found, the end of the string.
-			const index = m ? m.index : string.length;
+	// Escape "<".
+	string = string.replace( /</g, '\\<' );
 
-			// Append the substring between the last match and the current one (if anything).
-			if ( index > lastIndex ) {
-				escaped += escape( string.substring( lastIndex, index ) );
-			}
+	return string;
+}
 
-			// Append the match itself now, if anything.
-			m && ( escaped += m[ 0 ] );
+// eslint-disable-next-line max-len
+const regex = /\b(?:https?:\/\/|www\.)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()[\]{};:'".,<>?«»“”‘’])/g;
 
-			lastIndex = regex.lastIndex;
-		}
-		while ( m );
+TurndownService.prototype.escape = function( string ) {
+	// Urls should not be escaped. Our strategy is using a regex to find them and escape everything
+	// which is out of the matches parts.
 
-		return escaped;
+	let escaped = '';
+	let lastIndex = 0;
+	let m;
 
-		function escape( string ) {
-			string = originalEscape( string );
+	do {
+		m = regex.exec( string );
 
-			// Escape "<".
-			string = string.replace( /</g, '\\<' );
+		// The substring should to the matched index or, if nothing found, the end of the string.
+		const index = m ? m.index : string.length;
 
-			return string;
+		// Append the substring between the last match and the current one (if anything).
+		if ( index > lastIndex ) {
+			escaped += escape( string.substring( lastIndex, index ) );
 		}
-	};
-}
+
+		// Append the match itself now, if anything.
+		if ( m ) {
+			escaped += m[ 0 ];
+		}
+
+		lastIndex = regex.lastIndex;
+	}
+	while ( m );
+
+	return escaped;
+};
 
 const turndownService = new TurndownService( {
 	codeBlockStyle: 'fenced',

+ 3 - 1
packages/ckeditor5-markdown-gfm/tests/_utils/utils.js

@@ -22,8 +22,10 @@ export function testDataProcessor( markdown, viewString, normalizedMarkdown, opt
 	const viewDocument = new ViewDocument( new StylesProcessor() );
 
 	const dataProcessor = new MarkdownDataProcessor( viewDocument );
-	options && options.setup && options.setup( dataProcessor );
 
+	if ( options && options.setup ) {
+		options.setup( dataProcessor );
+	}
 	const viewFragment = dataProcessor.toView( markdown );
 
 	const html = cleanHtml( stringify( viewFragment ) );