diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-10-18 16:28:59 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-10-21 10:10:57 +0200 |
| commit | d667ef8b470f4749e18ac59fc2607c369215a644 (patch) | |
| tree | acc7aa159012d2cfa69602c7f1257d8734c47c20 /gui | |
| parent | b4bf5d95f1df339d416df7df2634dbe2bb370440 (diff) | |
| download | mullvadvpn-d667ef8b470f4749e18ac59fc2607c369215a644.tar.xz mullvadvpn-d667ef8b470f4749e18ac59fc2607c369215a644.zip | |
Replace markdown formatter with HTML formatter
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/src/renderer/lib/html-formatter.tsx | 18 | ||||
| -rw-r--r-- | gui/src/renderer/markdown-formatter.tsx | 19 |
2 files changed, 18 insertions, 19 deletions
diff --git a/gui/src/renderer/lib/html-formatter.tsx b/gui/src/renderer/lib/html-formatter.tsx new file mode 100644 index 0000000000..452b7fb1e8 --- /dev/null +++ b/gui/src/renderer/lib/html-formatter.tsx @@ -0,0 +1,18 @@ +import React from 'react'; +import styled from 'styled-components'; + +const boldSyntax = /(<b>.*?<\/b>)/g; +const Bold = styled.span({ fontWeight: 700 }); + +export function formatHtml(inputString: string): React.ReactElement { + const formattedString = inputString.split(boldSyntax).map((value, index) => { + if (boldSyntax.test(value)) { + const valueWithoutTags = value.replaceAll(/<b>|<\/b>/g, ''); + return <Bold key={index}>{valueWithoutTags}</Bold>; + } else { + return <React.Fragment key={index}>{value}</React.Fragment>; + } + }); + + return <>{formattedString}</>; +} diff --git a/gui/src/renderer/markdown-formatter.tsx b/gui/src/renderer/markdown-formatter.tsx deleted file mode 100644 index b6b18c62d6..0000000000 --- a/gui/src/renderer/markdown-formatter.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React from 'react'; -import styled from 'styled-components'; - -const boldSyntax = '**'; -const Bold = styled.span({ fontWeight: 700 }); - -export function formatMarkdown(inputString: string): React.ReactElement { - const formattedString = inputString - .split(boldSyntax) - .map((value, index) => - index % 2 === 0 ? ( - <React.Fragment key={index}>{value}</React.Fragment> - ) : ( - <Bold key={index}>{value}</Bold> - ), - ); - - return <>{formattedString}</>; -} |
