Question T9353
Visible to All Users

Markdown text showing html in "preview" tab

created 3 years ago (modified 3 years ago)

Hi,

I'm currently using some markdown text in my Survey Creator, which incorporates some HTML tags. This works fine on the "Designer" tab, and the tags do not show. However, if I switch to the "Preview" tab, the HTML tags are displayed, when I expect them not to be, similar to the "Designer" view.

Here is an example to reproduce the issue: https://codesandbox.io/s/elastic-newton-szp66c?file=/src/SurveyCreatorComponent.jsx

In this example, you will see the first element of the json to have a span tag. On the "Designer" tab, this doesn't show, however, you can see the tag if you switch to the "Preview" tab.

Is this a bug?

Answers approved by surveyjs Support

created 3 years ago

Hello Mo,
Here is the correct code and the forked example:

JavaScript
const creatorOptions = {}; const onTextMarkdown = (survey, options) => { let str = marked.parse(options.text); str = str.substring(3); str = str.substring(0, str.length - 5); options.html = str; }; creator = new SurveyCreator.SurveyCreator(creatorOptions); creator.onSurveyInstanceCreated.add(function (sender, options) { //If we are creating a surface for designer surface if (options.reason === "designer") { options.survey.onTextMarkdown.add(onTextMarkdown); } //If we are creating a surface for "Test Survey" tab if (options.reason === "test") { options.survey.onTextMarkdown.add(onTextMarkdown); } });

Thank you,
Andrew
SurveyJS Team

    Show previous comments (4)

      Is there a way that we can stop this from happening? When we use the resultant Json, it is used with the resultant markdown which causes unexpected results.

        Hello,

        Sidebar shows title property as raw data. So, if you set title with HTML tags you will see the HTML tags in the sidebar title editor. If you don't want to see raw markdown or HTML code there, you need to use another type of editor for this property as it is done, for example, here: https://surveyjs.io/Examples/Survey-Creator?id=ckeditorpropertyeditor&platform=ReactjsV2&theme=defaultV2

        Thank you,
        Alex
        SurveyJS Team

          Hi Alex, thank you for the example. I'll have a look at it.