Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { getHighlightedCode } from "../../../../utils/highlightCode";
const HighlightCode = ({ children }: { children: string }): JSX.Element => {
try {
const { value, lang, meta } = JSON.parse(children);
return <code>{getHighlightedCode(value, lang, parseInt(meta))}</code>;
} catch (ex) {
return <code>{children}</code>;
}
};
const sanitize = {
...schema,
attributes: {
...schema.attributes,
a: [...schema.attributes.a, ["class", "ping ping-link"]],
},
};
const setCodeProps = (): ((ast: Node[]) => void) => {
return (ast: Node[]): void =>
visit(
ast,
"code",
(node: Node): void => {
const { lang, meta, value } = node;
node.value = JSON.stringify({ value, lang, meta });
}
);
};
const MarkdownContainer = styled("div")`
import visit from "unist-util-visit";
import { getHighlightedCode } from "../../../../utils/highlightCode";
const HighlightCode = ({ children }: { children: string }): JSX.Element => {
try {
const { value, lang, meta } = JSON.parse(children);
return <code>{getHighlightedCode(value, lang, parseInt(meta))}</code>;
} catch (ex) {
return <code>{children}</code>;
}
};
const sanitize = {
...schema,
attributes: {
...schema.attributes,
a: [...schema.attributes.a, ["class", "ping ping-link"]],
},
};
const setCodeProps = (): ((ast: Node[]) => void) => {
return (ast: Node[]): void =>
visit(
ast,
"code",
(node: Node): void => {
const { lang, meta, value } = node;
node.value = JSON.stringify({ value, lang, meta });
}
);
};
const remarkWithHighlighting = memoize(() => {
const schema = Object.assign({}, githubSchema, {
attributes: Object.assign({}, githubSchema.attributes, {
code: [...(githubSchema.attributes.code || []), 'className'],
}),
});
return remark()
.use(externalLinks)
.use(remarkReact, {
sanitize: schema,
remarkReactComponents: {
code: remarkLowlight({css, js, xml}),
},
});
});
const remarkWithHighlighting = memoize(() => {
const schema = Object.assign({}, githubSchema, {
attributes: Object.assign({}, githubSchema.attributes, {
code: [...(githubSchema.attributes.code || []), 'className'],
}),
});
return remark()
.use(externalLinks)
.use(remarkReact, {
sanitize: schema,
remarkReactComponents: {
code: remarkLowlight({css, js, xml}),
},
});
});