diff --git a/lib/static.js b/lib/static.js index bf07a0e..d4b1506 100644 --- a/lib/static.js +++ b/lib/static.js @@ -3,7 +3,7 @@ const fs = require('fs-extra'); const path = require('path'); const _ = require('lodash'); const { getOptions, getAssetsDir, getPath, getStaticDir, getSlideOptions, getFilesGlob } = require('./config'); -const { isDirectory, isFile, parseYamlFrontMatter, getFilePaths, isAbsoluteURL } = require('./util'); +const { md, isDirectory, isFile, parseYamlFrontMatter, getFilePaths, isAbsoluteURL } = require('./util'); const { revealBasePath, highlightThemePath } = require('./constants'); const { renderFile } = require('./render'); const { renderListFile } = require('./listing'); @@ -11,7 +11,6 @@ const featuredSlide = require('./featured-slide'); const files = new Set(); -const mdImageRE = /!\[[^\]]*\]\((.*?)\s*(["'](?:.*[^"'])["'])?\s*\)/g; const htmlImageRE = //g; const relativeDir = (from, to) => path.relative(from, to).replace(/^\.\./, '.'); @@ -63,13 +62,14 @@ const copyAssetsAndWriteFile = async (sourceDir, file, targetDir) => { const awaits = await copyAssetsFromOptions(markdown); const base = relativeDir(file, '.'); const markup = await renderFile(path.join(sourceDir, file), { base }); - let image; - while ((image = mdImageRE.exec(markdown) || htmlImageRE.exec(markdown))) { + let image; + const html = md.marked(markdown.toString()); + while (image = htmlImageRE.exec(html)) { const [, imgPath] = image; if (!isAbsoluteURL(imgPath)) { const relPath = path.join(path.dirname(file), imgPath); - awaits.push(cp(path.join(sourceDir, relPath), path.join(targetDir, relPath))); + awaits.push(cp(path.join(sourceDir, relPath), path.join(targetDir, relPath)).catch((err) => console.warn(err))); } }