From 9c13101b62b1df150e1b3dbb93807df60a074ad5 Mon Sep 17 00:00:00 2001
From: dobri1408 <50819975+dobri1408@users.noreply.github.com>
Date: Fri, 13 Sep 2024 10:33:24 +0300
Subject: [PATCH] feat: autodetect links and use universal link - refs #274052
---
src/Blocks/Footnote/FootnotesBlockView.jsx | 40 ++++++--
src/editor/render.jsx | 102 ++++++++++++---------
src/editor/utils.js | 9 --
src/editor/utils.test.js | 14 ---
4 files changed, 91 insertions(+), 74 deletions(-)
diff --git a/src/Blocks/Footnote/FootnotesBlockView.jsx b/src/Blocks/Footnote/FootnotesBlockView.jsx
index 08c9629..cc8d304 100644
--- a/src/Blocks/Footnote/FootnotesBlockView.jsx
+++ b/src/Blocks/Footnote/FootnotesBlockView.jsx
@@ -3,13 +3,13 @@ import {
openAccordionOrTabIfContainsFootnoteReference,
getAllBlocksAndSlateFields,
makeFootnoteListOfUniqueItems,
- makeFootnote,
} from '@eeacms/volto-slate-footnote/editor/utils';
import './less/public.less';
import { UniversalLink } from '@plone/volto/components';
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
+const urlRegex = /https?:\/\/[^\s]+/g;
/**
* @summary The React component that displays the list of footnotes inserted
@@ -19,6 +19,7 @@ const alphabet = 'abcdefghijklmnopqrstuvwxyz';
* @param {Object} props Contains the properties `data` and `properties` as
* received from the Volto form.
*/
+
const FootnotesBlockView = (props) => {
const { data, properties, tabData, content } = props;
const { title, global, placeholder = 'Footnotes' } = data;
@@ -75,6 +76,30 @@ const FootnotesBlockView = (props) => {
startList = citationIndice;
}
+ const renderTextWithLinks = (text) => {
+ if (!text) return null;
+ const parts = text.split(urlRegex);
+ const links = text.match(urlRegex);
+ let result = [];
+
+ parts.forEach((part, index) => {
+ result.push({part});
+
+ if (links && links[index]) {
+ result.push(
+