import { performEmojiUnescape } from 'pretty-text/emoji'; const rule = { tag: 'quote', before(state, tagInfo) { const attrs = tagInfo.attrs; let options = state.md.options.discourse; let quoteInfo = attrs['_default']; let username, postNumber, topicId, avatarImg, primaryGroupName, full, displayName; if (quoteInfo) { let split = quoteInfo.split(/\,\s*/); username = split[0]; let i; for(i=1;i 0) { href += "/" + postNumber; } let title = topicInfo.title; if (options.enableEmoji) { title = performEmojiUnescape(topicInfo.title, { getURL: options.getURL, emojiSet: options.emojiSet }); } token = state.push('link_open', 'a', 1); token.attrs = [[ 'href', href ]]; token.block = false; token = state.push('html_inline', '', 0); token.content = title; token = state.push('link_close', 'a', -1); token.block = false; } } else { token = state.push('text', '', 0); token.content = ` ${displayName}:`; } token = state.push('quote_header_close', 'div', -1); } token = state.push('bbcode_open', 'blockquote', 1); }, after: function(state) { state.push('bbcode_close', 'blockquote', -1); state.push('bbcode_close', 'aside', -1); } }; export function setup(helper) { helper.registerOptions((opts, siteSettings) => { opts.enableEmoji = siteSettings.enable_emoji; opts.emojiSet = siteSettings.emoji_set; }); helper.registerPlugin(md => { md.block.bbcode.ruler.push('quotes', rule); }); helper.whiteList(['img[class=avatar]']); helper.whiteList({ custom(tag, name, value) { if (tag === 'aside' && name === 'class') { return value === "quote no-group" || !!/^quote group\-(.+)$/.exec(value); } } }); }