diff options
author | Cyrille Bollu <cyrpub@bollu.be> | 2019-07-26 15:35:20 +0200 |
---|---|---|
committer | Cyrille Bollu <cyrpub@bollu.be> | 2019-07-26 15:35:20 +0200 |
commit | 18862db660e07c175aea5681e9f4e58eba2e4c3c (patch) | |
tree | cb6f422fb46560905bf100c039a33ad5a572438e | |
parent | e64c1b5244b22a8a7f8124c835adb8145c195db3 (diff) |
Uses hashtag-regex to rewrite hashtag's href rather than linkifyjs.
Reason: linkifyjs doesn't support non-latin characters. So "#Framasphère"
is identified as "#Framasph" for example.
Signed-off-by: Cyrille Bollu <cyrpub@bollu.be>
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/components/TimelinePost.vue | 13 |
2 files changed, 9 insertions, 5 deletions
diff --git a/package.json b/package.json index 69f301da..742b43ea 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "vue-masonry-css": "^1.0.3", + "hashtag-regex": "^2.0.0", "linkifyjs": "^2.1.8", "nextcloud-axios": "^0.2.0", "nextcloud-vue": "^0.11.4", diff --git a/src/components/TimelinePost.vue b/src/components/TimelinePost.vue index c97546bc..5a9079be 100644 --- a/src/components/TimelinePost.vue +++ b/src/components/TimelinePost.vue @@ -52,16 +52,16 @@ <script> import Avatar from 'nextcloud-vue/dist/Components/Avatar' import * as linkify from 'linkifyjs' -import pluginTag from 'linkifyjs/plugins/hashtag' import pluginMention from 'linkifyjs/plugins/mention' import 'linkifyjs/string' import popoverMenu from './../mixins/popoverMenu' import currentUser from './../mixins/currentUserMixin' import PostAttachment from './PostAttachment' -pluginTag(linkify) pluginMention(linkify) +const hashtagRegex = require('hashtag-regex') + export default { name: 'TimelinePost', components: { @@ -109,14 +109,17 @@ export default { message = message.replace(/(?:\r\n|\r|\n)/g, '<br />') message = message.linkify({ formatHref: { - hashtag: function(href) { - return OC.generateUrl('/apps/social/timeline/tags/' + href.substring(1)) - }, mention: function(href) { return OC.generateUrl('/apps/social/@' + href.substring(1)) } } }) + // Replace hashtag's href parameter with local ones + const regex = hashtagRegex() + message = message.replace(regex, function(matched) { + var a = '<a href="' + OC.generateUrl('/apps/social/timeline/tags/' + matched.substring(1)) + '">' + matched + '</a>' + return a + }) message = this.$twemoji.parse(message) return message }, |