MCPcopy
hub / github.com/webpro/reveal-md / render

Function render

lib/render.js:40–81  ·  view source on GitHub ↗
(fullMarkdown, extraOptions = {})

Source from the content-addressed store, hash-verified

38 * @returns {string} The rendered HTML compatible with reveal.js
39 */
40export const render = async (fullMarkdown, extraOptions = {}) => {
41 const { yamlOptions, markdown: contentOnlyMarkdown } = parseYamlFrontMatter(fullMarkdown);
42 const options = Object.assign(getSlideOptions(yamlOptions), extraOptions);
43
44 const { title } = options;
45 const themeUrl = getThemeUrl(options.theme, options.assetsDir, options.base);
46 const highlightThemeUrl = getHighlightThemeUrl(options.highlightTheme);
47 const scriptPaths = getScriptPaths(options.scripts, options.assetsDir, options.base);
48 const cssPaths = getCssPaths(options.css, options.assetsDir, options.base);
49
50 const revealOptions = Object.assign({}, getRevealOptions(options.revealOptions), yamlOptions.revealOptions);
51
52 const slidifyOptions = _.pick(options, Object.keys(slidifyAttributeNames));
53 let slidifyAttributes = [];
54 for (const [key, value] of Object.entries(slidifyOptions)) {
55 const escaped_value = value.replace(/\n/g, '\\n').replace(/\r/g, '\\r');
56 slidifyAttributes.push(`${slidifyAttributeNames[key]}="${escaped_value}"`);
57 }
58
59 const preprocessorFn = await getPreprocessor(options.preprocessor);
60 const processedMarkdown = await preprocessorFn(contentOnlyMarkdown, options);
61
62 const revealOptionsStr = JSON.stringify(revealOptions);
63 const mermaidOptionsStr = options.mermaid === false ? undefined : JSON.stringify(options.mermaid);
64
65 const template = await getTemplate(options.template);
66 const context = Object.assign(options, {
67 title,
68 slidifyAttributes: slidifyAttributes.join(' '),
69 markdown: processedMarkdown,
70 themeUrl,
71 highlightThemeUrl,
72 scriptPaths,
73 cssPaths,
74 revealOptionsStr,
75 mermaidOptionsStr,
76 watch: getWatch()
77 });
78 const markup = Mustache.render(template, context);
79
80 return markup;
81};
82
83export const renderFile = async (filePath, extraOptions) => {
84 try {

Callers 2

render.spec.jsFile · 0.90
renderFileFunction · 0.85

Calls 10

parseYamlFrontMatterFunction · 0.90
getSlideOptionsFunction · 0.90
getThemeUrlFunction · 0.90
getHighlightThemeUrlFunction · 0.90
getScriptPathsFunction · 0.90
getCssPathsFunction · 0.90
getRevealOptionsFunction · 0.90
getPreprocessorFunction · 0.90
getTemplateFunction · 0.90
getWatchFunction · 0.90

Tested by

no test coverage detected