mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
PERF: Better handling of headings in HTML inline pasting
This commit is contained in:
parent
8175740e87
commit
4f2f42d710
@ -640,11 +640,11 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
_pasteMarkdown(text) {
|
||||
const lineVal = this._getSelected(null, {lineVal: true}).lineVal;
|
||||
const { pre, lineVal } = this._getSelected(null, {lineVal: true});
|
||||
|
||||
if(lineVal) { // inline pasting
|
||||
if(lineVal && pre.match(/[^\n]$/)) { // inline pasting
|
||||
text = text.replace(/^#+/, "").trim();
|
||||
text = (lineVal.search(/\s$/) === lineVal.length - 1) ? text : ` ${text}`;
|
||||
text = pre.match(/\S$/) ? ` ${text}` : text;
|
||||
}
|
||||
|
||||
this.appEvents.trigger('composer:insert-text', text);
|
||||
|
@ -109,6 +109,7 @@ class Tag {
|
||||
const attr = this.element.attributes;
|
||||
|
||||
if (attr && attr.href && text !== attr.href) {
|
||||
text = text.replace(/\n{2,}/g, "\n");
|
||||
return "[" + text + "](" + attr.href + ")";
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,12 @@ QUnit.test("converts inline nested styles", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("converts a link", assert => {
|
||||
const html = `<a href="https://discourse.org">Discourse</a>`;
|
||||
const markdown = `[Discourse](https://discourse.org)`;
|
||||
let html = `<a href="https://discourse.org">Discourse</a>`;
|
||||
let markdown = `[Discourse](https://discourse.org)`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
|
||||
html = `<a href="https://discourse.org">Disc\n\n\nour\n\nse</a>`;
|
||||
markdown = `[Disc\nour\nse](https://discourse.org)`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user