diff --git a/macao/assets/quiz.js b/macao/assets/quiz.js index f79d521a99d3d13706e3c4061b793cdb8766d3ef..4a0adb82f5f363d9a4a06e00200abdb962bd9850 100644 --- a/macao/assets/quiz.js +++ b/macao/assets/quiz.js @@ -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) }); diff --git a/macao/layouts/partials/docs/inject/head.html b/macao/layouts/partials/docs/inject/head.html index 28310c9c28aafad86fa90b84927b12de222b4be0..1d7dbd4e6824f06356b646e945f186efbf9fb1cc 100644 --- a/macao/layouts/partials/docs/inject/head.html +++ b/macao/layouts/partials/docs/inject/head.html @@ -9,6 +9,8 @@ <script defer type="text/javascript" src="https://unpkg.com/survey-core/themes/default-light-panelless.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" integrity="sha512-Evv84Mr4kqVGRNSgIGL/F/aIDqQb7xQ2vcrdIwxfjThSH8CSR7PBEakCr51Ck+w+/U6swU2Im1vVX0SVk9ABhg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> + <script src="https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.js"></script> + {{- $quizjs := slice -}} {{- $quizjs = $quizjs | append (resources.Get "quiz.js") -}} {{- $quizjs = $quizjs | append (resources.Get "custom.js") -}}