FIX: Keep emojis and remove clicks count
This commit is contained in:
parent
93201d8dbe
commit
fb35b0b3c3
|
@ -162,6 +162,24 @@ export class Tag {
|
|||
};
|
||||
}
|
||||
|
||||
static span() {
|
||||
return class extends Tag {
|
||||
constructor() {
|
||||
super("span");
|
||||
}
|
||||
|
||||
decorate(text) {
|
||||
const attr = this.element.attributes;
|
||||
|
||||
if (attr.class === "badge badge-notification clicks") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return super.decorate(text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static link() {
|
||||
return class extends Tag {
|
||||
constructor() {
|
||||
|
@ -200,6 +218,11 @@ export class Tag {
|
|||
const attr = e.attributes;
|
||||
const pAttr = (e.parent && e.parent.attributes) || {};
|
||||
const src = attr.src || pAttr.src;
|
||||
const cssClass = attr.class || pAttr.class;
|
||||
|
||||
if (cssClass === "emoji") {
|
||||
return attr.title || pAttr.title;
|
||||
}
|
||||
|
||||
if (src) {
|
||||
let alt = attr.alt || pAttr.alt || "";
|
||||
|
@ -443,7 +466,8 @@ function tags() {
|
|||
Tag.table(),
|
||||
Tag.tr(),
|
||||
Tag.ol(),
|
||||
Tag.list("ul")
|
||||
Tag.list("ul"),
|
||||
Tag.span()
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -140,13 +140,6 @@ export function selectedText() {
|
|||
$div.append(range.cloneContents());
|
||||
}
|
||||
|
||||
// strip click counters
|
||||
$div.find(".clicks").remove();
|
||||
// replace emojis
|
||||
$div.find("img.emoji").replaceWith(function() {
|
||||
return this.title;
|
||||
});
|
||||
|
||||
return toMarkdown($div.html());
|
||||
}
|
||||
|
||||
|
|
|
@ -314,3 +314,16 @@ QUnit.test("keeps mention/hash class", assert => {
|
|||
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
QUnit.test("keeps emoji and removes click count", assert => {
|
||||
const html = `
|
||||
<p>
|
||||
A <a href="http://example.com">link</a><span class="badge badge-notification clicks" title="1 click">1</span> with click count
|
||||
and <img class="emoji" title=":boom:" src="https://d11a6trkgmumsb.cloudfront.net/images/emoji/twitter/boom.png?v=5" alt=":boom:" /> emoji.
|
||||
</p>
|
||||
`;
|
||||
|
||||
const markdown = `A [link](http://example.com) with click count and :boom: emoji.`;
|
||||
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue