---
title: Markdown Support with markdown-it
product: Survey Creator
description: Learn how to integrate Markdown formatting into Survey Creator using the markdown-it library. Enable survey authors to format text with Markdown syntax to enhance the content of their forms. View this demo with Markdown formatting for JavaScript.
framework: Vanilla JS
source: https://surveyjs.io/survey-creator/examples/markdown-support-with-markdown-it/vanillajs
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Markdown Support with markdown-it (Vanilla JS)

Markdown is a simple, human-readable markup language designed to format plain text. For rendering on a web page, Markdown content needs to be converted to HTML. Survey Creator by SurveyJS supports Markdown via third-party Markdown-to-HTML JavaScript converters, such as <a href="https://github.com/markdown-it/markdown-it/tree/master#markdown-it-" target="_blank">`markdown-it`</a>. This demo shows how you can integrate `markdown-it` with Survey Creator to allow survey authors to format textual content within their surveys using <a href="https://www.markdownguide.org/cheat-sheet/" target="_blank">Markdown syntax</a>. 

## Access Internal Survey Instances

As Survey Creator is [built upon regular surveys from SurveyJS Form Library](https://surveyjs.io/survey-creator/documentation/property-grid-customization#add-custom-properties-to-the-property-grid), you need to access internal survey instances to process Markdown content. Handle `SurveyCreatorModel`'s [`onSurveyInstanceSetupHandlers`](https://surveyjs.io/survey-creator/documentation/api-reference/survey-creator#onSurveyInstanceSetupHandlers) event with a function. The function's `options.survey` parameter exposes one of the internal [`SurveyModel`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model) instances.

## Enable Markdown Support

To enable Markdown support in Survey Creator, implement a function that handles `SurveyModel`'s [`onTextMarkdown`](https://surveyjs.io/form-library/documentation/surveymodel#onTextMarkdown) event. The function's `options.text` parameter contains a string value with Markdown content. Pass this value to the `markdown-it` converter to get HTML markup. Assign the result to the `options.html` property.

> `markdown-it` can support HTML tags in the source if you enable the `html` property when instantiating the converter. 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.

## Integrate a Rich Text Editor

If you need advanced formatting capabilities (bullet points, numbered lists, hyperlinks, text alignment), you can integrate a rich content editor into Survey Creator. Refer to the following demo for more information:

[Integrate a Third-Party Rich Content Editor](/survey-creator/examples/form-builder-with-integrated-rich-text-editor/ (linkStyle))

## Files

### `public/index.html`

```html
<!-- Uncomment the following lines to enable Ace Editor in the JSON Editor tab -->
<!-- 
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ace.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ext-searchbox.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/theme-clouds_midnight.js"></script>
-->

<div id="surveyCreatorContainer" style="position: absolute; height: 100%; width: 100%"></div>
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/survey_json.js`

```js
export const surveyJSON = {
  "title": "*NPS Survey Question*",
  "pages": [
    {
      "name": "page1",
      "elements": [
        {
          "type": "rating",
          "name": "nps_score",
          "title": "*On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?*",
          "isRequired": true,
          "rateMin": 0,
          "rateMax": 10,
          "minRateDescription": "(Most unlikely)",
          "maxRateDescription": "(Most likely)"
        },
        {
          "type": "checkbox",
          "name": "promoter_features",
          "visibleIf": "{nps_score} >= 9",
          "title": "*Which of the following features do you value the most?*",
          "description": "**Please select no more than three features.**",
          "isRequired": true,
          "validators": [
            {
              "type": "answercount",
              "text": "Please select no more than three features.",
              "maxCount": 3
            }
          ],
          "showOtherItem": true,
          "choices": [
            "Performance",
            "Stability",
            "User interface",
            "Complete functionality",
            "Learning materials (documentation, demos, code examples)",
            "Quality support"
          ],
          "otherText": "Other features:",
          "colCount": 2
        },
        {
          "type": "comment",
          "name": "passive_experience",
          "visibleIf": "{nps_score} >= 7  and {nps_score} <= 8",
          "title": "*What can we do to make your experience more satisfying?*"
        },
        {
          "type": "comment",
          "name": "disappointing_experience",
          "visibleIf": "{nps_score} <= 6",
          "title": "*Please let us know why you had such a disappointing experience with our product*"
        }
      ]
    }
  ],
  "completedHtml": "<h3>Thank you for your feedback</h3>",
  "completedHtmlOnCondition": [
    {
      "expression": "{nps_score} >= 9",
      "html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you love our product. Your ideas and suggestions will help us make it even better.</h4>"
    },
    {
      "expression": "{nps_score} >= 6  and {nps_score} <= 8",
      "html": "<h3>Thank you for your feedback</h3> <h4>We are glad that you shared your ideas with us. They will help us make our product better.</h4>"
    }
  ]
};
```

### `src/index.js`

```js
import { SurveyCreator } from "survey-creator-js";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { surveyJSON } from "./survey_json";
import markdownit from "markdown-it";
import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";
import "./index.css";
import SurveyTheme from "survey-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

// Instantiate `markdown-it`
const converter = markdownit({
    html: true // Support HTML tags in the source (unsafe, see documentation)
});
const creator = new SurveyCreator();

creator.onSurveyInstanceSetupHandlers.add((_, options) => {
    options.survey.onTextMarkdown.add((_, options) => {
        if (!options.text) return;
        // 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;
    });
});

creator.JSON = surveyJSON;
creator.render("surveyCreatorContainer");
```

### `package.json`

```json
{
  "dependencies": {
    "markdown-it": "latest",
    "survey-core": "latest",
    "survey-js-ui": "latest",
    "survey-creator-core": "latest",
    "survey-creator-js": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/markdown-support-with-markdown-it/angular.md)
- [React](https://surveyjs.io/survey-creator/examples/markdown-support-with-markdown-it/reactjs.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/markdown-support-with-markdown-it/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/markdown-support-with-markdown-it/jquery.md)
