({
pkg,
markdown,
disableTitleParser,
})
| 85 | |
| 86 | // Render markdown for the given package context. |
| 87 | const renderMarkdownToHtml = async function({ |
| 88 | pkg, |
| 89 | markdown, |
| 90 | disableTitleParser, |
| 91 | }) { |
| 92 | // Parse title |
| 93 | if (!disableTitleParser) { |
| 94 | markdown = parseTitle({ pkg, markdown }); |
| 95 | } |
| 96 | // Parse emoji |
| 97 | const replacer = (match) => emoji.emojify(match); |
| 98 | markdown = markdown.replace(/(:.*:)/g, replacer); |
| 99 | // Render markdown |
| 100 | const linkBaseUrl = urljoin(pkg.repoUrl, "blob/" + pkg.readmeBranch); |
| 101 | const linkBaseRelativeUrl = urljoin(pkg.repoUrl, "blob/" + pkg.readmeBase); |
| 102 | const imageBaseUrl = urljoin(pkg.repoUrl, "raw/" + pkg.readmeBranch); |
| 103 | const imageBaseRelativeUrl = urljoin(pkg.repoUrl, "raw/" + pkg.readmeBase); |
| 104 | const renderer = markedRenderer({ |
| 105 | linkBaseUrl, |
| 106 | linkBaseRelativeUrl, |
| 107 | imageBaseUrl, |
| 108 | imageBaseRelativeUrl, |
| 109 | }); |
| 110 | const html = marked.parse(markdown, { renderer }); |
| 111 | // post-processing |
| 112 | return postProcessHtml(html, { imageBaseRelativeUrl }); |
| 113 | }; |
| 114 | |
| 115 | // Parse markdown to add title line. |
| 116 | const parseTitle = function({ pkg, markdown }) { |
no test coverage detected