-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'md-escape-curly-braces' into 'main'
Improve vue template variable handling in MDE See merge request reportcreator/reportcreator!484
- Loading branch information
Showing
6 changed files
with
126 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { htmlVoidElements } from 'html-void-elements' | ||
import { html } from 'property-information' | ||
import { stringifyEntities } from 'stringify-entities' | ||
import { handle } from '../node_modules/hast-util-to-html/lib/handle/index' | ||
import { all } from '../node_modules/hast-util-to-html/lib/index' | ||
|
||
|
||
export function rehypeStringify() { | ||
this.compiler = toHtml; | ||
} | ||
|
||
export function toHtml(tree) { | ||
const state = { | ||
one, | ||
all, | ||
settings: { | ||
// Required to pass-through vue template variables. | ||
// In preview mode, rehype-sanitize already removed dangerous HTML at this point. | ||
allowDangerousHtml: true, | ||
voids: htmlVoidElements, | ||
characterReferences: {}, | ||
|
||
}, | ||
schema: html, | ||
quote: '"', | ||
alternative: "'", | ||
} | ||
return state.one( | ||
Array.isArray(tree) ? {type: 'root', children: tree} : tree, | ||
undefined, | ||
undefined | ||
) | ||
} | ||
|
||
function one(node, index, parent) { | ||
return handleModified(node, index, parent, this); | ||
} | ||
|
||
function handleModified(node, index, parent, state) { | ||
if (node.type === 'text') { | ||
return text(node, index, parent, state); | ||
} | ||
return handle(node, index, parent, state); | ||
} | ||
|
||
export function text(node, _, parent, state) { | ||
// Check if content of `node` should be escaped. | ||
return parent && | ||
parent.type === 'element' && | ||
(parent.tagName === 'script' || parent.tagName === 'style') | ||
? node.value | ||
: stringifyEntities( | ||
node.value, | ||
Object.assign({}, state.settings.characterReferences, { | ||
subset: ['<', '&', '{', '}'] | ||
}) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters