FIX: Keep emojis and remove clicks count

This commit is contained in:
Vinoth Kannan 2018-08-29 07:26:25 +00:00
parent 93201d8dbe
commit fb35b0b3c3
3 changed files with 38 additions and 8 deletions

View File

@ -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() { static link() {
return class extends Tag { return class extends Tag {
constructor() { constructor() {
@ -200,6 +218,11 @@ export class Tag {
const attr = e.attributes; const attr = e.attributes;
const pAttr = (e.parent && e.parent.attributes) || {}; const pAttr = (e.parent && e.parent.attributes) || {};
const src = attr.src || pAttr.src; const src = attr.src || pAttr.src;
const cssClass = attr.class || pAttr.class;
if (cssClass === "emoji") {
return attr.title || pAttr.title;
}
if (src) { if (src) {
let alt = attr.alt || pAttr.alt || ""; let alt = attr.alt || pAttr.alt || "";
@ -443,7 +466,8 @@ function tags() {
Tag.table(), Tag.table(),
Tag.tr(), Tag.tr(),
Tag.ol(), Tag.ol(),
Tag.list("ul") Tag.list("ul"),
Tag.span()
]; ];
} }

View File

@ -140,13 +140,6 @@ export function selectedText() {
$div.append(range.cloneContents()); $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()); return toMarkdown($div.html());
} }

View File

@ -314,3 +314,16 @@ QUnit.test("keeps mention/hash class", assert => {
assert.equal(toMarkdown(html), markdown); 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);
});