UNPKG

@subsocial/utils

Version:
32 lines (31 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mdToHtml = exports.mdToText = exports.buildMdToEntity = void 0; /* eslint-disable @typescript-eslint/no-var-requires */ const string_1 = require("./string"); const remark = require('remark'); const strip = require('strip-markdown'); const html = require('remark-html'); const remarkGfm = require('remark-gfm'); const processMdToText = remark() .use(strip) // .use(squeezeParagraphs) // <-- doesn't work very well: leaves couple sequential new lines .processSync; const buildMdToEntity = (processMd) => (md) => { if ((0, string_1.isEmptyStr)(md)) return md; return String(processMd(md)) // strip-markdown renders URLs as: // http&#x3A;//hello.com // so we need to fix this issue .replace(/&#x3A;/g, ':'); }; exports.buildMdToEntity = buildMdToEntity; /** Convert text in markdown format to plain text */ exports.mdToText = (0, exports.buildMdToEntity)(processMdToText); const processMdToHtml = remark() .use(remarkGfm) .use(html) .processSync; /** Convert text in markdown format to html text */ exports.mdToHtml = (0, exports.buildMdToEntity)(processMdToHtml);