diff options
author | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-10-18 00:54:41 +0300 |
---|---|---|
committer | Vinicius Reis <vinicius.reis@nextcloud.com> | 2022-10-27 19:04:08 +0300 |
commit | 403fe2e179c56c6b672f480d4392484e7aac8d51 (patch) | |
tree | 05b436ca2736fcfc0a5d2f74264e35d311fc5caa | |
parent | d98929388d2fb8f7f4741e12a7e07da737542544 (diff) |
🐛 fix relative link in RichWorkspace
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
-rw-r--r-- | src/EditorFactory.js | 3 | ||||
-rw-r--r-- | src/components/Editor.vue | 1 | ||||
-rw-r--r-- | src/extensions/RichText.js | 1 | ||||
-rw-r--r-- | src/helpers/links.js | 5 | ||||
-rw-r--r-- | src/marks/Link.js | 15 |
5 files changed, 17 insertions, 8 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index 2e7c8b9e3..18466fb5e 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -57,12 +57,13 @@ const loadSyntaxHighlight = async (language) => { } } -const createEditor = ({ content, onCreate, onUpdate, extensions, enableRichEditing, session }) => { +const createEditor = ({ content, onCreate, onUpdate, extensions, enableRichEditing, session, relativePath }) => { let richEditingExtensions = [] if (enableRichEditing) { richEditingExtensions = [ Markdown, RichText.configure({ + relativePath, extensions: [ EditableTable, Mention.configure({ diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 2829045d9..92e7a5fa6 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -483,6 +483,7 @@ export default { (this.isRichEditor ? Promise.resolve() : loadSyntaxHighlight(language)) .then(() => { this.$editor = createEditor({ + relativePath: this.relativePath, session: this.currentSession, content, onCreate: ({ editor }) => { diff --git a/src/extensions/RichText.js b/src/extensions/RichText.js index 82b34d9a6..12454be39 100644 --- a/src/extensions/RichText.js +++ b/src/extensions/RichText.js @@ -99,6 +99,7 @@ export default Extension.create({ ...this.options.link, openOnClick: true, validate: href => /^https?:\/\//.test(href), + relativePath: this.options.relativePath, })) } const additionalExtensionNames = this.options.extensions.map(e => e.name) diff --git a/src/helpers/links.js b/src/helpers/links.js index 99088a307..6c02f18cb 100644 --- a/src/helpers/links.js +++ b/src/helpers/links.js @@ -50,7 +50,7 @@ const basedir = function(file) { : file.slice(0, end + 1) // basedir('/toplevel') should return '/' } -const domHref = function(node) { +const domHref = function(node, relativePath) { const ref = node.attrs.href if (!ref) { return ref @@ -61,10 +61,11 @@ const domHref = function(node) { if (ref.startsWith('#')) { return ref } + const match = ref.match(/^([^?]*)\?fileId=(\d+)/) if (match) { const [, relPath, id] = match - const currentDir = basedir(OCA.Viewer.file) + const currentDir = basedir(relativePath || OCA.Viewer.file) const dir = absolutePath(currentDir, basedir(relPath)) if (relPath.length > 1 && relPath.endsWith('/')) { // is directory diff --git a/src/marks/Link.js b/src/marks/Link.js index 14a970af8..02da20f50 100644 --- a/src/marks/Link.js +++ b/src/marks/Link.js @@ -30,6 +30,7 @@ const Link = TipTapLink.extend({ return { ...this.parent?.(), onClick: openLink, + relativePath: null, } }, @@ -56,11 +57,15 @@ const Link = TipTapLink.extend({ }, ], - renderHTML: ({ mark, HTMLAttributes }) => ['a', { - ...mark.attrs, - href: domHref(mark), - rel: 'noopener noreferrer nofollow', - }, 0], + renderHTML(options) { + const { mark } = options + + return ['a', { + ...mark.attrs, + href: domHref(mark, this.options.relativePath), + rel: 'noopener noreferrer nofollow', + }, 0] + }, addProseMirrorPlugins() { const plugins = this.parent() |