From d32f25425b735f69f4186e3879772e9c306f257b Mon Sep 17 00:00:00 2001 From: Chris LaFreniere <40371649+chlafreniere@users.noreply.github.com> Date: Fri, 3 Sep 2021 10:43:25 -0700 Subject: [PATCH] Use updated markdown renderer from vscode (#16988) --- .../notebook/browser/notebook.contribution.ts | 2 +- .../test/browser/notebookMarkdown.test.ts | 24 +++++++++---------- src/vs/base/common/marked/marked.js | 9 ++++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts index 0295ffa7b9..3fe76d216a 100644 --- a/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -341,7 +341,7 @@ configurationRegistry.registerConfiguration({ }, [useNewMarkdownRendererKey]: { 'type': 'boolean', - default: false, + default: true, 'description': localize('notebook.useNewMarkdownRenderer', "Whether to use the newer version of the markdown renderer for Notebooks. This may result in markdown being rendered differently than previous versions.") } } diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts index 4b72cae899..9f5bf6e55f 100644 --- a/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts +++ b/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts @@ -10,7 +10,7 @@ import { URI } from 'vs/base/common/uri'; import { TestConfigurationService } from 'sql/platform/connection/test/common/testConfigurationService'; suite('NotebookMarkdownRenderer', () => { - let notebookMarkdownRenderer = new NotebookMarkdownRenderer(new TestConfigurationService({ user: { 'notebook': { 'useNewMarkdownRenderer': false } } })); + let notebookMarkdownRenderer = new NotebookMarkdownRenderer(new TestConfigurationService({ user: { 'notebook': { 'useNewMarkdownRenderer': true } } })); test('image rendering conforms to default', () => { const markdown = { value: `` }; const result: HTMLElement = notebookMarkdownRenderer.renderMarkdown(markdown); @@ -107,7 +107,7 @@ suite('NotebookMarkdownRenderer', () => { test('table followed by blank line with space and then header renders correctly (#16245)', function (): void { let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: '
Item 1
Item 2
Sub-item 1
Sub-item 2
Item 1
Item 2
Sub-item 1
Sub-item 2
\n';
+ const expectedValue = '\n\n';
const result = notebookMarkdownRenderer.renderMarkdown({ value: markdown, isTrusted: true }).innerHTML;
assert.strictEqual(result, expectedValue);
});
@@ -140,7 +140,7 @@ suite('NotebookMarkdownRenderer', () => {
suite('Notebook e054f8e1-f014-4c7c-8a55-65bf13b22bb5', function (): void {
test('Cell 0981d264-25f5-489c-901b-74608297f7fc', function (): void {
const markdown = 'Some text **%appdata%\\*****Path\\\\To\\\\Folder\\\\<******FileName**>.ext** into **...\\\\Another\\\\****Path\\\\**\n\n';
- const expectedValue = 'Some text %appdata%***Path\\To\\Folder\\<******FileName**>.ext** into ...\\Another\\**Path\\**
'; + const expectedValue = 'Some text **%appdata%***Path\\To\\Folder\\<******FileName**>.ext into **...\\Another\\***Path\\*
'; const result = notebookMarkdownRenderer.renderMarkdown({ value: markdown, isTrusted: true }).innerHTML; assert.strictEqual(result, expectedValue); }); @@ -149,7 +149,7 @@ suite('NotebookMarkdownRenderer', () => { suite('Notebook ????', function (): void { test('Cell b74f16a2-5b2e-4e58-8c79-9688d6b1f62a', function (): void { const markdown = '# Heading 1\n- Some text\n\n \n\n- ## Heading 2'; - const expectedValue = 'Some text
Some text
Some more text\n';
+ const expectedValue = 'Some text
Some more text\n\n';
const result = notebookMarkdownRenderer.renderMarkdown({ value: markdown, isTrusted: true }).innerHTML;
assert.strictEqual(result, expectedValue);
});
@@ -167,7 +167,7 @@ suite('NotebookMarkdownRenderer', () => {
suite('Notebook 03b95d90-a0fc-43c8-b77b-d506f2002904', function (): void {
test('Cell e557e19c-8afa-40e4-a61d-ab08443562ee', function (): void {
const markdown = '# heading\n##';
- const expectedValue = '##
'; + const expectedValue = 'a. sub-list item\n';
+ const expectedValue = 'List item text
a. sub-list item
List Item
List Item 2
Text on new line
a. Sub List Item\n';
+ const expectedValue = 'Text on new line
a. Sub List Item\n\n';
const result = notebookMarkdownRenderer.renderMarkdown({ value: markdown, isTrusted: true }).innerHTML;
assert.strictEqual(result, expectedValue);
});
test('Cell e6ad1eb3-7409-4199-9592-9d13f1e2d8a0', function (): void {
const markdown = '1. Text \n\nMore text \n\n a. Sub-Text';
- const expectedValue = 'More text
a. Sub-Text\n';
+ const expectedValue = 'More text
a. Sub-Text\n\n';
const result = notebookMarkdownRenderer.renderMarkdown({ value: markdown, isTrusted: true }).innerHTML;
assert.strictEqual(result, expectedValue);
});
diff --git a/src/vs/base/common/marked/marked.js b/src/vs/base/common/marked/marked.js
index 163c49df39..f99d603f68 100644
--- a/src/vs/base/common/marked/marked.js
+++ b/src/vs/base/common/marked/marked.js
@@ -1160,9 +1160,12 @@
+ '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
+ '|\\n*|$)' // (4)
+ '|\\n*|$)' // (5)
- + '|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:\\n{2,}|$)' // (6)
- + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) open tag
- + '|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)' // (7) closing tag
+ // {{SQL CARBON EDIT}} Porting marked.js fix for non-empty lines followed by elements to not render properly
+ // PR where this fix ocurred here: https://github.com/markedjs/marked/pull/2052/files?file-filters%5B%5D=.js, shipped in markedjs 2.0.4
+ + '|?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (6)
+ + '|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) open tag
+ + '|(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)' // (7) closing tag
+ // {{SQL CARBON EDIT}} end fixes
+ ')',
def: /^ {0,3}\[(label)\]: *\n? *([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,
nptable: noopTest$1,