Skip to content

Commit

Permalink
sanitize generated SVGs
Browse files Browse the repository at this point in the history
  • Loading branch information
BearToCode committed Jul 23, 2023
1 parent 6137c30 commit 139575a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/plugin-tikz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ interface TikzExtensionOptions {
postProcess?: (elem: SVGElement) => void;
}

let sanitizer: ((html: string) => string) | undefined;

/**
* TikzJax extension for Carta.
* @param options Tikz options.
*/
export const tikz = (options?: TikzExtensionOptions): CartaExtension => {
return {
cartaRef: (carta) => (sanitizer = carta.options?.sanitizer),
shjRef: (shj) => {
import('./tikz').then((module) => shj.loadCustomLanguage('tikz', module));
},
Expand Down Expand Up @@ -84,7 +87,7 @@ const tikzTokenizer = (options?: TikzExtensionOptions): marked.TokenizerAndRende
class="tikz-generated ${options?.class ?? ''}"
tikz-generation="${currentGeneration}"
>
${html}
${sanitizer ? sanitizer(html) : html}
</div>
`;
}
Expand Down

0 comments on commit 139575a

Please sign in to comment.