Merge pull request #6333 from vinothkannans/rich-text-pasting
FIX: Use tight list format for GDocs html to markdown
This commit is contained in:
commit
092fb0c170
|
@ -109,6 +109,12 @@ export class Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
decorate(text) {
|
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}`;
|
return `${this.gap}${this.prefix}${text}${this.suffix}${this.gap}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -400,6 +406,12 @@ export class Tag {
|
||||||
return class extends Tag.block(name) {
|
return class extends Tag.block(name) {
|
||||||
decorate(text) {
|
decorate(text) {
|
||||||
let smallGap = "";
|
let smallGap = "";
|
||||||
|
const parent = this.element.parent;
|
||||||
|
|
||||||
|
if (parent && parent.name === "ul") {
|
||||||
|
this.gap = "";
|
||||||
|
this.suffix = "\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (this.element.filterParentNames(["li"]).length) {
|
if (this.element.filterParentNames(["li"]).length) {
|
||||||
this.gap = "";
|
this.gap = "";
|
||||||
|
|
|
@ -70,7 +70,7 @@ QUnit.test("converts heading tags", assert => {
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("converts ul list tag", assert => {
|
QUnit.test("converts ul list tag", assert => {
|
||||||
const html = `
|
let html = `
|
||||||
<ul>
|
<ul>
|
||||||
<li>Item 1</li>
|
<li>Item 1</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -84,7 +84,20 @@ QUnit.test("converts ul list tag", assert => {
|
||||||
<li>Item 3</li>
|
<li>Item 3</li>
|
||||||
</ul>
|
</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);
|
assert.equal(toMarkdown(html), markdown);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue