Replace newlines inside table cells so that resulting markdown is valid

This commit is contained in:
Laurent Cozic 2018-05-21 23:42:02 +01:00
parent 0f64fe53cb
commit 7af39b57f0
3 changed files with 5 additions and 1 deletions

View File

@ -6,6 +6,7 @@ This is a fork of the original [turndown-plugin-gfm](https://github.com/domchris
- Always render tables even they don't have a header. - Always render tables even they don't have a header.
- Don't render the border of tables that contain other tables (frequent for websites that do the layout using tables). Only render the inner tables, if any, and if they also don't contain other tables. - Don't render the border of tables that contain other tables (frequent for websites that do the layout using tables). Only render the inner tables, if any, and if they also don't contain other tables.
- Replace newlines (`\n`) with `<br>` inside table cells so that multi-line content is displayed correctly as Markdown.
## Installation ## Installation

3
publish.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
npm version patch
npm publish

View File

@ -99,7 +99,7 @@ function cell (content, node) {
var index = indexOf.call(node.parentNode.childNodes, node) var index = indexOf.call(node.parentNode.childNodes, node)
var prefix = ' ' var prefix = ' '
if (index === 0) prefix = '| ' if (index === 0) prefix = '| '
return prefix + content + ' |' return prefix + content.trim().replace(/[\n\r]/g, "<br>") + ' |'
} }
function nodeContainsTable(node) { function nodeContainsTable(node) {