Question T13784
Visible to All Users

Markdown Link in Description

created 2 years ago

Hello,

I'm trying to display a link in the description of my survey in order for it to be available on each page. Unfortunately, Markdown support seems disabled for descriptions.

Other tickets I found regarding this seemed outdated, is there any simple solution to currently achieve this?

Thanks

Lucas

Clipboard-File-1.png

JSON
{ "title": "My Survey", "description": "In case of questions or issues: <a href=\"help@example.com\">help@example.com</a> [help@example.com](mailto:help@example.com)", "pages": [ { "name": "page1", "elements": [ { "type": "text", "name": "question1" } ] } ] }

Answers approved by surveyjs Support

created 2 years ago

Hello Lucas,
To enable Markdown in survey texts, register a Markdown converter (for instance, Showdown, Marked), and handle the onTextMarkdown event to convert a Markdown text to HTML. For an example of usage, refer to the following demos:

Please let me know if you have further questions.

    Other Answers

    created 2 years ago (modified 2 years ago)

    Hello Jane,

    Thanks for the links. Somehow I was under the impression that there was already Markdown support included in SurveyJS and just not activated for descriptions…

    Anyway I took the same approach, as in the examples linked, but with a different React library that I already had included in my project called markdown-to-jsx. In case anyone stumbles over this ticket, here's the code:

    TypeScript
    import { compiler } from "markdown-to-jsx"; import { renderToString } "react-dom/server"; model.onTextMarkdown.add((_, options) => { options.html = renderToString( // `wrapper: null` deactivates the default <span> wrapping // strings without markdown should therefore be mapped to themselves compiler(options.text, { wrapper: null }) ); });

    Thanks,

    Lucas

      Comments (1)

        Thank you for sharing this code, Lucas.

        Should you have any questions, please feel free to contact us at any time.