Skip to content

Commit

Permalink
add markdown converter
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-jedrusiak committed Oct 10, 2024
1 parent fcc84ce commit 601383b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* `yarn` is now called directly through `subprocess.run()`. This should resolve some problems in Windows. `pynpm` dependency has been removed.
* Added `customCode` and `customFunctions` arguments for direct javascript use. Also added `getJS()` helper to get the code from a file.
* Now markdown and html in questions are honored by default.
13 changes: 13 additions & 0 deletions velesresearch/website_template/src/SurveyComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { json } from "./survey.js";
import * as SurveyCore from "survey-core";
import { nouislider } from "surveyjs-widgets";
import "nouislider/distribute/nouislider.css";
import { Converter } from "showdown";
import * as config from "./config.js";
import CSRFToken from "./csrf.js";
import registerCustomFunctions from "./customExpressionFunctions.js";
Expand Down Expand Up @@ -127,6 +128,18 @@ function SurveyComponent() {
document.body.style.setProperty("--sjs-general-backcolor-dim", document.getElementsByClassName("sd-root-modern")[0].style.getPropertyValue("--sjs-general-backcolor-dim"));
});

// Markdown formatting
const converter = new Converter();
survey.onTextMarkdown.add(function (survey, options) {
// Convert Markdown to HTML
let str = converter.makeHtml(options.text);
// Remove root paragraphs <p></p>
str = str.substring(3);
str = str.substring(0, str.length - 4);
// Set HTML markup to render
options.html = str;
});

// {% customCode %}

// placeholder
Expand Down

0 comments on commit 601383b

Please sign in to comment.