{"version":3,"file":"AppMarkdownContent.vue.mjs","sources":["../../lib/datasetDetails/AppMarkdownContent.vue"],"sourcesContent":["/**\n * A component that renders sanitized Markdown formatted text.\n */\n\n<template>\n  <div class=\"markdown-container\">\n\n    <!-- Prepend content here -->\n    <slot name=\"before\" />\n\n    <!-- This slot provides for further customization using interpreted content -->\n    <slot :html=\"interpretedMarkdownText\">\n      <component\n        :is=\"tag\"\n        class=\"markdown-content\"\n        v-html=\"interpretedMarkdownText\"\n      />\n    </slot>\n\n    <!-- Append content here -->\n    <slot name=\"after\" />\n\n  </div>\n</template>\n\n<script>\n// For Markdown into HTML\nimport { marked } from 'marked';\n// For sanitizing HTML to prevent vulnerabilities\nimport DOMPurify from 'dompurify';\n\n// Set DOMPurify configuration.\n// Note: don't refactor this code into any lifecycle hook since this will cause\n// the configuration code each time this component is rendered.\n\n// General settings\nDOMPurify.setConfig({\n  // By using HTML profile, forbid SVG and MathML\n  USE_PROFILES: { html: true },\n  FORBID_TAGS: ['img'],\n  FORBID_ATTR: ['style', 'class'],\n});\n\n// Add a hook to transform every <h1> into <h2>\nDOMPurify.addHook('uponSanitizeElement', (node) => {\n  const { tagName } = node;\n  if (tagName && tagName.toLowerCase() === 'h1') {\n    const h2 = document.createElement('h2');\n    h2.innerHTML = node.innerHTML;\n\n    node.parentNode.replaceChild(h2, node);\n  }\n});\n\n// Add a hook to make all links open a new window\nDOMPurify.addHook('afterSanitizeAttributes', (node) => {\n  // set all elements owning target to target=_blank\n  if ('target' in node) {\n    node.setAttribute('target', '_blank');\n    // prevent https://www.owasp.org/index.php/Reverse_Tabnabbing\n    node.setAttribute('rel', 'noopener noreferrer');\n  }\n  // set non-HTML/MathML links to xlink:show=new\n  if (!node.hasAttribute('target')\n        && (node.hasAttribute('xlink:href')\n            || node.hasAttribute('href'))) {\n    node.setAttribute('xlink:show', 'new');\n  }\n});\n\nexport default {\n  name: 'AppMarkdownContent',\n  props: {\n    /**\n     * Tag of resulting markdown content container\n     */\n    tag: {\n      type: String,\n      default: 'div',\n    },\n    /**\n     * Input text to be interpreted\n     */\n    text: {\n      type: String,\n      default: '',\n    },\n  },\n  computed: {\n    interpretedMarkdownText() {\n      return DOMPurify.sanitize(\n        marked.parse(this.text.trim(), { smartLists: true }),\n      );\n    },\n  },\n};\n</script>\n\n<style scoped>\n\n.markdown-container {\n  word-wrap: break-word;\n}\n\n</style>\n"],"names":["DOMPurify","node","tagName","h2","_sfc_main","marked","_hoisted_1","_openBlock","_createElementBlock","_renderSlot","_ctx","$options","_createBlock","_resolveDynamicComponent","$props"],"mappings":";;;;;AAoCAA,EAAU,UAAU;AAAA;AAAA,EAElB,cAAc,EAAE,MAAM,GAAM;AAAA,EAC5B,aAAa,CAAC,KAAK;AAAA,EACnB,aAAa,CAAC,SAAS,OAAO;AAChC,CAAC;AAGDA,EAAU,QAAQ,uBAAuB,CAACC,MAAS;AACjD,QAAM,EAAE,SAAAC,EAAQ,IAAID;AACpB,MAAIC,KAAWA,EAAQ,YAAW,MAAO,MAAM;AAC7C,UAAMC,IAAK,SAAS,cAAc,IAAI;AACtC,IAAAA,EAAG,YAAYF,EAAK,WAEpBA,EAAK,WAAW,aAAaE,GAAIF,CAAI;AAAA,EACvC;AACF,CAAC;AAGDD,EAAU,QAAQ,2BAA2B,CAACC,MAAS;AAErD,EAAI,YAAYA,MACdA,EAAK,aAAa,UAAU,QAAQ,GAEpCA,EAAK,aAAa,OAAO,qBAAqB,IAG5C,CAACA,EAAK,aAAa,QAAQ,MACrBA,EAAK,aAAa,YAAY,KAC3BA,EAAK,aAAa,MAAM,MACnCA,EAAK,aAAa,cAAc,KAAK;AAEzC,CAAC;AAED,MAAKG,IAAU;AAAA,EACb,MAAM;AAAA,EACN,OAAO;AAAA;AAAA;AAAA;AAAA,IAIL,KAAK;AAAA,MACH,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AAAA;AAAA;AAAA;AAAA,IAID,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,SAAS;AAAA,IACV;AA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