@@ -2,6 +2,7 @@ import { Next, RenderOption } from ".";
22import MarkType from "../nodes/mark-type" ;
33import Node from "../nodes/node" ;
44import NodeType from "../nodes/node-type" ;
5+ import * as DOMPurify from 'dompurify' ;
56
67export const defaultNodeOption : RenderOption = {
78 [ NodeType . DOCUMENT ] :( node : Node ) => {
@@ -11,16 +12,19 @@ export const defaultNodeOption: RenderOption = {
1112 return `<p${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } >${ next ( node . children ) } </p>`
1213 } ,
1314 [ NodeType . LINK ] :( node : Node , next : Next ) => {
15+ const sanitizedHref = DOMPurify . sanitize ( node . attrs . href || node . attrs . url ) ;
1416 if ( node . attrs . target ) {
15- return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ node . attrs . href || node . attrs . url } " target="${ node . attrs . target } ">${ next ( node . children ) } </a>`
17+ return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ sanitizedHref } " target="${ node . attrs . target } ">${ next ( node . children ) } </a>`
1618 }
17- return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ node . attrs . href || node . attrs . url } ">${ next ( node . children ) } </a>`
19+ return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ sanitizedHref } ">${ next ( node . children ) } </a>`
1820 } ,
1921 [ NodeType . IMAGE ] :( node : Node , next : Next ) => {
20- return `<img${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ node . attrs . src || node . attrs . url } " />${ next ( node . children ) } `
22+ const sanitizedSrc = DOMPurify . sanitize ( node . attrs . src || node . attrs . url ) ;
23+ return `<img${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ sanitizedSrc } " />${ next ( node . children ) } `
2124 } ,
2225 [ NodeType . EMBED ] :( node : Node , next : Next ) => {
23- return `<iframe${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ node . attrs . src || node . attrs . url } ">${ next ( node . children ) } </iframe>`
26+ const sanitizedSrc = DOMPurify . sanitize ( node . attrs . src || node . attrs . url ) ;
27+ return `<iframe${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ sanitizedSrc } ">${ next ( node . children ) } </iframe>`
2428 } ,
2529 [ NodeType . HEADING_1 ] :( node : Node , next : Next ) => {
2630 return `<h1${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } >${ next ( node . children ) } </h1>`
@@ -84,8 +88,9 @@ export const defaultNodeOption: RenderOption = {
8488 } ,
8589
8690 [ 'reference' ] :( node : Node , next : Next ) => {
91+ const sanitizedAsset = DOMPurify . sanitize ( node . attrs [ 'asset-link' ] ) ;
8792 if ( node . attrs . type === 'asset' ) {
88- return `<img${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ node . attrs [ 'asset-link' ] } " />`
93+ return `<img${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs . class ? ` class="${ node . attrs . class } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } src="${ sanitizedAsset } " />`
8994 }
9095 return ``
9196 } ,
0 commit comments