text
stringlengths
0
828
return included_file_path"
1484,"def _process_include(
self,
file_path: Path,
from_heading: str or None = None,
to_heading: str or None = None,
options={}
) -> str:
'''Replace a local include statement with the file content. Necessary
adjustments are applied to the content: cut between certain headings,
strip the top heading, set heading level.
:param file_path: Path to the included file
:param from_heading: Include starting from this heading
:param to_heading: Include up to this heading (not including the heading itself)
:param options: ``sethead``, ``nohead``
:returns: Included file content
'''
self.logger.debug(
f'Included file path: {file_path}, from heading: {from_heading}, ' +
f'to heading: {to_heading}, options: {options}'
)
if file_path.name.startswith('^'):
file_path = self._find_file(file_path.name[1:], file_path.parent)
with open(file_path, encoding='utf8') as incl_file:
incl_content = incl_file.read()
if from_heading:
incl_content = self._cut_from_heading_to_heading(
incl_content,
from_heading,
to_heading,
options
)
else:
incl_content = self._cut_to_heading(
incl_content,
to_heading,
options
)
incl_content = self._adjust_image_paths(incl_content, file_path)
return incl_content"
1485,"def process_includes(self, markdown_file_path: Path, content: str) -> str:
'''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
'''
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')