Skip to content

Commit

Permalink
feat: mdx callouts
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed Feb 29, 2024
1 parent a37c2eb commit 664dfc0
Show file tree
Hide file tree
Showing 6 changed files with 1,021 additions and 6,403 deletions.
42 changes: 0 additions & 42 deletions components/Callout/index.jsx

This file was deleted.

33 changes: 33 additions & 0 deletions components/Callout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as React from 'react';

interface Props extends React.PropsWithChildren<React.HTMLAttributes<HTMLQuoteElement>> {
attributes: {};
icon: string;
theme: string;
heading?: React.ReactElement;
}

const Callout = (props: Props) => {
const { attributes, theme, icon, heading } = props;

return (
// @ts-ignore
<blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
{heading && (
<h3 className={`callout-heading${heading ? '' : ' empty'}`}>
<span className="callout-icon">{icon}</span>
{heading}
</h3>
)}
{props.children}
</blockquote>
);
};

Callout.sanitize = sanitizeSchema => {
sanitizeSchema.attributes['rdme-callout'] = ['icon', 'theme', 'heading'];

return sanitizeSchema;
};

export default Callout;
4 changes: 3 additions & 1 deletion index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ export const html = (text: string, opts = {}) => {
};

export const mdast = (text: string, opts = {}) => {
const processor = unified().use(remark).use(calloutTransformer);
const processor = remark().use(remarkMdx);

try {
console.log(processor.parse('wtf'));
const tree = processor.parse(text);
return processor.runSync(tree);
} catch (e) {
console.log(e);
return { type: 'root', children: [] };
}
};
Expand Down
Loading

0 comments on commit 664dfc0

Please sign in to comment.