Skip to content

A platform for community discussion. Free, open, simple.

blockquote tag support for HTML pasting in composer

Vinoth Kannan6272f35eeca9
diff --git a/app/assets/javascripts/discourse/lib/to-markdown.js.es6 b/app/assets/javascripts/discourse/lib/to-markdown.js.es6
index 841b0c9103a..4fb5b92b126 100644
--- a/app/assets/javascripts/discourse/lib/to-markdown.js.es6
+++ b/app/assets/javascripts/discourse/lib/to-markdown.js.es6
@@ -29,7 +29,7 @@ class Tag {
}
static blocks() {
- return ["address", "article", "aside", "blockquote", "dd", "div", "dl", "dt", "fieldset",
+ return ["address", "article", "aside", "dd", "div", "dl", "dt", "fieldset",
"figcaption", "figure", "footer", "form", "header", "hgroup", "hr", "main", "nav",
"ol", "p", "pre", "section", "table", "ul"];
}
@@ -47,7 +47,7 @@ class Tag {
}
static trimmable() {
- return [...Tag.blocks(), ...Tag.headings(), ...Tag.slices(), "li", "td", "th", "br", "hr"];
+ return [...Tag.blocks(), ...Tag.headings(), ...Tag.slices(), "li", "td", "th", "br", "hr", "blockquote"];
}
static block(name, prefix, suffix) {
@@ -201,6 +201,19 @@ class Tag {
};
}
+ static blockquote() {
+ return class extends Tag {
+ constructor() {
+ super("blockquote", "\n> ", "\n");
+ }
+
+ decorate(text) {
+ text = text.trim().replace(/\n{2,}>/g, "\n>").replace(/\n/g, "\n> ");
+ return super.decorate(text);
+ }
+ };
+ }
+
}
const tags = [
@@ -211,10 +224,10 @@ const tags = [
Tag.cell("td"), Tag.cell("th"),
Tag.replace("br", "\n"), Tag.replace("hr", "\n---\n"), Tag.replace("head", ""),
Tag.keep("ins"), Tag.keep("del"), Tag.keep("small"), Tag.keep("big"),
- Tag.li(), Tag.link(), Tag.image(), Tag.code(),
+ Tag.li(), Tag.link(), Tag.image(), Tag.code(), Tag.blockquote(),
- // TO-DO CREATE: code, tbody, blockquote
- // UPDATE: ol, pre, thead, th, td
+ // TO-DO CREATE: tbody
+ // UPDATE: ol, thead, th, td
];
class Element {
diff --git a/test/javascripts/lib/to-markdown-test.js.es6 b/test/javascripts/lib/to-markdown-test.js.es6
index 9d6111aaa64..9cf2707c511 100644
--- a/test/javascripts/lib/to-markdown-test.js.es6
+++ b/test/javascripts/lib/to-markdown-test.js.es6
@@ -170,3 +170,17 @@ helloWorld();</code> consectetur.`;
assert.equal(toMarkdown(html), output);
});
+
+QUnit.test("converts blockquote tag", assert => {
+ let html = "<blockquote>Lorem ipsum</blockquote>";
+ let output = "> Lorem ipsum";
+ assert.equal(toMarkdown(html), output);
+
+ html = "<blockquote>Lorem ipsum</blockquote><blockquote><p>dolor sit amet</p></blockquote>";
+ output = "> Lorem ipsum\n\n> dolor sit amet";
+ assert.equal(toMarkdown(html), output);
+
+ html = "<blockquote>\nLorem ipsum\n<blockquote><p>dolor <blockquote>sit</blockquote> amet</p></blockquote></blockquote>";
+ output = "> Lorem ipsum\n> > dolor\n> > > sit\n> > amet";
+ assert.equal(toMarkdown(html), output);
+});