{"version":3,"sources":["markdown-to-text.ts"],"sourcesContent":["type Options = {\n\tstripListLeaders?: boolean;\n\tlistUnicodeChar: string | boolean;\n\tgfm?: boolean;\n\tuseImgAltText?: boolean;\n\tpreserveLinks?: boolean;\n  };\n  \n  /**\n   * @function removeMarkdown\n   *\n   * @description\n   * Parse the markdown and returns a string\n   *\n   * @param markdown - The markdown string to parse\n   * @param options - The options for the function\n   *\n   * @returns The parsed plain text\n   */\n  const removeMarkdown = (\n\tmarkdown: string,\n\toptions: Options = {\n\t  listUnicodeChar: \"\",\n\t}\n  ) => {\n\toptions = options || {};\n\toptions.listUnicodeChar = options.hasOwnProperty(\"listUnicodeChar\")\n\t  ? options.listUnicodeChar\n\t  : false;\n\toptions.stripListLeaders = options.hasOwnProperty(\"stripListLeaders\")\n\t  ? options.stripListLeaders\n\t  : true;\n\toptions.gfm = options.hasOwnProperty(\"gfm\") ? options.gfm : true;\n\toptions.useImgAltText = options.hasOwnProperty(\"useImgAltText\")\n\t  ? options.useImgAltText\n\t  : true;\n\toptions.preserveLinks = options.hasOwnProperty(\"preserveLinks\") ? options.preserveLinks : false;\n  \n\tlet output = markdown || \"\";\n  \n\t// Remove horizontal rules (stripListHeaders conflict with this rule, which is why it has been moved to the top)\n\toutput = output.replace(/^(-\\s*?|\\*\\s*?|_\\s*?){3,}\\s*$/gm, \"\");\n  \n\ttry {\n\t  if (options.stripListLeaders) {\n\t\tif (options.listUnicodeChar)\n\t\t  output = output.replace(\n\t\t\t/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm,\n\t\t\toptions.listUnicodeChar + \" $1\"\n\t\t  );\n\t\telse output = output.replace(/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm, \"$1\");\n\t  }\n\t  if (options.gfm) {\n\t\toutput = output\n\t\t  // Header\n\t\t  .replace(/\\n={2,}/g, \"\\n\")\n\t\t  // Fenced codeblocks\n\t\t  .replace(/~{3}.*\\n/g, \"\")\n\t\t  // Strikethrough\n\t\t  .replace(/~~/g, \"\")\n\t\t  // Fenced codeblocks\n\t\t  .replace(/`{3}.*\\n/g, \"\");\n\t  }\n\t  if(options.preserveLinks) {\n\t\t// Remove inline links while preserving the links\n\t\toutput = output.replace(/\\[(.*?)\\][\\[\\(](.*?)[\\]\\)]/g, \"$1 ($2)\")\n\t  }\n\t  output = output\n\t\t// Remove HTML tags\n\t\t.replace(/<[^>]*>/g, \"\")\n\t\t// Remove setext-style headers\n\t\t.replace(/^[=\\-]{2,}\\s*$/g, \"\")\n\t\t// Remove footnotes?\n\t\t.replace(/\\[\\^.+?\\](\\: .*?$)?/g, \"\")\n\t\t.replace(/\\s{0,2}\\[.*?\\]: .*?$/g, \"\")\n\t\t// Remove images\n\t\t.replace(/\\!\\[(.*?)\\][\\[\\(].*?[\\]\\)]/g, options.useImgAltText ? \"$1\" : \"\")\n\t\t// Remove inline links\n\t\t.replace(/\\[(.*?)\\][\\[\\(].*?[\\]\\)]/g, \"$1\")\n\t\t// Remove blockquotes\n\t\t.replace(/^\\s{0,3}>\\s?/g, \"\")\n\t\t.replace(/(^|\\n)\\s{0,3}>\\s?/g, \"\\n\\n\")\n\t\t// Remove reference-style links?\n\t\t.replace(/^\\s{1,2}\\[(.*?)\\]: (\\S+)( \".*?\")?\\s*$/g, \"\")\n\t\t// Remove atx-style headers\n\t\t.replace(\n\t\t  /^(\\n)?\\s{0,}#{1,6}\\s+| {0,}(\\n)?\\s{0,}#{0,} {0,}(\\n)?\\s{0,}$/gm,\n\t\t  \"$1$2$3\"\n\t\t)\n\t\t// Remove emphasis (repeat the line to remove double emphasis)\n\t\t.replace(/([\\*_]{1,3})(\\S.*?\\S{0,1})\\1/g, \"$2\")\n\t\t.replace(/([\\*_]{1,3})(\\S.*?\\S{0,1})\\1/g, \"$2\")\n\t\t// Remove code blocks\n\t\t.replace(/(`{3,})(.*?)\\1/gm, \"$2\")\n\t\t// Remove inline code\n\t\t.replace(/`(.+?)`/g, \"$1\")\n\t\t// Replace two or more newlines with exactly two? Not entirely sure this belongs here...\n\t\t.replace(/\\n{2,}/g, \"\\n\\n\");\n\t} catch (e) {\n\t  console.error(e);\n  \n\t  return markdown;\n\t}\n\treturn output;\n  };\n  \n  export default removeMarkdown;"],"names":["markdown","options","listUnicodeChar","hasOwnProperty","stripListLeaders","gfm","useImgAltText","preserveLinks","output","replace","e","console","error"],"mappings":"AA0GE,eAvFuB,CAAA,CACxBA,UACAC,UAAmB;IACjBC,iBAAiB;AACnB,CAAC;IAEDD,CAAAA,UAAUA,WAAW,CAAC,CAAA,EACdC,eAAe,GAAGD,EAAAA,QAAQE,cAAc,CAAC,sBAC7CF,QAAQC,eAAe,EAE3BD,QAAQG,gBAAgB,GAAGH,CAAAA,QAAQE,cAAc,CAAC,uBAC9CF,QAAQG,gBAAgB,EAE5BH,QAAQI,GAAG,GAAGJ,CAAAA,QAAQE,cAAc,CAAC,UAASF,QAAQI,GAAG,EACzDJ,QAAQK,aAAa,GAAGL,CAAAA,QAAQE,cAAc,CAAC,oBAC3CF,QAAQK,aAAa,EAEzBL,QAAQM,aAAa,GAAGN,EAAAA,QAAQE,cAAc,CAAC,oBAAmBF,QAAQM,aAAa;IAEvF,IAAIC,SAASR,YAAY;IAGzBQ,SAASA,OAAOC,OAAO,CAAC,mCAAmC;IAE3D,IAAI;QACER,QAAQG,gBAAgB,KAE3BI,SADEP,QAAQC,eAAe,GAChBM,OAAOC,OAAO,CACxB,mCACAR,QAAQC,eAAe,GAAG,SAEbM,OAAOC,OAAO,CAAC,mCAAmC,QAE3DR,QAAQI,GAAG,IAChBG,CAAAA,SAASA,OAENC,OAAO,CAAC,YAAY,MAEpBA,OAAO,CAAC,aAAa,IAErBA,OAAO,CAAC,OAAO,IAEfA,OAAO,CAAC,aAAa,GAAE,GAEtBR,QAAQM,aAAa,IAEzBC,CAAAA,SAASA,OAAOC,OAAO,CAAC,+BAA+B,UAAS,GAE/DD,SAASA,OAETC,OAAO,CAAC,YAAY,IAEpBA,OAAO,CAAC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