Skip to content

Commit

Permalink
Unify linkify usage, move to linkify-string
Browse files Browse the repository at this point in the history
Signed-off-by: Raimund Schlüßler <[email protected]>
  • Loading branch information
raimund-schluessler committed Sep 24, 2021
1 parent 526c9fe commit 7f8d45e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 26 deletions.
34 changes: 22 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"emoji-mart-vue-fast": "^7.0.7",
"escape-html": "^1.0.3",
"hammerjs": "^2.0.8",
"linkifyjs": "~2.1.9",
"linkify-string": "^3.0.2",
"md5": "^2.2.1",
"splitpanes": "^2.3.6",
"string-length": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/AppSidebar/AppSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ $top-buttons-spacing: 6px;
&::v-deep .linkified {
cursor: pointer;
text-decoration: underline;
margin: 0;
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/directives/Linkify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
import linkifyStr from 'linkifyjs/string'
import Linkify from '../../utils/Linkify'

// Use function shorthand for same behavior on bind and update
// https://vuejs.org/v2/guide/custom-directive.html#Function-Shorthand
export const directive = function(el, binding) {
if (binding.value?.linkify === true) {
el.innerHTML = linkifyStr(binding.value.text, {
defaultProtocol: 'https',
})
el.innerHTML = Linkify(binding.value.text)
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/mixins/richEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import escapeHtml from 'escape-html'
import linkifyStr from 'linkifyjs/string'
import Linkify from '../../utils/Linkify'
import stripTags from 'striptags'
import Vue from 'vue'

Expand Down Expand Up @@ -63,14 +63,7 @@ export default {
// on the the uneven indexes. We only want to generate the mentions html
if (!part.startsWith('@')) {
// This part doesn't contain a mention, let's make sure links are parsed
return linkifyStr(part, {
defaultProtocol: 'https',
target: '_blank',
className: 'external',
attributes: {
rel: 'nofollow noopener noreferrer',
},
})
return Linkify(part)
}

// Extracting the id, nuking the " and @
Expand Down
41 changes: 41 additions & 0 deletions src/utils/Linkify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @copyright Copyright (c) 2021 Raimund Schlüßler <[email protected]>
*
* @author Raimund Schlüßler <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import linkifyStr from 'linkify-string'

/**
* Linkify text
*
* @param {string} text The text to linkify
* @returns {string} The linkified string
*/
const Linkify = (text) => {
return linkifyStr(text, {
defaultProtocol: 'https',
target: '_blank',
className: 'external linkified',
attributes: {
rel: 'nofollow noopener noreferrer',
},
})
}

export default Linkify

0 comments on commit 7f8d45e

Please sign in to comment.