Kaynağa Gözat

Plaintext fix

main
Rocketsoup 1 yıl önce
ebeveyn
işleme
7a8cdaaecc
3 değiştirilmiş dosya ile 32 ekleme ve 20 silme
  1. 16
    5
      js/markdown.js
  2. 1
    1
      js/markdown.min.js
  3. 15
    14
      markdownjs.html

+ 16
- 5
js/markdown.js Dosyayı Görüntüle

3312
 	 * @returns {string} concatenated HTML
3312
 	 * @returns {string} concatenated HTML
3313
 	 */
3313
 	 */
3314
 	_childHTML(state) {
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
 		for (const symbol of symbolOrder) {
3758
 		for (const symbol of symbolOrder) {
3748
 			let content = footnotes[symbol];
3759
 			let content = footnotes[symbol];
3749
 			if (!content) continue;
3760
 			if (!content) continue;
3750
-			text += `${symbol}. ${content.toPlaintext(state)}\n`;
3761
+			text += `${symbol}. ${this._childPlaintext(state)}\n`;
3751
 		}
3762
 		}
3752
 		return text.trim();
3763
 		return text.trim();
3753
 	}
3764
 	}
4094
  */
4105
  */
4095
 class Markdown {
4106
 class Markdown {
4096
 	/**
4107
 	/**
4097
-	 * Set of standard readers.
4108
+	 * Set of standard readers to handle common syntax.
4098
 	 * @type {MDReader[]}
4109
 	 * @type {MDReader[]}
4099
 	 */
4110
 	 */
4100
 	static standardReaders = [
4111
 	static standardReaders = [
4117
 	];
4128
 	];
4118
 
4129
 
4119
 	/**
4130
 	/**
4120
-	 * All supported readers.
4131
+	 * All supported readers except `MDLineBreakReader`.
4121
 	 * @type {MDReader[]}
4132
 	 * @type {MDReader[]}
4122
 	 */
4133
 	 */
4123
 	static allReaders = [
4134
 	static allReaders = [
4218
 
4229
 
4219
 	/**
4230
 	/**
4220
 	 * Keeps removing first and last lines of markdown to locate the source of
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
 	 * @param {string[]} lines
4234
 	 * @param {string[]} lines
4224
 	 * @param {string} elementIdPrefix
4235
 	 * @param {string} elementIdPrefix

+ 1
- 1
js/markdown.min.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 15
- 14
markdownjs.html Dosyayı Görüntüle

257
 		<script src="js/markdown.js"></script>
257
 		<script src="js/markdown.js"></script>
258
 		<script src="js/spreadsheet.js"></script>
258
 		<script src="js/spreadsheet.js"></script>
259
 		<script>
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
 			var blockReaderClasses = {
260
 			var blockReaderClasses = {
275
 				'Heading (underline)': MDUnderlinedHeadingReader,
261
 				'Heading (underline)': MDUnderlinedHeadingReader,
276
 				'Heading (hash)': MDHashHeadingReader,
262
 				'Heading (hash)': MDHashHeadingReader,
305
 				'Modifiers': MDModifierReader,
291
 				'Modifiers': MDModifierReader,
306
 				'Line breaks': MDLineBreakReader,
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
 			function populateReaderCheckboxes() {
309
 			function populateReaderCheckboxes() {
309
 				const container = document.getElementById('readercontainer');
310
 				const container = document.getElementById('readercontainer');
310
 				var header = document.createElement('div');
311
 				var header = document.createElement('div');

Loading…
İptal
Kaydet