From 36179a839460e9dd9c5715b32e37168492a1aedf Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 21 May 2018 23:55:53 +0100 Subject: [PATCH] Make table cells at least 3 char long --- README.md | 1 + src/tables.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 077dceed1..8d74b8c36 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ This is a fork of the original [turndown-plugin-gfm](https://github.com/domchris - Always render tables even if 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. - Replace newlines (`\n`) with `
` inside table cells so that multi-line content is displayed correctly as Markdown. +- Table cells are at least three characters long (padded with spaces) so that they render correctly in GFM-compliant renderers. ## Installation diff --git a/src/tables.js b/src/tables.js index 8b782dc72..0c2ca2306 100644 --- a/src/tables.js +++ b/src/tables.js @@ -99,7 +99,9 @@ function cell (content, node) { var index = indexOf.call(node.parentNode.childNodes, node) var prefix = ' ' if (index === 0) prefix = '| ' - return prefix + content.trim().replace(/[\n\r]/g, "
") + ' |' + let filteredContent = content.trim().replace(/[\n\r]/g, "
"); + while (filteredContent.length < 3) filteredContent += ' '; + return prefix + filteredContent + ' |' } function nodeContainsTable(node) {