From 6d3229b1a10a6547d5c0ebcf47a65f03a0f9c690 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 3 Feb 2022 22:23:28 +0200 Subject: fix poast mentions tripping --- src/components/rich_content/rich_content.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index c0d20c5e..46bc661a 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -120,7 +120,8 @@ export default Vue.component('RichContent', { // don't include spaces when processing mentions - we'll include them // in MentionsLine lastSpacing = item - return currentMentions !== null ? item.trim() : item + // Don't remove last space in a container (fixes poast mentions) + return (index !== array.length - 1) && (currentMentions !== null) ? item.trim() : item } currentMentions = null -- cgit v1.2.3-70-g09d2 From 39ecb338830a71c015688e7ec45e16e1151983d3 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 3 Feb 2022 22:58:12 +0200 Subject: fix amps in links --- src/components/rich_content/rich_content.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 46bc661a..8ebabad7 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -60,7 +60,7 @@ export default Vue.component('RichContent', { // NEVER EVER TOUCH DATA INSIDE RENDER render (h) { // Pre-process HTML - const { newHtml: html } = preProcessPerLine(this.html, this.greentext) + const { newHtml: html } = preProcessPerLine(unescape(this.html), this.greentext) let currentMentions = null // Current chain of mentions, we group all mentions together // This is used to recover spacing removed when parsing mentions let lastSpacing = '' -- cgit v1.2.3-70-g09d2 From 571e73a346996f1bcdecb6545b44351a65fee3cb Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 3 Feb 2022 23:13:28 +0200 Subject: better approach to unescaping --- src/components/rich_content/rich_content.jsx | 2 +- src/services/html_converter/html_tree_converter.service.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 8ebabad7..46bc661a 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -60,7 +60,7 @@ export default Vue.component('RichContent', { // NEVER EVER TOUCH DATA INSIDE RENDER render (h) { // Pre-process HTML - const { newHtml: html } = preProcessPerLine(unescape(this.html), this.greentext) + const { newHtml: html } = preProcessPerLine(this.html, this.greentext) let currentMentions = null // Current chain of mentions, we group all mentions together // This is used to recover spacing removed when parsing mentions let lastSpacing = '' diff --git a/src/services/html_converter/html_tree_converter.service.js b/src/services/html_converter/html_tree_converter.service.js index 6a8796c4..247a8173 100644 --- a/src/services/html_converter/html_tree_converter.service.js +++ b/src/services/html_converter/html_tree_converter.service.js @@ -1,4 +1,5 @@ import { getTagName } from './utility.service.js' +import { unescape } from 'lodash' /** * This is a not-so-tiny purpose-built HTML parser/processor. This parses html @@ -49,7 +50,7 @@ export const convertHtmlToTree = (html = '') => { const handleOpen = (tag) => { const curBuf = getCurrentBuffer() - const newLevel = [tag, []] + const newLevel = [unescape(tag), []] levels.push(newLevel) curBuf.push(newLevel) } -- cgit v1.2.3-70-g09d2 From 8311d4deba93309dd60ebeb28f7b3ac1d0d23e6c Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Wed, 16 Mar 2022 22:13:21 +0200 Subject: shit renders yo --- src/components/rich_content/rich_content.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 46bc661a..383b29b3 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -1,4 +1,4 @@ -import Vue from 'vue' +import { h } from 'vue' import { unescape, flattenDeep } from 'lodash' import { getTagName, processTextForEmoji, getAttrs } from 'src/services/html_converter/utility.service.js' import { convertHtmlToTree } from 'src/services/html_converter/html_tree_converter.service.js' @@ -27,7 +27,7 @@ import './rich_content.scss' * * Apart from that one small hiccup with emit in render this _should_ be vue3-ready */ -export default Vue.component('RichContent', { +export default { name: 'RichContent', props: { // Original html content @@ -58,7 +58,7 @@ export default Vue.component('RichContent', { } }, // NEVER EVER TOUCH DATA INSIDE RENDER - render (h) { + render () { // Pre-process HTML const { newHtml: html } = preProcessPerLine(this.html, this.greentext) let currentMentions = null // Current chain of mentions, we group all mentions together @@ -266,7 +266,7 @@ export default Vue.component('RichContent', { return result } -}) +} const getLinkData = (attrs, children, index) => { const stripTags = (item) => { -- cgit v1.2.3-70-g09d2 From 4993dc37e2430067a92ec78389c9d9dce79d19db Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 17 Mar 2022 08:47:19 +0200 Subject: fix rich content not rendering stillimage nor links correctly --- src/components/rich_content/rich_content.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 383b29b3..97c51189 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -76,7 +76,7 @@ export default { const renderImage = (tag) => { return } @@ -222,7 +222,7 @@ export default { attrs.target = '_blank' const newChildren = [...children].reverse().map(processItemReverse).reverse() - return + return { newChildren } } -- cgit v1.2.3-70-g09d2 From c2cf13fc006aa1e513feb99799a8d2df14119eca Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 22 Mar 2022 16:40:45 +0200 Subject: fix richcontent and its tests --- src/components/rich_content/rich_content.jsx | 7 +- test/unit/specs/components/rich_content.spec.js | 234 ++++++++++++------------ 2 files changed, 124 insertions(+), 117 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 97c51189..41e287e4 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -1,4 +1,3 @@ -import { h } from 'vue' import { unescape, flattenDeep } from 'lodash' import { getTagName, processTextForEmoji, getAttrs } from 'src/services/html_converter/utility.service.js' import { convertHtmlToTree } from 'src/services/html_converter/html_tree_converter.service.js' @@ -82,12 +81,12 @@ export default { } const renderHashtag = (attrs, children, encounteredTextReverse) => { - const linkData = getLinkData(attrs, children, tagsIndex++) + const { index, ...linkData } = getLinkData(attrs, children, tagsIndex++) writtenTags.push(linkData) if (!encounteredTextReverse) { lastTags.push(linkData) } - return + return } const renderMention = (attrs, children) => { @@ -235,7 +234,7 @@ export default { const newChildren = Array.isArray(children) ? [...children].reverse().map(processItemReverse).reverse() : children - return + return { newChildren } } else { diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index 30c66a33..a4920867 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -1,8 +1,15 @@ -import { mount, shallowMount, createLocalVue } from '@vue/test-utils' +import { mount, shallowMount } from '@vue/test-utils' import RichContent from 'src/components/rich_content/rich_content.jsx' -const localVue = createLocalVue() const attentions = [] +const global = { + mocks: { + '$store': null + }, + stubs: { + FAIcon: true + } +} const makeMention = (who) => { attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` }) @@ -11,17 +18,17 @@ const makeMention = (who) => { const p = (...data) => `

${data.join('')}

` const compwrap = (...data) => `${data.join('')}` const mentionsLine = (times) => [ - '' + '">' ].join('') describe('RichContent', () => { it('renders simple post without exploding', () => { const html = p('Hello world!') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -30,7 +37,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(html)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(html)) }) it('unescapes everything as needed', () => { @@ -43,8 +50,8 @@ describe('RichContent', () => { 'Testing \'em all' ].join('') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -53,7 +60,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('replaces mention with mentionsline', () => { @@ -62,8 +69,8 @@ describe('RichContent', () => { ' how are you doing today?' ) const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -72,7 +79,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(p( + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(p( mentionsLine(1), ' how are you doing today?' ))) @@ -93,17 +100,17 @@ describe('RichContent', () => { ), // TODO fix this extra line somehow? p( - '' + '">' ) ].join('') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -112,7 +119,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('Does not touch links if link handling is disabled', () => { @@ -130,8 +137,8 @@ describe('RichContent', () => { ].join('\n') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: false, greentext: true, @@ -154,8 +161,8 @@ describe('RichContent', () => { ].join('\n') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: false, greentext: true, @@ -174,8 +181,8 @@ describe('RichContent', () => { ].join('\n') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: false, greentext: false, @@ -191,12 +198,12 @@ describe('RichContent', () => { const html = p('Ebin :DDDD :spurdo:') const expected = p( 'Ebin :DDDD ', - '' + '' ) const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: false, greentext: false, @@ -205,15 +212,15 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('Doesn\'t add nonexistent emoji to post', () => { const html = p('Lol :lol:') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: false, greentext: false, @@ -222,7 +229,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(html)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(html)) }) it('Greentext + last mentions', () => { @@ -240,8 +247,8 @@ describe('RichContent', () => { ].join('\n') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -272,8 +279,8 @@ describe('RichContent', () => { ].join('
') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -282,7 +289,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('buggy example/hashtags', () => { @@ -300,16 +307,18 @@ describe('RichContent', () => { '

', '', 'NHCMDUXJPPZ6M3Z2CQ6D2EBRSWGE7MZY.jpg', - ' ', - '', - ' ', - '', + ' ', + '#nou', + '', + ' ', + '#screencap', + '', '

' ].join('') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -318,7 +327,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('rich contents of a mention are handled properly', () => { @@ -342,7 +351,8 @@ describe('RichContent', () => { p( '', '', - '', + '', + '', '', 'https://', '', @@ -350,9 +360,10 @@ describe('RichContent', () => { '', '', '', - '', // v-if placeholder, mentionlink's "new" (i.e. rich) display + '', + '', // v-if placeholder, mentionlink's "new" (i.e. rich) display '', - '', // v-if placeholder, mentionsline's extra mentions and stuff + '', // v-if placeholder, mentionsline's extra mentions and stuff '' ), p( @@ -361,8 +372,8 @@ describe('RichContent', () => { ].join('') const wrapper = mount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -371,76 +382,73 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('rich contents of nested mentions are handled properly', () => { attentions.push({ statusnet_profile_url: 'lol' }) const html = [ - p( - '', - '', - '', - 'https://', - '', - 'lol.tld/', - '', - '', - '', - ' ', - '', - '', - 'https://', - '', - 'lol.tld/', - '', - '', - '', - '' - ), - p( - 'Testing' - ) + '', + '', + '', + 'https://', + '', + 'lol.tld/', + '', + '', + '', + ' ', + '', + '', + 'https://', + '', + 'lol.tld/', + '', + '', + '', + ' ', + '', + 'Testing' ].join('') const expected = [ - p( - '', - '', - '', - '', - '', - 'https://', - '', - 'lol.tld/', - '', - '', - '', - '', // v-if placeholder, mentionlink's "new" (i.e. rich) display - '', - '', - '', - '', - 'https://', - '', - 'lol.tld/', - '', - '', - '', - '', // v-if placeholder, mentionlink's "new" (i.e. rich) display - '', - '', // v-if placeholder, mentionsline's extra mentions and stuff - '', - '' - ), + '', + '', + '', + '', + '', + '', + 'https://', + '', + 'lol.tld/', + '', + '', + '', + '', + '', // v-if placeholder, mentionlink's "new" (i.e. rich) display + '', + '', + '', + '', + '', + 'https://', + '', + 'lol.tld/', + '', + '', + '', + '', + '', // v-if placeholder, mentionlink's "new" (i.e. rich) display + '', + '', // v-if placeholder, mentionsline's extra mentions and stuff + '', ' ', - p( - 'Testing' - ) + '', + 'Testing' ].join('') const wrapper = mount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -449,7 +457,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it('rich contents of a link are handled properly', () => { @@ -483,8 +491,8 @@ describe('RichContent', () => { ].join('') const wrapper = shallowMount(RichContent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks: true, greentext: true, @@ -493,7 +501,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(expected)) + expect(wrapper.html().replace(/\n/g, '')).to.eql(compwrap(expected)) }) it.skip('[INFORMATIVE] Performance testing, 10 000 simple posts', () => { @@ -530,8 +538,8 @@ describe('RichContent', () => { const t0 = performance.now() const wrapper = mount(TestComponent, { - localVue, - propsData: { + global, + props: { attentions, handleLinks, vhtml -- cgit v1.2.3-70-g09d2 From d175e86901dda5b54f7caad744f78f347332f821 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Tue, 12 Apr 2022 18:10:19 +0300 Subject: fix hashtags by explicitly putting attributes --- src/components/rich_content/rich_content.jsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 41e287e4..ca075270 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -28,6 +28,10 @@ import './rich_content.scss' */ export default { name: 'RichContent', + components: { + MentionsLine, + HashtagLink + }, props: { // Original html content html: { @@ -86,7 +90,8 @@ export default { if (!encounteredTextReverse) { lastTags.push(linkData) } - return + const { url, tag, content } = linkData + return } const renderMention = (attrs, children) => { -- cgit v1.2.3-70-g09d2 From 7fed35a627679e20003ee76a3015f84d395c85ac Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sat, 26 Nov 2022 23:38:06 +0200 Subject: fun restrained --- src/components/rich_content/rich_content.jsx | 9 +++++---- src/services/html_converter/utility.service.js | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index ca075270..8a5758af 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -179,7 +179,7 @@ export default { break } case 'span': - if (this.handleLinks && attrs['class'] && attrs['class'].includes('h-card')) { + if (this.handleLinks && attrs.class && attrs.class.includes('h-card')) { return ['', children.map(processItem), ''] } } @@ -213,13 +213,13 @@ export default { const [opener, children] = item const Tag = opener === '' ? '' : getTagName(opener) switch (Tag) { - case 'a': // replace mentions with MentionLink + case 'a': { // replace mentions with MentionLink if (!this.handleLinks) break const attrs = getAttrs(opener) // should only be this if ( - (attrs['class'] && attrs['class'].includes('hashtag')) || // Pleroma style - (attrs['rel'] === 'tag') // Mastodon style + (attrs.class && attrs.class.includes('hashtag')) || // Pleroma style + (attrs.rel === 'tag') // Mastodon style ) { return renderHashtag(attrs, children, encounteredTextReverse) } else { @@ -230,6 +230,7 @@ export default { { newChildren } } + } case '': return [...children].reverse().map(processItemReverse).reverse() } diff --git a/src/services/html_converter/utility.service.js b/src/services/html_converter/utility.service.js index 583ccca5..c8670cb4 100644 --- a/src/services/html_converter/utility.service.js +++ b/src/services/html_converter/utility.service.js @@ -16,7 +16,7 @@ export const getTagName = (tag) => { * @return {Object} - map of attributes key = attribute name, value = attribute value * attributes without values represented as boolean true */ -export const getAttrs = tag => { +export const getAttrs = (tag, filter) => { const innertag = tag .substring(1, tag.length - 1) .replace(new RegExp('^' + getTagName(tag)), '') @@ -28,7 +28,8 @@ export const getAttrs = tag => { if (!v) return [k, true] return [k, v.substring(1, v.length - 1)] }) - return Object.fromEntries(attrs) + const defaultFilter = ([k, v]) => (k.toLowerCase() !== 'class' && k.toLowerCase() !== 'style') + return Object.fromEntries(attrs.filter(filter || defaultFilter)) } /** -- cgit v1.2.3-70-g09d2 From 74813864fcbd513a5782b739055f132c68e6eca7 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 27 Nov 2022 00:11:54 +0200 Subject: fix tests --- src/components/rich_content/rich_content.jsx | 12 +++++++----- src/services/html_converter/utility.service.js | 9 ++++++++- test/unit/specs/components/rich_content.spec.js | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) (limited to 'src/components/rich_content') diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx index 8a5758af..7881e365 100644 --- a/src/components/rich_content/rich_content.jsx +++ b/src/components/rich_content/rich_content.jsx @@ -150,6 +150,7 @@ export default { if (Array.isArray(item)) { const [opener, children, closer] = item const Tag = getTagName(opener) + const fullAttrs = getAttrs(opener, () => true) const attrs = getAttrs(opener) const previouslyMentions = currentMentions !== null /* During grouping of mentions we trim all the empty text elements @@ -171,7 +172,7 @@ export default { return ['', [mentionsLinePadding, renderImage(opener)], ''] case 'a': // replace mentions with MentionLink if (!this.handleLinks) break - if (attrs['class'] && attrs['class'].includes('mention')) { + if (fullAttrs.class && fullAttrs.class.includes('mention')) { // Handling mentions here return renderMention(attrs, children) } else { @@ -179,7 +180,7 @@ export default { break } case 'span': - if (this.handleLinks && attrs.class && attrs.class.includes('h-card')) { + if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) { return ['', children.map(processItem), ''] } } @@ -215,11 +216,12 @@ export default { switch (Tag) { case 'a': { // replace mentions with MentionLink if (!this.handleLinks) break - const attrs = getAttrs(opener) + const fullAttrs = getAttrs(opener, () => true) + const attrs = getAttrs(opener, () => true) // should only be this if ( - (attrs.class && attrs.class.includes('hashtag')) || // Pleroma style - (attrs.rel === 'tag') // Mastodon style + (fullAttrs.class && fullAttrs.class.includes('hashtag')) || // Pleroma style + (fullAttrs.rel === 'tag') // Mastodon style ) { return renderHashtag(attrs, children, encounteredTextReverse) } else { diff --git a/src/services/html_converter/utility.service.js b/src/services/html_converter/utility.service.js index c8670cb4..f1042971 100644 --- a/src/services/html_converter/utility.service.js +++ b/src/services/html_converter/utility.service.js @@ -28,7 +28,14 @@ export const getAttrs = (tag, filter) => { if (!v) return [k, true] return [k, v.substring(1, v.length - 1)] }) - const defaultFilter = ([k, v]) => (k.toLowerCase() !== 'class' && k.toLowerCase() !== 'style') + const defaultFilter = ([k, v]) => { + const attrKey = k.toLowerCase() + if (attrKey === 'style') return false + if (attrKey === 'class') { + return v === 'greentext' || v === 'cyantext' + } + return true + } return Object.fromEntries(attrs.filter(filter || defaultFilter)) } diff --git a/test/unit/specs/components/rich_content.spec.js b/test/unit/specs/components/rich_content.spec.js index 616df6a0..427eb5ed 100644 --- a/test/unit/specs/components/rich_content.spec.js +++ b/test/unit/specs/components/rich_content.spec.js @@ -19,9 +19,11 @@ const global = { } } -const makeMention = (who) => { +const makeMention = (who, noClass) => { attentions.push({ statusnet_profile_url: `https://fake.tld/@${who}` }) - return `@${who}` + return noClass + ? `@${who}` + : `@${who}` } const p = (...data) => `

${data.join('')}

` const compwrap = (...data) => `${data.join('')}` @@ -142,6 +144,17 @@ describe('RichContent', () => { makeMention('Josh'), makeMention('Jeremy') ].join('') ].join('\n') + const strippedHtml = [ + [ + makeMention('Jack', true), + 'let\'s meet up with ', + makeMention('Janet', true) + ].join(''), + [ + makeMention('John', true), + makeMention('Josh', true), makeMention('Jeremy', true) + ].join('') + ].join('\n') const wrapper = shallowMount(RichContent, { global, @@ -154,7 +167,7 @@ describe('RichContent', () => { } }) - expect(wrapper.html()).to.eql(compwrap(html)) + expect(wrapper.html()).to.eql(compwrap(strippedHtml)) }) it('Adds greentext and cyantext to the post', () => { @@ -412,7 +425,7 @@ describe('RichContent', () => { 'Testing' ].join('') const expected = [ - '', + '', '', '', '', -- cgit v1.2.3-70-g09d2