packages/remark-cq/index.js
function codeImportBlock(eat, value, silent) {
  var index = -1;
  var length = value.length + 1;
  var subvalue = EMPTY;
  var character;
  var marker;
  var markerCount;
  var queue;

  // eat initial spacing
  while (++index < length) {
    character = value.charAt(index);

    if (character !== C_TAB && character !== C_SPACE) {
      break;
    }

    subvalue += character;
  }

  if (value.charAt(index) !== "<") {
    return;
  }

  // require <<
  if (value.charAt(index + 1) !== "<") {
    return;
  }

  marker = character;
  subvalue += character;
  markerCount = 1;
  queue = EMPTY;

  while (++index < length) {
    character = value.charAt(index);

    if (character !== C_RIGHT_PAREN) {
      markerCount++;
      subvalue += queue + character;
      queue = EMPTY;
    } else if (character === C_RIGHT_PAREN) {
      subvalue += queue + C_RIGHT_PAREN;
      break;
    }
  }

  var match = /^(<<.*?)\s*$/m.exec(subvalue);
  if (!match) return;

  var fileMatches = /<<\[(.*)\]\((.*)\)/.exec(match[0]);
  var statedFilename = fileMatches[1];
  var actualFilename = fileMatches[2];

  var cqOpts = {
    ...__options
  };
  if (__lastBlockAttributes["undent"]) {
    cqOpts.undent = true;
  }
  if (__lastBlockAttributes["root"]) {
    cqOpts.root = __lastBlockAttributes["root"];
  }
  if (__lastBlockAttributes["meta"]) {
    cqOpts.meta = __lastBlockAttributes["meta"];
  }

  let newNode = {
    type: "cq",
    lang: null,
    statedFilename,
    actualFilename,
    query: null,
    cropStartLine: null,
    cropEndLine: null,
    options: cqOpts
  };

  if (__lastBlockAttributes["lang"]) {
    newNode.lang = __lastBlockAttributes["lang"].toLowerCase();
  }

  if (__lastBlockAttributes["crop-query"]) {
    newNode.query = __lastBlockAttributes["crop-query"];
  }

  if (__lastBlockAttributes["crop-start-line"]) {
    newNode.cropStartLine = parseInt(__lastBlockAttributes["crop-start-line"]);
  }

  if (__lastBlockAttributes["crop-end-line"]) {
    newNode.cropEndLine = parseInt(__lastBlockAttributes["crop-end-line"]);
  }

  // meta: `{ info=string filename="foo/bar/baz.js" githubUrl="https://github.com/foo/bar"}`
  return eat(subvalue)(newNode);
}
function codeImportBlock(eat, value, silent) {
  var index = -1;
  var length = value.length + 1;
  var subvalue = EMPTY;
  var character;
  var marker;
  var markerCount;
  var queue;

  // eat initial spacing
  while (++index < length) {
    character = value.charAt(index);

    if (character !== C_TAB && character !== C_SPACE) {
      break;
    }

    subvalue += character;
  }

  if (value.charAt(index) !== "<") {
    return;
  }

  // require <<
  if (value.charAt(index + 1) !== "<") {
    return;
  }

  marker = character;
  subvalue += character;
  markerCount = 1;
  queue = EMPTY;

  while (++index < length) {
    character = value.charAt(index);

    if (character !== C_RIGHT_PAREN) {
      markerCount++;
      subvalue += queue + character;
      queue = EMPTY;
    } else if (character === C_RIGHT_PAREN) {
      subvalue += queue + C_RIGHT_PAREN;
      break;
    }
  }

  var match = /^(<<.*?)\s*$/m.exec(subvalue);
  if (!match) return;

  var fileMatches = /<<\[(.*)\]\((.*)\)/.exec(match[0]);
  var statedFilename = fileMatches[1];
  var actualFilename = fileMatches[2];

  var cqOpts = {
    ...__options
  };
  if (__lastBlockAttributes["undent"]) {
    cqOpts.undent = true;
  }
  if (__lastBlockAttributes["root"]) {
    cqOpts.root = __lastBlockAttributes["root"];
  }
  if (__lastBlockAttributes["meta"]) {
    cqOpts.meta = __lastBlockAttributes["meta"];
  }

  let newNode = {
    type: "cq",
    lang: null,
    statedFilename,
    actualFilename,
    query: null,
    cropStartLine: null,
    cropEndLine: null,
    options: cqOpts
  };

  if (__lastBlockAttributes["lang"]) {
    newNode.lang = __lastBlockAttributes["lang"].toLowerCase();
  }

  if (__lastBlockAttributes["crop-query"]) {
    newNode.query = __lastBlockAttributes["crop-query"];
  }

  if (__lastBlockAttributes["crop-start-line"]) {
    newNode.cropStartLine = parseInt(__lastBlockAttributes["crop-start-line"]);
  }

  if (__lastBlockAttributes["crop-end-line"]) {
    newNode.cropEndLine = parseInt(__lastBlockAttributes["crop-end-line"]);
  }

  // meta: `{ info=string filename="foo/bar/baz.js" githubUrl="https://github.com/foo/bar"}`
  return eat(subvalue)(newNode);
}
function codeImportBlock ( eat , value , silent ) { var index = - 1 ; var length = value . length + 1 ; var subvalue = EMPTY ; var character ; var marker ; var markerCount ; var queue ; // eat initial spacing while ( ++ index < length ) { character = value . charAt ( index ) ; if ( character !== C_TAB && character !== C_SPACE ) { break ; } subvalue += character ; } if ( value . charAt ( index ) !== "<" ) { return ; } // require << if ( value . charAt ( index + 1 ) !== "<" ) { return ; } marker = character ; subvalue += character ; markerCount = 1 ; queue = EMPTY ; while ( ++ index < length ) { character = value . charAt ( index ) ; if ( character !== C_RIGHT_PAREN ) { markerCount ++ ; subvalue += queue + character ; queue = EMPTY ; } else if ( character === C_RIGHT_PAREN ) { subvalue += queue + C_RIGHT_PAREN ; break ; } } var match = / ^(<<.*?)\s*$ / m . exec ( subvalue ) ; if ( ! match ) return ; var fileMatches = / <<\[(.*)\]\((.*)\) / . exec ( match [ 0 ] ) ; var statedFilename = fileMatches [ 1 ] ; var actualFilename = fileMatches [ 2 ] ; var cqOpts = { ... __options } ; if ( __lastBlockAttributes [ "undent" ] ) { cqOpts . undent = true ; } if ( __lastBlockAttributes [ "root" ] ) { cqOpts . root = __lastBlockAttributes [ "root" ] ; } if ( __lastBlockAttributes [ "meta" ] ) { cqOpts . meta = __lastBlockAttributes [ "meta" ] ; } let newNode = { type : "cq" , lang : null , statedFilename , actualFilename , query : null , cropStartLine : null , cropEndLine : null , options : cqOpts } ; if ( __lastBlockAttributes [ "lang" ] ) { newNode . lang = __lastBlockAttributes [ "lang" ] . toLowerCase ( ) ; } if ( __lastBlockAttributes [ "crop-query" ] ) { newNode . query = __lastBlockAttributes [ "crop-query" ] ; } if ( __lastBlockAttributes [ "crop-start-line" ] ) { newNode . cropStartLine = parseInt ( __lastBlockAttributes [ "crop-start-line" ] ) ; } if ( __lastBlockAttributes [ "crop-end-line" ] ) { newNode . cropEndLine = parseInt ( __lastBlockAttributes [ "crop-end-line" ] ) ; } // meta: `{ info=string filename="foo/bar/baz.js" githubUrl="https://github.com/foo/bar"}` return eat ( subvalue ) ( newNode ) ; }
Tokenize a code import

@example
codeImportBlock(eat, '\n<<[my-file.js](my-file.js)');

@property {Function} locator - Mention locator.
@param {function(string)} eat - Eater.
@param {string} value - Rest of content.
@param {boolean?} [silent] - Whether this is a dry run.
@return {Node?|boolean} - `delete` node.
Tokenize a code import