Convert Markdown to HTML with Marked

Edit in →

Marked is a lightweight and extensible JavaScript library for converting Markdown to HTML. This library allows you to add Markdown support to survey JSON schemas. This example shows how to integrate Marked with SurveyJS Form Library.

To enable Markdown support, implement a function that handles the onTextMarkdown event. The function's second parameter, options, has the text property that contains a string value with Markdown content. Pass this value to the Marked converter to get HTML markup. Note that the converter wraps the passed Markdown string into an unnecessary paragraph (<p> tag). Remove this tag and assign the result to the options.html property.

The Marked library supports HTML tags in the source. However, this feature is considered unsafe because the converter allows any HTML markup to pass through, even if it contains malicious code. To ensure that the resulting HTML markup is safe, it must be processed through a sanitizer. This demo does not use any third-party sanitizer, as the SurveyJS Form Library includes basic sanitizing capabilities. However, these capabilities do not guarantee 100% protection against malicious code injections. We highly recommend using a dedicated sanitizing library in production code.

Markdown provides rich formatting capabilities that can be extended if required. For example, this demo allows you to specify image sizes next to the image URL in a survey JSON schema. See the code examples for further details.

Your cookie settings

We use cookies on our site to make your browsing experience more convenient and personal. In some cases, they are essential to making the site work properly. By clicking "Accept All", you consent to the use of all cookies in accordance with our Terms of Use & Privacy Statement. However, you may visit "Cookie settings" to provide a controlled consent.

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.