---
title: Markdown Support with Marked
product: Survey Creator
description: Learn how to enable Markdown support in your SurveyJS surveys and forms using the Marked library. Check out our demo for JavaScript to give it a try.
framework: React
source: https://surveyjs.io/survey-creator/examples/markdown-support-with-marked/reactjs
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Markdown Support with Marked (React)

<a href="https://marked.js.org/" target="_blank">Marked</a> is a JavaScript library used to convert Markdown to HTML. You can integrate this library with Survey Creator to let survey authors format question titles, descriptions, and other textual survey content using <a href="https://www.markdownguide.org/cheat-sheet/" target="_blank">Markdown syntax</a>. This example shows how to enable Markdown support in Survey Creator.

## 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, 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 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 SurveyJS 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/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/SurveyCreatorComponent.jsx`

```js
import React from "react";
import { SurveyCreator, SurveyCreatorComponent } from "survey-creator-react";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { surveyJSON } from "./survey_json";
import { marked } from "marked";
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

marked.use();
function SurveyCreatorRenderComponent() {
    const creator = new SurveyCreator();
    creator.onSurveyInstanceSetupHandlers.add((_, options) => {
        options.survey.onTextMarkdown.add((_, options) => {
            if (!options.text) return;
            // Convert Markdown to HTML
            let str = marked(options.text);
            // ...
            // Sanitize the HTML markup using a third-party library here
            // ...
            // Remove root paragraphs <p></p>
            str = str.substring(3);
            str = str.substring(0, str.length - 5);
            // Set HTML markup to render
            options.html = str;
        });
    });
    
    creator.JSON = surveyJSON;
    return (<SurveyCreatorComponent creator={creator} />);
}

export default SurveyCreatorRenderComponent;
```

### `src/index.css`

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

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyCreatorRenderComponent from "./SurveyCreatorComponent";

const root = createRoot(document.getElementById("surveyCreatorContainer"));
root.render(<SurveyCreatorRenderComponent />);
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "marked": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest",
    "survey-creator-core": "latest",
    "survey-creator-react": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/markdown-support-with-marked/angular.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/markdown-support-with-marked/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/markdown-support-with-marked/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/markdown-support-with-marked/vanillajs.md)
