Skip to content

Commit

Permalink
render images in view
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jan 28, 2025
1 parent daefed2 commit 1e3f4e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
4 changes: 2 additions & 2 deletions packages/vscode/src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export async function createWebview(
const csp = `
default-src 'none';
frame-src ${cspUrl} ${cspSource} https:;
img-src ${cspUrl} ${cspSource} https:;
media-src ${cspUrl} ${cspSource} https:;
img-src ${cspUrl} ${cspSource} https: data:;
media-src ${cspUrl} ${cspSource} https: data:;
connect-src ${cspUrl} ${wsCspUrl};
script-src ${cspUrl} ${cspSource} 'nonce-${nonce}';
style-src 'unsafe-inline' ${cspUrl} ${cspSource};
Expand Down
73 changes: 36 additions & 37 deletions packages/web/src/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,37 @@ import { ErrorBoundary } from "react-error-boundary"
import rehypeHighlight from "rehype-highlight"
import Code from "./Code"

const genaiscriptSchema = Object.freeze({
...defaultSchema,
tagNames: [...defaultSchema.tagNames, "blockquote", "svg", "path"],
protocols: {
...defaultSchema.protocols,
src: ["http", "https", "data"],
},
attributes: {
...defaultSchema.attributes,
blockquote: [["className", /^markdown-./], /^aria-./],
p: [["className", /^markdown-./]],
svg: [
["className", "octicon", /^markdown-./],
"viewBox",
"width",
"height",
/^aria-./,
],
path: ["d", /^aria-./],
code: [
[
"className",
/^language-./,
/^aria-./,
"math-inline",
"math-display",
],
],
},
})

export default function Markdown(props: { className?: string; children: any }) {
const { className, children } = props
return children ? (
Expand All @@ -28,45 +59,13 @@ export default function Markdown(props: { className?: string; children: any }) {
return <Code {...props}>{children}</Code>
},
}}
urlTransform={url => {
console.log(url)
return url
}}
rehypePlugins={[
rehypeRaw,
[
rehypeSanitize,
{
...defaultSchema,
tagNames: [
...defaultSchema.tagNames,
"blockquote",
"svg",
"path",
],
attributes: {
...defaultSchema.attributes,
blockquote: [
["className", /^markdown-./],
/^aria-./,
],
p: [["className", /^markdown-./]],
svg: [
["className", "octicon", /^markdown-./],
"viewBox",
"width",
"height",
/^aria-./,
],
path: ["d", /^aria-./],
code: [
[
"className",
/^language-./,
/^aria-./,
"math-inline",
"math-display",
],
],
},
},
],
[rehypeSanitize, genaiscriptSchema],
rehypeMathML,
[rehypeHighlight, { ignoreMissing: true }],
]}
Expand Down

0 comments on commit 1e3f4e8

Please sign in to comment.