diff options
author | Azul <azul@riseup.net> | 2020-06-16 13:06:18 +0300 |
---|---|---|
committer | Azul <azul@riseup.net> | 2020-08-11 16:25:54 +0300 |
commit | 9dfc8cd64d2f90bf70028088f1c4697e3f659547 (patch) | |
tree | b29abc57854403e91d1f5a9dd53e363f59aaf1a9 /src | |
parent | 03ccc8aa0369ada0ed0d50b50e60171696fdd2e6 (diff) |
refactor: define our own Link mark to rewrite hrefs
The short relative links used in markdown
need to be converted to working urls in the href attributes.
In order to properly serialize the content
the full urls in html need to be converted to relative links as well.
This commit splits out the href handling into a new helper.
This way it can be easily tested.
Signed-off-by: Azul <azul@riseup.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers/files.js | 4 | ||||
-rw-r--r-- | src/helpers/links.js | 34 | ||||
-rw-r--r-- | src/marks/index.js | 4 | ||||
-rw-r--r-- | src/tests/nodes/ImageView.spec.js | 2 |
4 files changed, 38 insertions, 6 deletions
diff --git a/src/helpers/files.js b/src/helpers/files.js index b85319dfb..0494ade03 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -20,10 +20,6 @@ * */ -/** - * Callback that should be executed after the document is ready - * @param callback - */ import { openMimetypes } from './mime' import RichWorkspace from '../views/RichWorkspace' import { imagePath } from '@nextcloud/router' diff --git a/src/helpers/links.js b/src/helpers/links.js new file mode 100644 index 000000000..0a00abfea --- /dev/null +++ b/src/helpers/links.js @@ -0,0 +1,34 @@ +/* + * @copyright Copyright (c) 2020 Azul <azul@riseup.net> + * + * @author Azul <azul@riseup.net> + * + * @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/>. + * + */ + +const domHref = function(node) { + return node.attrs.href +} + +const parseHref = function(dom) { + return dom.getAttribute('href') +} + +export { + domHref, + parseHref, +} diff --git a/src/marks/index.js b/src/marks/index.js index d66da88ca..3a3d6c5f2 100644 --- a/src/marks/index.js +++ b/src/marks/index.js @@ -21,6 +21,7 @@ */ import { Bold, Italic as TipTapItalic, Strike as TipTapStrike, Link as TipTapLink } from 'tiptap-extensions' +import { domHref, parseHref } from './../helpers/links' /** * This file maps prosemirror mark names to tiptap classes, @@ -88,12 +89,13 @@ class Link extends TipTapLink { { tag: 'a[href]', getAttrs: dom => ({ - href: dom.getAttribute('href'), + href: parseHref(dom), }), }, ], toDOM: node => ['a', { ...node.attrs, + href: domHref(node), title: node.attrs.href, rel: 'noopener noreferrer nofollow', }, 0], diff --git a/src/tests/nodes/ImageView.spec.js b/src/tests/nodes/ImageView.spec.js index 43f6b3fdd..0f37a1d9f 100644 --- a/src/tests/nodes/ImageView.spec.js +++ b/src/tests/nodes/ImageView.spec.js @@ -11,7 +11,7 @@ global.OC = { webroot: '' } -describe('Image View html source based on md source', () => { +describe('Image View src attribute based on markdown', () => { const factory = attrs => { const propsData = { |