Pipe through all the files and insert the title and link instead of the placeholders.
188222
function(config, stream, extras, callback) {
    stream = stream.pipe(through.obj(function(file, enc, cb) {

      var contents = file.contents.toString();
      var changed = false;

      if(file.prev) {
        changed = true;
        file.prev.$el = file.prev.$el || cheerio.load(file.prev.contents.toString());
        var title = file.prev.$el('h1').first().text();
        contents = contents.replace(/MBINSERTPREVLABEL/g, title);
        var href = path.relative(path.dirname(file.relative), file.prev.relative);
        contents = contents.replace(/MBINSERTPREVHREF/g, href);
      }

      if(file.next) {
        changed = true;
        file.next.$el = file.next.$el || cheerio.load(file.next.contents.toString());
        var title = file.next.$el('h1').first().text();
        contents = contents.replace(/MBINSERTNEXTLABEL/g, title);
        var href = path.relative(path.dirname(file.relative), file.next.relative);
        contents = contents.replace(/MBINSERTNEXTHREF/g, href);
      }

      if(changed) {
        file.contents = new Buffer(contents);
        file.$el = undefined;
      }

      cb(null, file);

    }));
    callback(null, config, stream, extras);
  }
1272422
def add_file(self, file, filename):
        
        self.files['_{}'.format(filename)] = (filename, file)
20615
def integrate_to_file(what, filename, start_line, end_line):
    

    try:
        with open(filename) as f:
            lines = f.readlines()
    except IOError:
        lines = []

    tmp_file = tempfile.NamedTemporaryFile(delete=False)

    lines.reverse()

    # first copy before start line
    while lines:
        line = lines.pop()

        if line == start_line:
            break

        tmp_file.write(line)

    # insert content
    tmp_file.write(start_line)
    tmp_file.write(what)
    tmp_file.write(end_line)

    # skip until end line
    while lines:
        line = lines.pop()

        if line == end_line:
            break

    # copy rest
    tmp_file.writelines(lines)
    tmp_file.close()

    os.rename(tmp_file.name, filename)
225400
def expand_includes(text, path='.'):
    """"""
    def read_and_expand(match):
        filename = match.group('filename')
        filename = join(path, filename)
        text = read(filename)
        return expand_includes(
            text, path=join(path, dirname(filename)))

    return re.sub(r'^\.\. include:: (?P<filename>.*)$',
                  read_and_expand,
                  text,
                  flags=re.MULTILINE)
1115017
def addAttachment(self, title, attachment):
        
        self._attachments[title] = attachment
        self.resizeToContents()
1158215
function replaceLinkWithEmbedded(node, index, parent, vFile) {
  const { title, url, position } = node;
  let newNode;

  // If the node isn't mermaid, ignore it.
  if (!isMermaid(title)) {
    return node;
  }

  try {
    const value = fs.readFileSync(`${vFile.dirname}/${url}`, { encoding: 'utf-8' });

    newNode = createMermaidDiv(value);
    parent.children.splice(index, 1, newNode);
    vFile.info('mermaid link replaced with div', position, PLUGIN_NAME);
  } catch (error) {
    vFile.message(error, position, PLUGIN_NAME);
    return node;
  }

  return node;
}
894012
def add_string_as_file(self, content, filename, pred=None):
        """"""

        # Generate summary string for logging
        summary = content.splitlines()[0] if content else ''
        if not isinstance(summary, six.string_types):
            summary = content.decode('utf8', 'ignore')

        if not self.test_predicate(cmd=False, pred=pred):
            self._log_info("skipped string ...'%s' due to predicate (%s)" %
                           (summary, self.get_predicate(pred=pred)))
            return

        self.copy_strings.append((content, filename))
        self._log_debug("added string ...'%s' as '%s'" % (summary, filename))
1105077
def attach_files(self, files: Sequence[AttachedFile]):
        '''
        
        '''
        assert not self._content, 'content must be empty to attach files.'
        self.content_type = 'multipart/form-data'
        self._attached_files = files
327140
def insert_line_in_file_after_regex(path, line, after_regex, use_sudo=False):
    

    tmpfile = str(uuid.uuid4())
    get_file(path, tmpfile, use_sudo=use_sudo)
    with open(tmpfile) as f:
        original = f.read()

    if line not in original:
        outfile = str(uuid.uuid4())
        with open(outfile, 'w') as output:
            for l in original.split('\n'):
                output.write(l + '\n')
                if re.match(after_regex, l) is not None:
                    output.write(line + '\n')

        upload_file(local_path=outfile,
                    remote_path=path,
                    use_sudo=use_sudo)
        os.unlink(outfile)
    os.unlink(tmpfile)
297060
def add_file(self, filename, overwrite=False):
        

        with open(filename, 'r') as fin:
            self.add(fin.read(), overwrite)
313850
function replaceStringsInFile(name, rootDir, replacements) {
  return findFirstFile(name, rootDir)
  .then(function (path) {
    return fs.readFileAsync(path, 'utf8')
    .then(function (content) {
      return replaceContent(path, content, replacements);
    })
    .then(function (content) {
      return fs.writeFileAsync(path, content, 'utf8');
    });

  })
  .catch(function (error) {
    console.error(
      'we couldn\'t replace strings in file, error: \'%s\', stack: \'%s\'',
      error.toString(), error.stack
    );
    return Promise.reject(error);
  });
}
918780
def add(self, files, items):
        
        if isinstance(files, (str, bytes)):
            files = iter([files])
        for pathname in files:
            try:
                values = self._filemap[pathname]
            except KeyError:
                self._filemap[pathname] = items
            else:
                values.extend(items)
639341
function renameLinks (files)
{
  if (originalFiles.length <= 0)
  {
    if (debug)
      console.log("No links to rename.");
    return;
  }

  files.forEach(function (file)
  {
    // Read the file
    data = fs.readFileSync(file, 'ascii');

    // Find/replace the file names that were renamed
    for (var i = 0; i < originalFiles.length; i++)
    {
      var findString = '/' + originalFiles[i] + '\"';
      var replaceString = '/' + renamedFiles[i] + '\"';

      data = data.replace(findString, replaceString);
    }

    // Write back
    fs.writeFile(file, data, 'ascii', function (err) {
      if (err)
        throw err;
    });

    if (debug)
      console.log('Renamed links in: %s', file);
  });
}
1268577
def _expand_filename(self, line):
        """"""
        # expand .
        newline = line
        path = os.getcwd()
        if newline.startswith("."):
            newline = newline.replace(".", path, 1)
        # expand ~
        newline = os.path.expanduser(newline)
        return newline
164520
def add_find_links(self, urls):
        """"""
        for url in urls:
            if (
                self.to_scan is None  # if we have already "gone online"
                or not URL_SCHEME(url)  # or it's a local file/directory
                or url.startswith('file:')
                or list(distros_for_url(url))  # or a direct package link
            ):
                # then go ahead and process it now
                self.scan_url(url)
            else:
                # otherwise, defer retrieval till later
                self.to_scan.append(url)
150768
def insert_attachments(self, volumeID, attachments):
        '''  '''
        log.debug("adding new attachments to volume '{}': {}".format(volumeID, attachments))
        if not attachments:
            return
        rawVolume = self._req_raw_volume(volumeID)
        attsID = list()
        for index, a in enumerate(attachments):
            try:
                rawAttachment = self._assemble_attachment(a['file'], a)
                rawVolume['_source']['_attachments'].append(rawAttachment)
                attsID.append(rawAttachment['id'])
            except Exception:
                log.exception("Error while elaborating attachments array at index: {}".format(index))
                raise
        self._db.modify_book(volumeID, rawVolume['_source'], version=rawVolume['_version'])
        return attsID
798447
def insert_text(self,
	                text,
	                fname,
	                pattern=None,
	                expect=None,
	                shutit_pexpect_child=None,
	                before=False,
	                force=False,
	                note=None,
	                replace=False,
	                line_oriented=True,
	                create=True,
	                loglevel=logging.DEBUG):
		""""""
		shutit_global.shutit_global_object.yield_to_draw()
		return self.change_text(text=text,
		                        fname=fname,
		                        pattern=pattern,
		                        expect=expect,
		                        shutit_pexpect_child=shutit_pexpect_child,
		                        before=before,
		                        force=force,
		                        note=note,
		                        line_oriented=line_oriented,
		                        create=create,
		                        replace=replace,
		                        delete=False,
		                        loglevel=loglevel)