Survey.StylesManager.applyTheme("modern");
var json = {
"elements": [
{
"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(sender) {
document.querySelector('#surveyResult').textContent =
"Result JSON:\n" + JSON.stringify(sender.data, null, 3);
});
//Make Marked support specifying image size in pixels
const renderer = {
image: function (src, title, alt) {
const exec = /=\s*(\d*)\s*x\s*(\d*)\s*$/.exec(title);
let res = '<img src="' + src + '" alt="' + alt;
if (exec && exec[1]) res += '" height="' + exec[1];
if (exec && exec[2]) res += '" width="' + exec[2];
return res + '">';
},
};
marked.use({ renderer });
survey.onTextMarkdown.add(function (survey, options) {
//convert the markdown text to html
var str = marked.marked(options.text);
// remove root paragraphs <p></p>
str = str.substring(3);
str = str.substring(0, str.length - 5);
// set html
options.html = str;
});
$("#surveyElement").Survey({
model: survey
});
<!DOCTYPE html>
<html lang="en">
<head>
<title>Markdown Radiogroup (Marked), jQuery Survey Library Example</title>
<meta name="viewport" content="width=device-width" />
<script src="https://unpkg.com/jquery"></script>
<script src="/DevBuilds/survey-jquery/survey.jquery.min.js"></script>
<link href="/DevBuilds/survey-core/modern.min.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="./index.css">
<script src="https://cdn.jsdelivr.net/npm/marked/marked.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>