src/lib/markbind/src/parser.js
function extractPageVariables(fileName, data, userDefinedVariables, includedVariables) {
  const $ = cheerio.load(data);
  const pageVariables = { };
  $('variable').each(function () {
    const variableElement = $(this);
    const variableName = variableElement.attr('name');
    if (!variableName) {
      // eslint-disable-next-line no-console
      console.warn(`Missing 'name' for variable in ${fileName}\n`);
      return;
    }
    if (!pageVariables[variableName]) {
      const variableValue
        = nunjucks.renderString(md.renderInline(variableElement.html()),
                                { ...pageVariables, ...userDefinedVariables, ...includedVariables });
      pageVariables[variableName] = variableValue;
      if (!VARIABLE_LOOKUP[fileName]) {
        VARIABLE_LOOKUP[fileName] = {};
      }
      VARIABLE_LOOKUP[fileName][variableName] = variableValue;
    }
  });
  return pageVariables;
}
function extractPageVariables(fileName, data, userDefinedVariables, includedVariables) {
  const $ = cheerio.load(data);
  const pageVariables = { };
  $('variable').each(function () {
    const variableElement = $(this);
    const variableName = variableElement.attr('name');
    if (!variableName) {
      // eslint-disable-next-line no-console
      console.warn(`Missing 'name' for variable in ${fileName}\n`);
      return;
    }
    if (!pageVariables[variableName]) {
      const variableValue
        = nunjucks.renderString(md.renderInline(variableElement.html()),
                                { ...pageVariables, ...userDefinedVariables, ...includedVariables });
      pageVariables[variableName] = variableValue;
      if (!VARIABLE_LOOKUP[fileName]) {
        VARIABLE_LOOKUP[fileName] = {};
      }
      VARIABLE_LOOKUP[fileName][variableName] = variableValue;
    }
  });
  return pageVariables;
}
function extractPageVariables ( fileName , data , userDefinedVariables , includedVariables ) { const $ = cheerio . load ( data ) ; const pageVariables = { } ; $ ( 'variable' ) . each ( function ( ) { const variableElement = $ ( this ) ; const variableName = variableElement . attr ( 'name' ) ; if ( ! variableName ) { // eslint-disable-next-line no-console console . warn ( ` ${ fileName } \n ` ) ; return ; } if ( ! pageVariables [ variableName ] ) { const variableValue = nunjucks . renderString ( md . renderInline ( variableElement . html ( ) ) , { ... pageVariables , ... userDefinedVariables , ... includedVariables } ) ; pageVariables [ variableName ] = variableValue ; if ( ! VARIABLE_LOOKUP [ fileName ] ) { VARIABLE_LOOKUP [ fileName ] = { } ; } VARIABLE_LOOKUP [ fileName ] [ variableName ] = variableValue ; } } ) ; return pageVariables ; }
Extract page variables from a page
@param filename for error printing
@param data to extract variables from
@param userDefinedVariables global variables
@param includedVariables variables from parent include
Extract page variables from a page