Skip to content
Snippets Groups Projects
Commit 816b26f4 authored by Anthony's avatar Anthony
Browse files

Improve markdown translation in Survey

parent 75918eff
No related branches found
No related tags found
No related merge requests found
Pipeline #2008 canceled
......@@ -44,6 +44,22 @@ $(function () {
// Load survey model from JSON
const survey = new Survey.Model(jsonStatic);
// Instantiate `markdown-it`
const converter = markdownit({
html: true // Support HTML tags in the source (unsafe, see documentation)
});
survey.onTextMarkdown.add((_, options) => {
console.log("On text markdown")
// Convert Markdown to HTML
let str = converter.renderInline(options.text);
// ...
// Sanitize the HTML markup using a third-party library here
// ...
// Set HTML markup to render
options.html = str;
});
// Add "Check answers" button
survey.addNavigationItem({
id: "sv-nav-check",
......@@ -65,12 +81,6 @@ $(function () {
innerCss: "sd-btn nav-input"
});
survey.onTextMarkdown.add((survey, options) => {
// FIXME: this inserts raw HTML from the text, to remove as soon as Macao-Legacy converter
// can actually produce Markdown
options.html = options.text;
});
survey.onValueChanged.add((_, options) => {
console.log(options)
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment