HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/current/node_modules/@frctl/fractal/src/core/markdown.js
"use strict";

const marked = require("marked");
const _ = require("lodash");
const highlighter = require("./highlighter");
const renderer = new marked.Renderer();

renderer.code = function(code, lang, escaped) {
  const output = highlighter(code, lang);
  if (output != null) {
    code = output;
  }
  if (!lang) {
    return `<pre><code>${code}</code></pre>`;
  }
  return `<pre><code class="${this.options.langPrefix}${escape(
    lang,
    true
  )}">${code}</code></pre>`;
};

/*
 * Export the markdown parser.
 */

module.exports = function markdown(content, mdConfig) {
  mdConfig = _.cloneDeep(mdConfig && _.isObject(mdConfig) ? mdConfig : {});
  mdConfig.renderer = renderer;

  return marked(_.toString(content), mdConfig);
};

module.exports.toc = function(content, maxDepth, mdConfig) {
  maxDepth = maxDepth || 6;
  mdConfig = mdConfig && _.isObject(mdConfig) ? mdConfig : {};
  mdConfig.renderer = renderer;

  const tokens = marked.lexer(_.toString(content));

  return tokens
    .filter(token => {
      return token.type === "heading" && token.depth <= maxDepth;
    })
    .map(token => {
      token.id = token.text.toLowerCase().replace(/[^\w]+/g, "-");
      return token;
    });
};