A platform for community discussion. Free, open, simple.
FIX: Use tight list format for GDocs html to markdown
Vinoth Kannan4c99acea1b8a
diff --git a/app/assets/javascripts/discourse/lib/to-markdown.js.es6 b/app/assets/javascripts/discourse/lib/to-markdown.js.es6index 560c0657300..9b08fee72fd 100644--- a/app/assets/javascripts/discourse/lib/to-markdown.js.es6+++ b/app/assets/javascripts/discourse/lib/to-markdown.js.es6@@ -109,6 +109,12 @@ export class Tag {}decorate(text) {+ const parent = this.element.parent;++ if (this.name === "p" && parent && parent.name === "li") { // fix for google docs+ this.gap = "";+ }+return `${this.gap}${this.prefix}${text}${this.suffix}${this.gap}`;}};@@ -400,6 +406,12 @@ export class Tag {return class extends Tag.block(name) {decorate(text) {let smallGap = "";+ const parent = this.element.parent;++ if (parent && parent.name === "ul") {+ this.gap = "";+ this.suffix = "\n";+ }if (this.element.filterParentNames(["li"]).length) {this.gap = "";diff --git a/test/javascripts/lib/to-markdown-test.js.es6 b/test/javascripts/lib/to-markdown-test.js.es6index 0ab96fa43ab..57a437a4a53 100644--- a/test/javascripts/lib/to-markdown-test.js.es6+++ b/test/javascripts/lib/to-markdown-test.js.es6@@ -70,7 +70,7 @@ QUnit.test("converts heading tags", assert => {});QUnit.test("converts ul list tag", assert => {- const html = `+ let html = `<ul><li>Item 1</li><li>@@ -84,7 +84,20 @@ QUnit.test("converts ul list tag", assert => {<li>Item 3</li></ul>`;- const markdown = `* Item 1\n* Item 2\n * Sub Item 1\n * Sub Item 2\n\n * Sub Item 3\n * Sub *Sub* Item 1\n * Sub **Sub** Item 2\n* Item 3`;+ let markdown = `* Item 1\n* Item 2\n * Sub Item 1\n * Sub Item 2\n * Sub Item 3\n * Sub *Sub* Item 1\n * Sub **Sub** Item 2\n* Item 3`;+ assert.equal(toMarkdown(html), markdown);++ html = `+<ul>+ <li><p><span>Bullets at level 1</span></p></li>+ <li><p><span>Bullets at level 1</span></p></li> <ul> <li><p><span>Bullets at level 2</span></p></li> <li><p><span>Bullets at level 2</span></p></li> <ul> <li><p><span>Bullets at level 3</span></p></li> </ul> <li><p><span>Bullets at level 2</span></p></li> </ul> <li><p><span>Bullets at level 1</span></p></li></ul> `;+ markdown = `* Bullets at level 1+* Bullets at level 1+ * Bullets at level 2+ * Bullets at level 2+ * Bullets at level 3+ * Bullets at level 2+* Bullets at level 1`;assert.equal(toMarkdown(html), markdown);});