MCPcopy
hub / github.com/openupm/openupm / renderMarkdownToHtml

Function renderMarkdownToHtml

app/utils/markdown.js:87–113  ·  view source on GitHub ↗
({
  pkg,
  markdown,
  disableTitleParser,
})

Source from the content-addressed store, hash-verified

85
86// Render markdown for the given package context.
87const 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.
116const parseTitle = function({ pkg, markdown }) {

Callers 2

_fetchReadmeForLangFunction · 0.85

Calls 3

parseTitleFunction · 0.85
markedRendererFunction · 0.85
postProcessHtmlFunction · 0.85

Tested by

no test coverage detected