src/lib/markbind/src/parser.js
function extractIncludeVariables(includeElement, contextVariables) {
  const includedVariables = { ...contextVariables };
  Object.keys(includeElement.attribs).forEach((attribute) => {
    if (!attribute.startsWith('var-')) {
      return;
    }
    const variableName = attribute.replace(/^var-/, '');
    if (!includedVariables[variableName]) {
      includedVariables[variableName] = includeElement.attribs[attribute];
    }
  });
  if (includeElement.children) {
    includeElement.children.forEach((child) => {
      if (child.name !== 'variable' && child.name !== 'span') {
        return;
      }
      const variableName = child.attribs.name || child.attribs.id;
      if (!variableName) {
        // eslint-disable-next-line no-console
        console.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n`
                   + `Missing 'name' or 'id' in variable for ${includeElement.attribs.src} include.`);
        return;
      }
      if (!includedVariables[variableName]) {
        includedVariables[variableName] = cheerio.html(child.children);
      }
    });
  }
  return includedVariables;
}
function extractIncludeVariables(includeElement, contextVariables) {
  const includedVariables = { ...contextVariables };
  Object.keys(includeElement.attribs).forEach((attribute) => {
    if (!attribute.startsWith('var-')) {
      return;
    }
    const variableName = attribute.replace(/^var-/, '');
    if (!includedVariables[variableName]) {
      includedVariables[variableName] = includeElement.attribs[attribute];
    }
  });
  if (includeElement.children) {
    includeElement.children.forEach((child) => {
      if (child.name !== 'variable' && child.name !== 'span') {
        return;
      }
      const variableName = child.attribs.name || child.attribs.id;
      if (!variableName) {
        // eslint-disable-next-line no-console
        console.warn(`Missing reference in ${includeElement.attribs[ATTRIB_CWF]}\n`
                   + `Missing 'name' or 'id' in variable for ${includeElement.attribs.src} include.`);
        return;
      }
      if (!includedVariables[variableName]) {
        includedVariables[variableName] = cheerio.html(child.children);
      }
    });
  }
  return includedVariables;
}
function extractIncludeVariables ( includeElement , contextVariables ) { const includedVariables = { ... contextVariables } ; Object . keys ( includeElement . attribs ) . forEach ( ( attribute ) => { if ( ! attribute . startsWith ( 'var-' ) ) { return ; } const variableName = attribute . replace ( / ^var- / , '' ) ; if ( ! includedVariables [ variableName ] ) { includedVariables [ variableName ] = includeElement . attribs [ attribute ] ; } } ) ; if ( includeElement . children ) { includeElement . children . forEach ( ( child ) => { if ( child . name !== 'variable' && child . name !== 'span' ) { return ; } const variableName = child . attribs . name || child . attribs . id ; if ( ! variableName ) { // eslint-disable-next-line no-console console . warn ( ` ${ includeElement . attribs [ ATTRIB_CWF ] } \n ` + ` ${ includeElement . attribs . src } ` ) ; return ; } if ( ! includedVariables [ variableName ] ) { includedVariables [ variableName ] = cheerio . html ( child . children ) ; } } ) ; } return includedVariables ; }
Extract variables from an include element
@param includeElement include element to extract variables from
@param contextVariables variables defined by parent pages
Extract variables from an include element