diff --git a/core/src/tests/OCP/comments.spec.js b/core/src/OCP/comments.spec.ts similarity index 96% rename from core/src/tests/OCP/comments.spec.js rename to core/src/OCP/comments.spec.ts index f4493b1f8d6..55f9d174e2a 100644 --- a/core/src/tests/OCP/comments.spec.js +++ b/core/src/OCP/comments.spec.ts @@ -4,7 +4,7 @@ */ import { expect, it } from 'vitest' -import * as Comments from '../../OCP/comments.js' +import { plainToRich } from './comments.ts' it.for([ { input: 'nextcloud.com', expected: 'nextcloud.com' }, @@ -28,6 +28,6 @@ it.for([ { input: 'FirebaseInstanceId.getInstance().deleteInstanceId()', expected: 'FirebaseInstanceId.getInstance().deleteInstanceId()' }, { input: 'I mean...it', expected: 'I mean...it' }, ])('OCP.Comments should parse URLs only', ({ input, expected }) => { - const result = Comments.plainToRich(input) + const result = plainToRich(input) expect(result).toEqual(expected) }) diff --git a/core/src/OCP/comments.js b/core/src/OCP/comments.ts similarity index 57% rename from core/src/OCP/comments.js rename to core/src/OCP/comments.ts index 34699a477d1..c95bebe6899 100644 --- a/core/src/OCP/comments.js +++ b/core/src/OCP/comments.ts @@ -3,8 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import $ from 'jquery' - /* * Detects links: * Either the http(s) protocol is given or two strings, basically limited to ascii with the last @@ -19,23 +17,29 @@ import $ from 'jquery' const urlRegex = /(\s|^)(https?:\/\/)([-A-Z0-9+_.]+(?::[0-9]+)?(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig /** - * @param {any} content - + * Converts plain text to rich text + * + * @param content - The plain text content */ -export function plainToRich(content) { - return this.formatLinksRich(content) +export function plainToRich(content: string) { + return formatLinksRich(content) } /** - * @param {any} content - + * Converts rich text to plain text + * + * @param content - The rich text content */ -export function richToPlain(content) { - return this.formatLinksPlain(content) +export function richToPlain(content: string) { + return formatLinksPlain(content) } /** - * @param {any} content - + * Format links in the given content to rich text links + * + * @param content - The content containing plain text URLs */ -export function formatLinksRich(content) { +export function formatLinksRich(content: string) { return content.replace(urlRegex, function(_, leadingSpace, protocol, url, trailingSpace) { let linkText = url if (!protocol) { @@ -49,13 +53,16 @@ export function formatLinksRich(content) { } /** - * @param {any} content - + * Format links in the given content to plain text links + * + * @param content - The content containing rich text URLs */ -export function formatLinksPlain(content) { - const $content = $('
').html(content) - $content.find('a').each(function() { - const $this = $(this) - $this.html($this.attr('href')) +export function formatLinksPlain(content: string) { + const el = document.createElement('div') + el.innerHTML = content + el.querySelectorAll('a').forEach((anchor) => { + anchor.replaceWith(document.createTextNode(anchor.getAttribute('href') || '')) }) - return $content.html() + + return el.innerHTML } diff --git a/core/src/OCP/index.js b/core/src/OCP/index.js index faf63f1baf4..b2377f050a5 100644 --- a/core/src/OCP/index.js +++ b/core/src/OCP/index.js @@ -7,7 +7,7 @@ import { loadState } from '@nextcloud/initial-state' import Accessibility from './accessibility.js' import * as AppConfig from './appconfig.ts' import Collaboration from './collaboration.js' -import * as Comments from './comments.js' +import * as Comments from './comments.ts' import Loader from './loader.js' import Toast from './toast.js' import * as WhatsNew from './whatsnew.js' @@ -17,6 +17,9 @@ export default { Accessibility, AppConfig, Collaboration, + /** + * @deprecated 33.0.0 + */ Comments, InitialState: { /**