-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aksel.nav.no] Update examples of Page (#3349)
- Loading branch information
1 parent
6483d6b
commit 0be3a08
Showing
15 changed files
with
77 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
aksel.nav.no/website/components/website-modules/TextWithMarkdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
import AkselLink from "@/web/AkselLink"; | ||
import InlineCode from "./InlineCode"; | ||
|
||
/** | ||
* Takes a string and replaces markdown links with Link components | ||
* and backticks with InlineCode components. | ||
*/ | ||
const TextWithMarkdown = ({ children: input }: { children: string }) => { | ||
const regex = /\[([^\]]+)\]\(([^\s)]+)\)|`([^`]+)`/g; // The part before the pipe finds links, the part after finds backticks. | ||
let lastIndex = 0; | ||
const elements: React.ReactNode[] = []; | ||
|
||
input.replace(regex, (match, text, url, code, index) => { | ||
if (index > lastIndex) { | ||
elements.push(input.slice(lastIndex, index)); | ||
} | ||
|
||
if (code) { | ||
elements.push(<InlineCode key={index}>{code}</InlineCode>); | ||
} else { | ||
elements.push( | ||
<AkselLink href={url} key={index}> | ||
{text} | ||
</AkselLink>, | ||
); | ||
} | ||
|
||
lastIndex = index + match.length; | ||
return match; | ||
}); | ||
|
||
if (lastIndex < input.length) { | ||
elements.push(input.slice(lastIndex)); | ||
} | ||
|
||
return <>{elements}</>; | ||
}; | ||
|
||
export { TextWithMarkdown }; |
34 changes: 0 additions & 34 deletions
34
aksel.nav.no/website/components/website-modules/TextWithMarkdownLink.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,7 @@ | |
.containerStaticFull { | ||
padding-block: 1.5rem; | ||
} | ||
|
||
.containerFullscreen { | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters