rehype-sanitize has different output than github #159
-
From readme:
Example:
output github: |
Beta Was this translation helpful? Give feedback.
Answered by
ChristianMurphy
Nov 16, 2023
Replies: 1 comment 12 replies
-
Hey @RARgames! 👋 rehype-santize does behave as GitHub does. source from sandbox// ⚠️ Important! Please make sure the dependencies are up to date.
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeRaw from 'rehype-raw';
import rehypeSanitize from 'rehype-sanitize';
import rehypeStringify from 'rehype-stringify';
const sourceMarkdown = `
<!-- test --> 123
<!-- test --> 456 <!-- test -->
`;
try {
document.querySelector<HTMLPreElement>('#source')!.textContent =
sourceMarkdown;
const file = await unified()
.use(remarkParse)
// Add any remark plugins here
.use(remarkRehype, { allowDangerousHtml: true })
// Add any rehype plugins here
.use(rehypeRaw)
.use(rehypeSanitize)
.use(rehypeStringify)
.process(sourceMarkdown);
document.querySelector<HTMLIFrameElement>(
'#result'
)!.contentWindow!.document.body.innerHTML = String(file);
document.querySelector<HTMLPreElement>('#error')!.textContent = '';
} catch (error) {
document.querySelector<HTMLPreElement>('#error')!.textContent = String(error);
} |
Beta Was this translation helpful? Give feedback.
12 replies
Answer selected by
RARgames
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @RARgames! 👋
Sorry you ran into some confusion.
rehype-santize does behave as GitHub does.
Make sure you have your remark and rehype configuration setup correctly.
A working example for reference: https://stackblitz.com/edit/github-ozn1qm?file=src%2Fmain.ts
source from sandbox