Notebooks: Fix Table Generation into Pure Markdown When No thead Exists (#15423)

* works without alignment

* Alignment working

* Add comment

* Remove outdated comment
This commit is contained in:
Chris LaFreniere
2021-05-12 16:28:23 -07:00
committed by GitHub
parent 89db1266d2
commit 624c07947c
3 changed files with 72 additions and 23 deletions

View File

@@ -266,6 +266,15 @@ export class HTMLMarkdownConverter {
return delimiter + leadingSpace + content + trailingSpace + delimiter;
}
});
this.turndownService.addRule('p', {
filter: 'p',
replacement: function (content, node) {
// If inside of a table cell, extra newlines would break table rendering
return isInsideTable(node) ? content : '\n\n' + content + '\n\n';
}
});
this.turndownService.escape = escapeMarkdown;
}
}
@@ -281,10 +290,16 @@ function blankReplacement(content, node) {
// When outdenting a nested list, an empty list will still remain. Need to handle this case.
if (node.nodeName === 'UL' || node.nodeName === 'OL') {
return '\n';
} else if (isInsideTable(node)) {
return ' ';
}
return node.isBlock ? '\n\n' : '';
}
function isInsideTable(node): boolean {
return node.parentNode?.nodeName === 'TH' || node.parentNode?.nodeName === 'TD';
}
export function findPathRelativeToContent(notebookFolder: string, contentPath: URI | undefined): string {
if (notebookFolder) {
if (contentPath?.scheme === 'file') {