Rocketsoup пре 1 година
родитељ
комит
7a8cdaaecc
3 измењених фајлова са 32 додато и 20 уклоњено
  1. 16
    5
      js/markdown.js
  2. 1
    1
      js/markdown.min.js
  3. 15
    14
      markdownjs.html

+ 16
- 5
js/markdown.js Прегледај датотеку

@@ -3312,7 +3312,18 @@ class MDNode {
3312 3312
 	 * @returns {string} concatenated HTML
3313 3313
 	 */
3314 3314
 	_childHTML(state) {
3315
-		return this.children.map((child) => child.toHTML(state)).join('');
3315
+		return MDNode.toHTML(this.children, state);
3316
+	}
3317
+
3318
+	/**
3319
+	 * Protected helper that renders and concatenates the plaintext of all
3320
+	 * children of this node.
3321
+	 *
3322
+	 * @param {MDState} state
3323
+	 * @returns {string} concatenated plaintext
3324
+	 */
3325
+	_childPlaintext(state) {
3326
+		return MDNode.toPlaintext(this.children, state);
3316 3327
 	}
3317 3328
 
3318 3329
 	/**
@@ -3747,7 +3758,7 @@ class MDFootnoteListNode extends MDBlockNode {
3747 3758
 		for (const symbol of symbolOrder) {
3748 3759
 			let content = footnotes[symbol];
3749 3760
 			if (!content) continue;
3750
-			text += `${symbol}. ${content.toPlaintext(state)}\n`;
3761
+			text += `${symbol}. ${this._childPlaintext(state)}\n`;
3751 3762
 		}
3752 3763
 		return text.trim();
3753 3764
 	}
@@ -4094,7 +4105,7 @@ class MDHTMLTagNode extends MDInlineNode {
4094 4105
  */
4095 4106
 class Markdown {
4096 4107
 	/**
4097
-	 * Set of standard readers.
4108
+	 * Set of standard readers to handle common syntax.
4098 4109
 	 * @type {MDReader[]}
4099 4110
 	 */
4100 4111
 	static standardReaders = [
@@ -4117,7 +4128,7 @@ class Markdown {
4117 4128
 	];
4118 4129
 
4119 4130
 	/**
4120
-	 * All supported readers.
4131
+	 * All supported readers except `MDLineBreakReader`.
4121 4132
 	 * @type {MDReader[]}
4122 4133
 	 */
4123 4134
 	static allReaders = [
@@ -4218,7 +4229,7 @@ class Markdown {
4218 4229
 
4219 4230
 	/**
4220 4231
 	 * Keeps removing first and last lines of markdown to locate the source of
4221
-	 * an exception.
4232
+	 * an exception and prints the minimal snippet to `console.error`.
4222 4233
 	 *
4223 4234
 	 * @param {string[]} lines
4224 4235
 	 * @param {string} elementIdPrefix

+ 1
- 1
js/markdown.min.js
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 15
- 14
markdownjs.html Прегледај датотеку

@@ -257,20 +257,6 @@
257 257
 		<script src="js/markdown.js"></script>
258 258
 		<script src="js/spreadsheet.js"></script>
259 259
 		<script>
260
-			var activeReaders = [];
261
-			var parser = null;
262
-			function onDocumentLoad() {
263
-				activeReaders = Markdown.standardReaders.slice();
264
-				parser = new Markdown(activeReaders);
265
-				document.getElementById('markdowninput').addEventListener('input', onMarkdownChange);
266
-				populateReaderCheckboxes();
267
-				setTimeout(onMarkdownChange, 0);
268
-			}
269
-			function onMarkdownChange() {
270
-				let markdown = document.getElementById('markdowninput').value;
271
-				let html = parser.toHTML(markdown, 'foo-');
272
-				document.getElementById('preview').innerHTML = html;
273
-			}
274 260
 			var blockReaderClasses = {
275 261
 				'Heading (underline)': MDUnderlinedHeadingReader,
276 262
 				'Heading (hash)': MDHashHeadingReader,
@@ -305,6 +291,21 @@
305 291
 				'Modifiers': MDModifierReader,
306 292
 				'Line breaks': MDLineBreakReader,
307 293
 			};
294
+			var activeReaders = [];
295
+			var parser = null;
296
+			function onDocumentLoad() {
297
+				activeReaders = [ ...Markdown.allReaders, new MDSpreadsheetReader() ];
298
+				parser = new Markdown(activeReaders);
299
+				document.getElementById('markdowninput').addEventListener('input', onMarkdownChange);
300
+				populateReaderCheckboxes();
301
+				setTimeout(onMarkdownChange, 0);
302
+			}
303
+			function onMarkdownChange() {
304
+				const textarea = document.getElementById('markdowninput');
305
+				let markdown = textarea.value;
306
+				let html = parser.toHTML(markdown, 'foo-');
307
+				document.getElementById('preview').innerHTML = html;
308
+			}
308 309
 			function populateReaderCheckboxes() {
309 310
 				const container = document.getElementById('readercontainer');
310 311
 				var header = document.createElement('div');

Loading…
Откажи
Сачувај