feat: enable iframe rendering in markdown code block (#2799)

* enable iframe rendering in code block

* fix eslint issue
This commit is contained in:
Mark Zhao 2024-01-19 22:36:45 -05:00 committed by GitHub
parent 196facfacd
commit bd1cf62761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,16 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
const formatedLanguage = language.toLowerCase() || "plaintext";
let highlightedCode = hljs.highlightAuto(content).value;
// Users can set Markdown code blocks as 'iframe'
// to embed videos or external audio links from services like Apple Music or Spotify.
if (formatedLanguage === "iframe") {
const renderHTML = () => {
return { __html: content };
};
return <div className="mx-auto w-11/12 !my-4" dangerouslySetInnerHTML={renderHTML()} />;
}
try {
const temp = hljs.highlight(content, {
language: formatedLanguage,