Skip to content

Commit

Permalink
fix: correctly renders custom markdown elements
Browse files Browse the repository at this point in the history
Correctly renders the custom markdown elements
  • Loading branch information
anguspiv committed Nov 20, 2022
1 parent 1e2cc7b commit 930265e
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 19 deletions.
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"rehype-autolink-headings": "^6.1.1",
"rehype-parse": "^8.0.4",
"rehype-react": "^7.1.1",
"rehype-sanitize": "^5.0.1",
"rehype-slug": "^5.1.0",
"rehype-stringify": "^9.0.3",
"remark": "^14.0.2",
"remark-html": "^15.0.1",
Expand Down
16 changes: 8 additions & 8 deletions src/components/organisms/SiteBanner/SiteBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,41 +130,41 @@ export function SiteBanner({ className }) {
<p css={subtitleCss}>
Software Engineer and Manager specializing in Web Applicaton development.
</p>
<a
<Link
href="mailto:angusp@angusp.com"
aria-label="Email angusp@angusp.com"
title="Email"
css={emailCss}
>
angusp@angusp.com
</a>
</Link>
<div css={profileLinksListCss}>
<a
<Link
href="https://github.com/anguspiv"
aria-label="Github Profile"
title="Github Profile"
css={profileLinkCss}
>
<FontAwesomeIcon icon={faGithub} />
</a>
</Link>

<a
<Link
href="https://twitter.com/angusp"
aria-label="Twitter Profile"
title="Twitter Profile"
css={profileLinkCss}
>
<FontAwesomeIcon icon={faTwitter} mask={faCircle} transform="shrink-6" />
</a>
</Link>

<a
<Link
href="https://www.linkedin.com/in/aperkerson"
aria-label="LinkedIn Profile"
title="LinkedIn Profile"
css={profileLinkCss}
>
<FontAwesomeIcon icon={faLinkedinIn} mask={faCircle} transform="shrink-6" />
</a>
</Link>
</div>
<nav role="navigation" aria-label="Main">
<ul css={menuCss}>
Expand Down
28 changes: 17 additions & 11 deletions src/lib/markdownToHtml.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { createElement, Fragment } from 'react';
import ReactDOMServer from 'react-dom/server';
import { createElement } from 'react';
import { unified } from 'unified';
import parse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeReact from 'rehype-react';
import stringify from 'rehype-stringify';
import rehype from 'remark-rehype';
import react from 'rehype-react';
import slug from 'rehype-slug';
import { Link } from '@components/atoms/Link';
import { Divider } from '@components/atoms/Divider';

export async function markdownToHtml(markdown) {
const result = unified()
const file = unified()
.use(parse)
.use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeReact, {
.use(rehype)
.use(slug)
.use(react, {
createElement,
Fragment,
a: Link,
components: {
a: Link,
hr: Divider,
},
})
.use(stringify)
.processSync(markdown);

return result.toString();
const string = ReactDOMServer.renderToStaticMarkup(file.result);

return string;
}

export default markdownToHtml;

1 comment on commit 930265e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.