From 20ce6468520e76b0fb2931a5fac368157d950b1d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 03:14:48 +0300 Subject: [WIP] MUCH better approach to replacing emojis with still versions --- .../mini_post_html_processor.spec.js | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js (limited to 'test') diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js new file mode 100644 index 00000000..41818f57 --- /dev/null +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -0,0 +1,130 @@ +import { convertHtml, processTextForEmoji } from 'src/services/mini_html_converter/mini_html_converter.service.js' + +describe('MiniHtmlConverter', () => { + describe('convertHtml', () => { + it('converts html into a tree structure', () => { + const inputOutput = '1

2

345' + expect(convertHtml(inputOutput)).to.eql([ + '1 ', + [ + '

', + ['2'], + '

' + ], + ' ', + [ + '', + [ + '3', + [''], + '4' + ], + '' + ], + '5' + ]) + }) + it('converts html to tree while preserving tag formatting', () => { + const inputOutput = '1

2

345' + expect(convertHtml(inputOutput)).to.eql([ + '1 ', + [ + '

', + ['2'], + '

' + ], + [ + '', + [ + '3', + [''], + '4' + ], + '' + ], + '5' + ]) + }) + it('converts semi-broken html', () => { + const inputOutput = '1
2

42' + expect(convertHtml(inputOutput)).to.eql([ + '1 ', + ['
'], + ' 2 ', + [ + '

', + [' 42'] + ] + ]) + }) + it('realistic case', () => { + const inputOutput = '

@benis @hj nice

' + expect(convertHtml(inputOutput)).to.eql([ + [ + '

', + [ + [ + '', + [ + [ + '', + [ + '@', + [ + '', + [ + 'benis' + ], + '' + ] + ], + '' + ] + ], + '' + ], + ' ', + [ + '', + [ + [ + '', + [ + '@', + [ + '', + [ + 'hj' + ], + '' + ] + ], + '' + ] + ], + '' + ], + ' nice' + ], + '

' + ] + ]) + }) + }) + describe('processTextForEmoji', () => { + it('processes all emoji in text', () => { + const inputOutput = 'Hello from finland! :lol: We have best water! :lmao:' + const emojis = [ + { shortcode: 'lol', src: 'LOL' }, + { shortcode: 'lmao', src: 'LMAO' } + ] + const processor = ({ shortcode, src }) => ({ shortcode, src }) + expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([ + 'Hello from finland! ', + { shortcode: 'lol', src: 'LOL' }, + ' We have best water! ', + { shortcode: 'lmao', src: 'LMAO' } + ]) + }) + }) +}) -- cgit v1.2.3-70-g09d2 From be79643bcf6f05df500f0d6bcb773f07dd15da3d Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 12:38:27 +0300 Subject: fix emoji processor not leaving string as-is if no emoji are found --- .../mini_html_converter.service.js | 1 + .../mini_post_html_processor.spec.js | 29 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/src/services/mini_html_converter/mini_html_converter.service.js b/src/services/mini_html_converter/mini_html_converter.service.js index 00d20019..879ff544 100644 --- a/src/services/mini_html_converter/mini_html_converter.service.js +++ b/src/services/mini_html_converter/mini_html_converter.service.js @@ -118,6 +118,7 @@ export const processTextForEmoji = (text, emojis, processor) => { textBuffer += char } } + if (textBuffer) buffer.push(textBuffer) return buffer } diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js index 41818f57..c4e3f688 100644 --- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -57,7 +57,7 @@ describe('MiniHtmlConverter', () => { ] ]) }) - it('realistic case', () => { + it('realistic case 1', () => { const inputOutput = '

@benis @hj nice

' expect(convertHtml(inputOutput)).to.eql([ [ @@ -110,6 +110,24 @@ describe('MiniHtmlConverter', () => { ] ]) }) + it('realistic case 2', () => { + const inputOutput = 'Country improv: give me a city
Audience: Memphis
Improv troupe: come on, a better one
Audience: el paso' + expect(convertHtml(inputOutput)).to.eql([ + 'Country improv: give me a city', + [ + '
' + ], + 'Audience: Memphis', + [ + '
' + ], + 'Improv troupe: come on, a better one', + [ + '
' + ], + 'Audience: el paso' + ]) + }) }) describe('processTextForEmoji', () => { it('processes all emoji in text', () => { @@ -126,5 +144,14 @@ describe('MiniHtmlConverter', () => { { shortcode: 'lmao', src: 'LMAO' } ]) }) + it('leaves text as is', () => { + const inputOutput = 'Number one: that\'s terror' + const emojis = [] + const processor = ({ shortcode, src }) => ({ shortcode, src }) + expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([ + 'Number one: that\'s terror' + ]) + }) + }) }) }) -- cgit v1.2.3-70-g09d2 From 1923ed84d451011df42e47a85060cc754a011e27 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 16:15:32 +0300 Subject: more tests --- .../mini_post_html_processor.spec.js | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js index c4e3f688..b42f5f35 100644 --- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -1,10 +1,10 @@ -import { convertHtml, processTextForEmoji } from 'src/services/mini_html_converter/mini_html_converter.service.js' +import { convertHtml, processTextForEmoji, getAttrs } from 'src/services/mini_html_converter/mini_html_converter.service.js' describe('MiniHtmlConverter', () => { describe('convertHtml', () => { it('converts html into a tree structure', () => { - const inputOutput = '1

2

345' - expect(convertHtml(inputOutput)).to.eql([ + const input = '1

2

345' + expect(convertHtml(input)).to.eql([ '1 ', [ '

', @@ -25,8 +25,8 @@ describe('MiniHtmlConverter', () => { ]) }) it('converts html to tree while preserving tag formatting', () => { - const inputOutput = '1

2

345' - expect(convertHtml(inputOutput)).to.eql([ + const input = '1

2

345' + expect(convertHtml(input)).to.eql([ '1 ', [ '

', @@ -46,8 +46,8 @@ describe('MiniHtmlConverter', () => { ]) }) it('converts semi-broken html', () => { - const inputOutput = '1
2

42' - expect(convertHtml(inputOutput)).to.eql([ + const input = '1
2

42' + expect(convertHtml(input)).to.eql([ '1 ', ['
'], ' 2 ', @@ -58,8 +58,8 @@ describe('MiniHtmlConverter', () => { ]) }) it('realistic case 1', () => { - const inputOutput = '

@benis @hj nice

' - expect(convertHtml(inputOutput)).to.eql([ + const input = '

@benis @hj nice

' + expect(convertHtml(input)).to.eql([ [ '

', [ @@ -129,15 +129,16 @@ describe('MiniHtmlConverter', () => { ]) }) }) + describe('processTextForEmoji', () => { it('processes all emoji in text', () => { - const inputOutput = 'Hello from finland! :lol: We have best water! :lmao:' + const input = 'Hello from finland! :lol: We have best water! :lmao:' const emojis = [ { shortcode: 'lol', src: 'LOL' }, { shortcode: 'lmao', src: 'LMAO' } ] const processor = ({ shortcode, src }) => ({ shortcode, src }) - expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([ + expect(processTextForEmoji(input, emojis, processor)).to.eql([ 'Hello from finland! ', { shortcode: 'lol', src: 'LOL' }, ' We have best water! ', @@ -145,13 +146,21 @@ describe('MiniHtmlConverter', () => { ]) }) it('leaves text as is', () => { - const inputOutput = 'Number one: that\'s terror' + const input = 'Number one: that\'s terror' const emojis = [] const processor = ({ shortcode, src }) => ({ shortcode, src }) - expect(processTextForEmoji(inputOutput, emojis, processor)).to.eql([ + expect(processTextForEmoji(input, emojis, processor)).to.eql([ 'Number one: that\'s terror' ]) }) }) + + describe('getAttrs', () => { + it('extracts arguments from tag', () => { + const input = '' + const output = { src: 'boop', cool: true, ebin: 'true' } + + expect(getAttrs(input)).to.eql(output) + }) }) }) -- cgit v1.2.3-70-g09d2 From b0ae32e309134f0e91026c6712f2e9081f493c22 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 7 Jun 2021 16:31:39 +0300 Subject: made getAttrs correctly handle both ' and " --- src/services/mini_html_converter/mini_html_converter.service.js | 4 ++-- .../tiny_post_html_processor/mini_post_html_processor.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/src/services/mini_html_converter/mini_html_converter.service.js b/src/services/mini_html_converter/mini_html_converter.service.js index 879ff544..01f8adf8 100644 --- a/src/services/mini_html_converter/mini_html_converter.service.js +++ b/src/services/mini_html_converter/mini_html_converter.service.js @@ -128,11 +128,11 @@ export const getAttrs = tag => { .replace(new RegExp('^' + getTagName(tag)), '') .replace(/\/?$/, '') .trim() - const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=(?:"([^"]+?)"|'([^']+?)'))?/gi)) + const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=("[^"]+?"|'[^']+?'))?/gi)) .map(([trash, key, value]) => [key, value]) .map(([k, v]) => { if (!v) return [k, true] - return [k, v] + return [k, v.substring(1, v.length - 1)] }) return Object.fromEntries(attrs) } diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js index b42f5f35..8df2fbc3 100644 --- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -157,7 +157,7 @@ describe('MiniHtmlConverter', () => { describe('getAttrs', () => { it('extracts arguments from tag', () => { - const input = '' + const input = '' const output = { src: 'boop', cool: true, ebin: 'true' } expect(getAttrs(input)).to.eql(output) -- cgit v1.2.3-70-g09d2 From cc00af7a3102034b05ebcd4aa1fd01c6f467184a Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Thu, 10 Jun 2021 18:52:01 +0300 Subject: Hellthread(tm) Certified --- src/components/mention_link/mention_link.js | 3 - src/components/mention_link/mention_link.vue | 1 - src/components/rich_content/rich_content.jsx | 176 ++++++++++++++++----- src/components/status/status.js | 3 + src/components/status/status.vue | 1 + src/components/status_body/status_body.js | 8 +- src/components/status_body/status_body.vue | 12 +- src/components/status_content/status_content.js | 1 + src/components/status_content/status_content.vue | 3 +- .../html_converter/html_line_converter.service.js | 102 ++++++++++++ .../html_converter/html_tree_converter.service.js | 146 +++++++++++++++++ .../mini_html_converter.service.js | 138 ---------------- .../tiny_post_html_processor.service.js | 94 ----------- .../html_converter/html_line_converter.spec.js | 130 +++++++++++++++ .../html_converter/html_tree_converter.spec.js | 166 +++++++++++++++++++ .../mini_post_html_processor.spec.js | 166 ------------------- .../tiny_post_html_processor.spec.js | 96 ----------- 17 files changed, 707 insertions(+), 539 deletions(-) create mode 100644 src/services/html_converter/html_line_converter.service.js create mode 100644 src/services/html_converter/html_tree_converter.service.js delete mode 100644 src/services/mini_html_converter/mini_html_converter.service.js delete mode 100644 src/services/tiny_post_html_processor/tiny_post_html_processor.service.js create mode 100644 test/unit/specs/services/html_converter/html_line_converter.spec.js create mode 100644 test/unit/specs/services/html_converter/html_tree_converter.spec.js delete mode 100644 test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js delete mode 100644 test/unit/specs/services/tiny_post_html_processor/tiny_post_html_processor.spec.js (limited to 'test') diff --git a/src/components/mention_link/mention_link.js b/src/components/mention_link/mention_link.js index 711c87d6..00b9e388 100644 --- a/src/components/mention_link/mention_link.js +++ b/src/components/mention_link/mention_link.js @@ -70,9 +70,6 @@ const MentionLink = { highlightClass () { if (this.highlight) return highlightClass(this.user) }, - oldPlace () { - return !this.mergedConfig.mentionsOwnLine - }, oldStyle () { return !this.mergedConfig.mentionsNewStyle }, diff --git a/src/components/mention_link/mention_link.vue b/src/components/mention_link/mention_link.vue index 281fab25..a65dbad3 100644 --- a/src/components/mention_link/mention_link.vue +++ b/src/components/mention_link/mention_link.vue @@ -1,7 +1,6 @@