Survey.StylesManager.applyTheme("modern");
var json = { questions: [
{
"type": "radiogroup",
"hasOther": true,
"isRequired": true,
"name": "favoritePet",
"title": "What is your favorite pet  ?",
"choices": [
{
"value": "dog",
"text": "Dog: "
},
{
"value": "cat",
"text": "Cat: "
},
{
"value": "parrot",
"text": "Parrot "
}
]
}
]
};
window.survey = new Survey.Model(json);
survey.onComplete.add(function(result) {
document.querySelector('#surveyResult').textContent =
"Result JSON:\n" + JSON.stringify(result.data, null, 3);
});
//Create showdown markdown converter
var converter = new showdown.Converter();
survey.onTextMarkdown.add(function(survey, options){
//convert the markdown text to html
var str = converter.makeHtml(options.text);
//remove root paragraphs <p></p>
str = str.substring(3);
str = str.substring(0, str.length - 4);
//set html
options.html = str;
});
survey.render("surveyElement");
<!DOCTYPE html>
<html lang="en">
<head>
<title>Use markdown to render images in title and question elements, Knockoutjs Survey Library Example</title>
<meta name="viewport" content="width=device-width" />
<script src="https://unpkg.com/knockout@3.5.1/build/output/knockout-latest.js"></script>
<script src="/DevBuilds/survey-knockout/survey.ko.min.js"></script>
<link href="/DevBuilds/survey-knockout/modern.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="./index.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.6.4/showdown.min.js"></script>
</head>
<body>
<div id="surveyElement" style="display:inline-block;width:100%;">
</div>
<div id="surveyResult"></div>
<script type="text/javascript" src="./index.js"></script>
</body>
</html>
SurveyJS supports markdown via onTextMarkDown event. You may use any JavaScript markdown library. In this example, we are using Showdown markdown. You may use all features that this or other libraries have.