(fullMarkdown, extraOptions = {})
| 38 | * @returns {string} The rendered HTML compatible with reveal.js |
| 39 | */ |
| 40 | export 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 | |
| 83 | export const renderFile = async (filePath, extraOptions) => { |
| 84 | try { |
no test coverage detected