From 0e8dd9ef4aee5caf58373547765821bd7a945802 Mon Sep 17 00:00:00 2001 From: Shawky Ebrahim Ahmed <101745968+shawkyebrahim2514@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:47:25 +0200 Subject: [PATCH] Supporting links with Markdown Syntax --- react-frontend/README.md | 37 +++++++++ .../HTMLMarkdown/AncherLinkMarkdown.tsx | 35 ++++++++ .../components/HTMLMarkdown/SpanMarkdown.tsx | 81 +++++++++++++++---- .../src/components/HTMLMarkdown/index.tsx | 2 + .../src/components/MainSection/Header.tsx | 4 +- 5 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 react-frontend/src/components/HTMLMarkdown/AncherLinkMarkdown.tsx diff --git a/react-frontend/README.md b/react-frontend/README.md index 3314312..eb162bd 100644 --- a/react-frontend/README.md +++ b/react-frontend/README.md @@ -76,6 +76,43 @@ Into ``` +> Links => Normal markdown notations + +- The normal syntax `[Text](Link)` will be rendered as a text with an icon bext to it +- The syntax `[[Text]](Link)` will be rendered as a lnik button with the text inside it + +```markdown + +[Google](https://google.com) + +--- + +[[Google]](https://google.com) + +``` + +Into + +```html + +

+

+

Google

+

+ +

+
+

+ +

+

+ + Google +
+

+ +``` + > Using Markdown Notations: Highlight Text - Use the syntax `**Text Here**` to make the text bold and with the base color diff --git a/react-frontend/src/components/HTMLMarkdown/AncherLinkMarkdown.tsx b/react-frontend/src/components/HTMLMarkdown/AncherLinkMarkdown.tsx new file mode 100644 index 0000000..c5cb261 --- /dev/null +++ b/react-frontend/src/components/HTMLMarkdown/AncherLinkMarkdown.tsx @@ -0,0 +1,35 @@ +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import Button from '../Button'; +import Header from '../MainSection/Header'; +import type { Element } from 'hast' +import { faLink } from '@fortawesome/free-solid-svg-icons'; + +type AncherLinkMarkdownProps = { + node?: Element, +} & React.HTMLAttributes; + +const AncherLinkMarkdown = ({ node, ...props }: AncherLinkMarkdownProps) => { + console.log("Title: ", props.children); + console.log("Link: ", node?.properties?.href); + const title = props.children as string; + const link = node?.properties?.href as string; + const matchButtonLink = /\[(.*)\]/.exec(title); + if (matchButtonLink) { + return ( +