UNPKG

1.98 kBSource Map (JSON)View Raw
1{"version":3,"file":"markdown-service.umd.js","sources":["../src/markdown-service.js"],"sourcesContent":["import fetch from 'node-fetch'\nimport { marked } from 'marked'\n\nconst regExp = /^(-{3}(?:\\n|\\r)([\\w\\W]+?)(?:\\n|\\r)-{3})?([\\w\\W]*)*/\n\nfunction convertMarkdownResponse (response) {\n const contentType = response.headers.get('Content-Type')\n if (contentType.includes('text')) return response.text()\n}\n\nfunction getMarkdownFrontMatter (metas) {\n return metas.split('\\n').reduce((acc, meta) => {\n const [key, value] = meta.trim().split(': ', 2)\n const schema = { [key]: value.slice(1, -1) }\n return { ...acc, ...schema }\n }, {})\n}\n\nfunction formatMarkdownResponseToHtml (data) {\n if (!data) return null\n\n const { 2: metas, 3: body } = regExp.exec(data)\n const content = body ? marked(body) : null\n const head = metas ? getMarkdownFrontMatter(metas) : null\n\n return { head, content }\n}\n\nexport default function markdownService (url) {\n if (!url) return null\n\n return fetch(url)\n .then(convertMarkdownResponse)\n .then(formatMarkdownResponseToHtml)\n .catch(() => null)\n}\n"],"names":["regExp","convertMarkdownResponse","response","headers","get","includes","text","data","metas","body","exec","content","marked","head","split","reduce","acc","meta","key","value","trim","slice","getMarkdownFrontMatter","markdownService","url","fetch","then","formatMarkdownResponseToHtml","catch"],"mappings":"wZAGA,MAAMA,EAAS,qDAEf,SAAAC,EAAkCC,GAEhC,GADoBA,EAASC,QAAQC,IAAI,gBACzBC,SAAS,QAAS,OAAeH,EAACI,OAWpD,WAAuCC,GACrC,IAAKA,EAAM,OAAO,KAElB,MAAQ,EAAGC,EAAO,EAAGC,GAAST,EAAOU,KAAKH,GACpCI,EAAUF,EAAOG,EAAMA,OAACH,GAAQ,KAC5BI,EAAGL,EAbf,SAAiCA,GAC/B,SAAaM,MAAM,MAAMC,OAAO,CAACC,EAAKC,KACpC,MAAOC,EAAKC,GAASF,EAAKG,OAAON,MAAM,KAAM,GAE7C,MAAO,IAAKE,EADKE,CAACA,GAAMC,EAAME,MAAM,GAAI,KAEvC,IAQkBC,CAAuBd,GAAS,KAErD,MAAO,CAAEK,OAAMF,kBAGOY,SAAiBC,GACvC,OAAKA,EAEEC,EAAAA,QAAMD,GACVE,KAAKzB,GACLyB,KAAKC,GACLC,MAAM,IAAM,MALE"}
\No newline at end of file