Replace all include statements with the respective file contents.

        :param markdown_file_path: Path to curently processed Markdown file
        :param content: Markdown content

        :returns: Markdown content with resolved includes
547688
def process_includes(self, markdown_file_path: Path, content: str) -> str:
        '''
        '''

        markdown_file_path = markdown_file_path.resolve()

        self.logger.debug(f'Processing Markdown file: {markdown_file_path}')

        processed_content = ''

        include_statement_pattern = re.compile(
            rf'((?<!\<)\<{"|".join(self.tags)}(?:\s[^\<\>]*)?\>.*?\<\/{"|".join(self.tags)}\>)',
            flags=re.DOTALL
        )

        content_parts = include_statement_pattern.split(content)

        for content_part in content_parts:
            include_statement = self.pattern.fullmatch(content_part)

            if include_statement:
                body = self._tag_body_pattern.match(include_statement.group('body').strip())
                options = self.get_options(include_statement.group('options'))

                self.logger.debug(f'Processing include statement; body: {body}, options: {options}')

                if body.group('repo'):
                    repo = body.group('repo')
                    repo_from_alias = self.options['aliases'].get(repo)

                    revision = None

                    if repo_from_alias:
                        self.logger.debug(f'Alias found: {repo}, resolved as: {repo_from_alias}')

                        if '#' in repo_from_alias:
                            repo_url, revision = repo_from_alias.split('#', maxsplit=1)

                        else:
                            repo_url = repo_from_alias

                    else:
                        repo_url = repo

                    if body.group('revision'):
                        revision = body.group('revision')

                        self.logger.debug(f'Highest priority revision specified in the include statement: {revision}')

                    self.logger.debug(f'File in Git repository referenced; URL: {repo_url}, revision: {revision}')

                    repo_path = self._sync_repo(repo_url, revision)

                    self.logger.debug(f'Local path of the repo: {repo_path}')

                    included_file_path = repo_path / body.group('path')

                    self.logger.debug(f'Resolved path to the included file: {included_file_path}')

                    processed_content_part = self._process_include(
                        included_file_path,
                        body.group('from_heading'),
                        body.group('to_heading'),
                        options
                    )

                else:
                    self.logger.debug('Local file referenced')

                    included_file_path = self._get_included_file_path(body.group('path'), markdown_file_path)

                    self.logger.debug(f'Resolved path to the included file: {included_file_path}')

                    processed_content_part = self._process_include(
                        included_file_path,
                        body.group('from_heading'),
                        body.group('to_heading'),
                        options
                    )

                if self.options['recursive'] and self.pattern.search(processed_content_part):
                    self.logger.debug('Recursive call of include statements processing')

                    processed_content_part = self.process_includes(included_file_path, processed_content_part)

                if options.get('inline'):
                    self.logger.debug('Processing included content part as inline')

                    processed_content_part = re.sub(r'\s+', ' ', processed_content_part).strip()

            else:
                processed_content_part = content_part

            processed_content += processed_content_part

        return processed_content
385900
function (contents, workingDir) {
			var matches = includePattern.exec(contents);

			while (matches) {
				var match = matches[0];
				var includePath = resolveIncludePath(matches[1], workingDir);

				grunt.log.debug('Including', includePath);

				var includeContents = grunt.file.read(includePath);
				includeContents = include(includeContents, path.dirname(includePath));
				contents = contents.replace(match, includeContents);

				matches = includePattern.exec(contents);

				numIncludes++;
			}

			return contents;
		}
580185
def contents(self, path):
        
        try:
            out, code, err = self.command_exec(['cat-file', '-p', self.ref_head+':'+path])
            if not code:
                return out.decode('utf-8')
        except Exception:
            pass

        return None
600762
def write_markdown_to_file(self, f):
    
    print("---", file=f)
    print("---", file=f)
    print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f)
    print("", file=f)
    # TODO(touts): Do not insert these.  Let the doc writer put them in
    # the module docstring explicitly.
    print("#", self._title, file=f)
    if self._prefix:
      print(self._prefix, file=f)
    print("[TOC]", file=f)
    print("", file=f)
    if self._module is not None:
      self._write_module_markdown_to_file(f, self._module)
582928
function include(path) {
	var path = publish.conf.templatesDir+path;
	return IO.readFile(path);
}
190583
function processSourceFile(work_directory, file_path) {

    var path = create('fs.path', work_directory).combine(file_path),
        source = create('fs.filereader(utf8)', path).readSync();

    // replace /*#include filename.ext*/
    var result = source.replace(/\/\*#include \S+\*\//gm, function(line) {
        var include_file_path = /\/\*#include (\S+)\*\//.exec(line)[1];
        // list .js file
        watch_list.push(include_file_path);
        // recursively perform substitutions
        return processSourceFile(path.getParentPath().path, include_file_path);
    });

    return result;
}
415531
function processContent(target, opt, tagsRegExp, listOfFiles) {
	let targetContent = String(target.contents);
	const targetPath = target.path;
	const files = extractFilePaths(targetContent, targetPath, opt, tagsRegExp);

	// recursively process files
	files.forEach(function (fileData) {
		if (listOfFiles.indexOf(fileData.file.path) !== -1) {
			throw error("Circular definition found. File: " + fileData.file.path + " referenced in a child file.");
		}
		listOfFiles.push(fileData.file.path);
		const content = processContent(fileData.file, opt, tagsRegExp, listOfFiles);
		listOfFiles.pop();

		targetContent = inject(targetContent, String(content), opt, fileData.tags);
	});
	if (listOfFiles.length === 1 && !opt.quiet && files.length) {
		log(
			colors.cyan(files.length.toString()) +
			' partials injected into ' +
			colors.magenta(targetPath) +
			'.');
	}
	return new Buffer.from(targetContent);
}
19479
def include_file(self, uri, **kwargs):
        """"""

        _include_file(self.context, uri, self._templateuri, **kwargs)
812998
def merge_includes(code):
    """"""

    pattern = '\#\s*include\s*"(?P<filename>[a-zA-Z0-9\_\-\.\/]+)"'
    regex = re.compile(pattern)
    includes = []

    def replace(match):
        filename = match.group("filename")

        if filename not in includes:
            includes.append(filename)
            path = glsl.find(filename)
            if not path:
                logger.critical('"%s" not found' % filename)
                raise RuntimeError("File not found", filename)
            text = '\n// --- start of "%s" ---\n' % filename
            with open(path) as fh:
                text += fh.read()
            text += '// --- end of "%s" ---\n' % filename
            return text
        return ''

    # Limit recursion to depth 10
    for i in range(10):
        if re.search(regex, code):
            code = re.sub(regex, replace, code)
        else:
            break

    return code
1270927
def markdown(*args, &block)
      filter(Rake::Pipeline::Web::Filters::MarkdownFilter, *args, &block)
    end
898501
static function findFileToInclude($file_path, &$new_file_path, &$rel_to_include = "")
    {
        // First look in path of current file
        static $_path_array = null;
        if (__DIR__) {
            $selfdir = dirname(__DIR__);
            $new_file_path = $selfdir . "/" . $file_path;
            $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler", 0);
            if (@file_exists($new_file_path) || is_dir($new_file_path)) {
                $new_file_path = $selfdir . "/" . $file_path;
                $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler");
                return true;
            }
            $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler");
        }

        // else look in incude path
        if (!isset($_path_array)) {
            $_ini_include_path = get_include_path();

            if (defined("__DIR __")) {
                $selfdir = dirname(__DIR__);
            } else {
                $selfdir = dirname(dirname(__FILE__));
            }

            if (strstr($_ini_include_path, ';')) {
                $_ini_include_path = $selfdir . ";" . $_ini_include_path;
                $_path_array = explode(';', $_ini_include_path);
            } else {
                $_ini_include_path = $selfdir . ":" . $_ini_include_path;
                $_path_array = explode(':', $_ini_include_path);
            }
        }
        // Turn off Error handling for the following to avoid open_basedir errors
        $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler", 0);
        foreach ($_path_array as $_include_path) {
            if (@file_exists($_include_path . "/" . $file_path)) {
                $new_file_path = $_include_path . "/" . $file_path;
                $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler");
                return true;
            }
        }
        $old_error_handler = set_error_handler("Reportico\Engine\ReporticoApp::ErrorHandler");

        $new_file_path = $file_path;
        return false;
    }
793776
def get_includes(self, path):
        
        config = self.file_index.unfold_yaml(path)

        return self.get_includes_from_dict(config, extract=True)
1164071
def _check_and_handle_includes(self, from_file):
        
        logger.debug("Check/handle includes from %s", from_file)
        try:
            paths = self._parser.get("INCLUDE", "paths")
        except (config_parser.NoSectionError,
                config_parser.NoOptionError) as exc:
            logger.debug("_check_and_handle_includes: EXCEPTION: %s", exc)
            return
        paths_lines = [p.strip() for p in paths.split("\n")]
        logger.debug("paths = %s (wanted just once; CLEARING)", paths_lines)
        self._parser.remove_option("INCLUDE", "paths")
        for f in paths_lines:
            abspath = (f if os.path.isabs(f) else
                       os.path.abspath(
                           os.path.join(os.path.dirname(from_file), f)))
            use_path = os.path.normpath(abspath)
            if use_path in self._parsed_files:
                raise RecursionInConfigFile("In %s: %s already read",
                                            from_file, use_path)
            self._parsed_files.append(use_path)
            self._handle_rc_file(use_path)
105806
def do_include(self, t):
        
        t = self.resolve_include(t)
        include_file = self.find_include_file(t)
        if include_file:
            #print("include_file =", include_file)
            self.result.append(include_file)
            contents = self.read_file(include_file)
            new_tuples = [('scons_current_file', include_file)] + \
                         self.tupleize(contents) + \
                         [('scons_current_file', self.current_file)]
            self.tuples[:] = new_tuples + self.tuples
1260936
def get_compiled_file_content(path)
      begin
        Tilt.new(path.to_s).render({}, {
          :spec => spec
        })
      rescue RuntimeError
        File.read(path)
      end
    end
157070
def render_text(path, cp):
    

    # define filename and slug from path
    filename = os.path.basename(path)
    slug = filename.replace('.', '_')

    # initializations
    content = None

    # read file as a string
    with codecs.open(path, 'r', encoding='utf-8', errors='replace') as fp:
        content = fp.read()

    # replace all the escaped characters
    content = unescape(content, unescape_table)

    # render template
    template_dir = pycbc.results.__path__[0] + '/templates/files'
    env = Environment(loader=FileSystemLoader(template_dir))
    env.globals.update(abs=abs)
    env.globals.update(path_exists=os.path.exists)
    template = env.get_template('file_pre.html')
    context = {'filename' : filename,
               'slug'     : slug,
               'cp'       : cp,
               'content'  : content}
    output = template.render(context)

    return output
428131
def include_file(_parent, indent)
      return unless accept :include

      # Process data
      name = accept :line_feed || ''
      name.strip!

      # Check if there is any string after the include input
      Logger.error :parse, @code, @i, @j, :include_end if name.empty?

      # Get the complete file path based on the current file being compiled
      include_path = File.expand_path name, File.dirname(@file[-1][0])

      # Try to see if it has any existing extension, otherwise add .op
      include_path += Settings::FILE_EXTENSION if File.extname(name).empty?

      # Throw an error if the file doesn't exist
      unless Dir[include_path].any?
        Logger.error :parse, @code, @i, @j, :include, name
      end

      # include entire directory tree
      Dir[include_path].each do |file|
        # Skip current file when including from same directory
        next if file == @file[-1][0]

        @file << [include_path, indent]

        # Throw an error if the file doesn't exist
        if File.directory? file
          Logger.error :parse, @code, @i, @j, :include_dir, file
        end

        # Throw an error if the file doesn't exist
        unless File.file? file
          Logger.error :parse, @code, @i, @j, :include, file
        end

        # Indent all lines and prepare them for the parser
        lines = indent_lines File.read(file), ' ' * indent
        lines << ' '

        # Indent all the output lines with the current indentation
        @code.insert @i + 1, *lines.lines
      end

      true
    end