Merge branch 'better-still-emoji' into shigusegubu

* better-still-emoji:
  fix not escaping some stuff
  fix rich images
This commit is contained in:
Henry Jameson 2021-06-18 21:43:12 +03:00
commit a0330483cf
4 changed files with 37 additions and 8 deletions

View file

@ -121,14 +121,13 @@ export default Vue.component('RichContent', {
if (emptyText) {
return encounteredText ? item : item.trim()
}
let unescapedItem = unescape(item)
if (!encounteredText) {
unescapedItem = unescapedItem.trimStart()
item = item.trimStart()
encounteredText = true
}
if (item.includes(':')) {
unescapedItem = ['', processTextForEmoji(
unescapedItem,
item = ['', processTextForEmoji(
item,
this.emoji,
({ shortcode, url }) => {
return <StillImage
@ -140,7 +139,7 @@ export default Vue.component('RichContent', {
}
)]
}
return unescapedItem
return item
}
// Handle tag nodes
@ -189,7 +188,7 @@ export default Vue.component('RichContent', {
const emptyText = item.trim() === ''
if (emptyText) return item
if (!encounteredTextReverse) encounteredTextReverse = true
return item
return unescape(item)
} else if (Array.isArray(item)) {
// Handle tag nodes
const [opener, children] = item
@ -203,9 +202,7 @@ export default Vue.component('RichContent', {
return renderHashtag(attrs, children, encounteredTextReverse)
} else {
attrs.target = '_blank'
html.includes('freenode') && console.log('PASS1', children)
const newChildren = [...children].reverse().map(processItemReverse).reverse()
html.includes('freenode') && console.log('PASS1b', newChildren)
return <a {...{ attrs }}>
{ newChildren }

View file

@ -114,6 +114,8 @@ export const convertHtmlToLines = (html) => {
} else {
handleOpen(tagFull)
}
} else {
textBuffer += tagFull
}
} else {
textBuffer += tagFull

View file

@ -27,6 +27,29 @@ describe('RichContent', () => {
expect(wrapper.html()).to.eql(compwrap(html))
})
it('unescapes everything as needed', () => {
const html = [
p('Testing &#39;em all'),
'Testing &#39;em all'
].join('')
const expected = [
p('Testing \'em all'),
'Testing \'em all'
].join('')
const wrapper = shallowMount(RichContent, {
localVue,
propsData: {
hideMentions: true,
handleLinks: true,
greentext: true,
emoji: [],
html
}
})
expect(wrapper.html()).to.eql(compwrap(expected))
})
it('removes mentions from the beginning of post', () => {
const html = p(
makeMention('John'),

View file

@ -69,6 +69,13 @@ describe('html_line_converter', () => {
const comparableResult = result.map(mapOnlyText(processorKeep)).join('')
expect(comparableResult).to.eql(inputOutput)
})
it('fed with some recognized but not handled elements', () => {
const inputOutput = 'testing images\n\n<img src="benis.png">'
const result = convertHtmlToLines(inputOutput)
const comparableResult = result.map(mapOnlyText(processorKeep)).join('')
expect(comparableResult).to.eql(inputOutput)
})
})
describe('with processor that replaces lines with word "_" should match expected line when', () => {
const processorReplace = (line) => '_'