scripts/doc-generator/create_documentation_page.js
/**
 * Convert Markdown to HTML.
 * @param {string} data - Markdown to convert
 * @param {string} inputDir - Directory the Markdown file is in.
 * Can be used to copy image/video/audio files.
 * @param {string} outputDir - Directory the HTML file will be in.
 * Can be used to copy image/video/audio files.
 * @param {Function|null|undefined} linkTranslator - Allow to translate links
 * from markdown to HTML. Is given the orginal link in the markdown and should
 * return the converted link.
 * If null or undefined, the links won't be converted.
 * @returns {string}
 */
Convert Markdown to HTML.
@param {string} data - Markdown to convert
@param {string} inputDir - Directory the Markdown file is in.
Can be used to copy image/video/audio files.
@param {string} outputDir - Directory the HTML file will be in.
Can be used to copy image/video/audio files.
@param {Function|null|undefined} linkTranslator - Allow to translate links
from markdown to HTML. Is given the orginal link in the markdown and should
return the converted link.
If null or undefined, the links won't be converted.
@returns {string}
Convert Markdown to HTML . @param { string } data - Markdown to convert @param { string } inputDir - Directory the Markdown file is in . Can be used to copy image / video / audio files . @param { string } outputDir - Directory the HTML file will be in . Can be used to copy image / video / audio files . @param { Function|null|undefined } linkTranslator - Allow to translate links from markdown to HTML . Is given the orginal link in the markdown and should return the converted link . If null or undefined the links won ' t be converted . @returns { string }
async function parseMD(data, inputDir, outputDir, linkTranslator) {
  const $ = cheerio.load(convertMDToHTML(data));
  if (linkTranslator) {
    $("a").each((_, elem) => {
      const href = $(elem).attr("href");
      if (typeof href === "string") {
        $(elem).attr("href", linkTranslator(href));
      }
    });
  }
  const imgTags = $("img").toArray();
  for (let i = 0; i < imgTags.length; i++) {
    await updateMediaTag($(imgTags[i]), inputDir, outputDir);
  }
  const audioTags = $("audio").toArray();
  for (let i = 0; i < audioTags.length; i++) {
    await updateMediaTag($(audioTags[i]), inputDir, outputDir);
  }
  const videoTags = $("video").toArray();
  for (let i = 0; i < videoTags.length; i++) {
    await updateMediaTag($(videoTags[i]), inputDir, outputDir);
  }
  return $.html();
}
async function parseMD ( data , inputDir , outputDir , linkTranslator ) { const $ = cheerio . load ( convertMDToHTML ( data ) ) ; if ( linkTranslator ) { $ ( "a" ) . each ( ( _ , elem ) => { const href = $ ( elem ) . attr ( "href" ) ; if ( typeof href === "string" ) { $ ( elem ) . attr ( "href" , linkTranslator ( href ) ) ; } } ) ; } const imgTags = $ ( "img" ) . toArray ( ) ; for ( let i = 0 ; i < imgTags . length ; i ++ ) { await updateMediaTag ( $ ( imgTags [ i ] ) , inputDir , outputDir ) ; } const audioTags = $ ( "audio" ) . toArray ( ) ; for ( let i = 0 ; i < audioTags . length ; i ++ ) { await updateMediaTag ( $ ( audioTags [ i ] ) , inputDir , outputDir ) ; } const videoTags = $ ( "video" ) . toArray ( ) ; for ( let i = 0 ; i < videoTags . length ; i ++ ) { await updateMediaTag ( $ ( videoTags [ i ] ) , inputDir , outputDir ) ; } return $ . html ( ) ; }
Convert Markdown to HTML.
Convert Markdown to HTML .
// TODO I don't understand Cheerio/Jquery here, that's plain ugly // use markdown-it plugin instead?