debian-mirror-gitlab/app/assets/javascripts/behaviors/markdown/nodes/emoji.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
920 B
JavaScript
Raw Normal View History

2019-03-02 22:35:43 +05:30
// Transforms generated HTML back to GFM for Banzai::Filter::EmojiFilter
2022-05-07 20:08:51 +05:30
export default () => ({
name: 'emoji',
schema: {
inline: true,
group: 'inline',
attrs: {
name: {},
title: {},
moji: {},
},
parseDOM: [
{
tag: 'gl-emoji',
getAttrs: (el) => ({
name: el.dataset.name,
title: el.getAttribute('title'),
moji: el.textContent,
}),
2019-03-02 22:35:43 +05:30
},
2022-05-07 20:08:51 +05:30
{
tag: 'img.emoji',
getAttrs: (el) => {
const name = el.getAttribute('title').replace(/^:|:$/g, '');
2021-11-18 22:05:49 +05:30
2022-05-07 20:08:51 +05:30
return {
name,
title: name,
moji: name,
};
2021-11-18 22:05:49 +05:30
},
2022-05-07 20:08:51 +05:30
},
],
toDOM: (node) => [
'gl-emoji',
{ 'data-name': node.attrs.name, title: node.attrs.title },
node.attrs.moji,
],
},
2019-03-02 22:35:43 +05:30
toMarkdown(state, node) {
state.write(`:${node.attrs.name}:`);
2022-05-07 20:08:51 +05:30
},
});