text
stringlengths
0
828
if options.get('sethead'):
if options['sethead'] > 0:
result = self._shift_headings(
result,
options['sethead'] - from_heading_level
)
return result"
1481,"def _adjust_image_paths(self, content: str, md_file_path: Path) -> str:
'''Locate images referenced in a Markdown string and replace their paths
with the absolute ones.
:param content: Markdown content
:param md_file_path: Path to the Markdown file containing the content
:returns: Markdown content with absolute image paths
'''
def _sub(image):
image_caption = image.group('caption')
image_path = md_file_path.parent / Path(image.group('path'))
self.logger.debug(
f'Updating image reference; user specified path: {image.group(""path"")}, ' +
f'absolute path: {image_path}, caption: {image_caption}'
)
return f'![{image_caption}]({image_path.absolute().as_posix()})'
return self._image_pattern.sub(_sub, content)"
1482,"def _get_src_file_path(self, markdown_file_path: Path) -> Path:
'''Translate the path of Markdown file that is located inside the temporary working directory
into the path of the corresponding Markdown file that is located inside the source directory
of Foliant project.
:param markdown_file_path: Path to Markdown file that is located inside the temporary working directory
:returns: Mapping of Markdown file path to the source directory
'''
path_relative_to_working_dir = markdown_file_path.relative_to(self.working_dir.resolve())
self.logger.debug(
'Currently processed Markdown file path relative to working dir: ' +
f'{path_relative_to_working_dir}'
)
path_mapped_to_src_dir = (
self.project_path.resolve() /
self.config['src_dir'] /
path_relative_to_working_dir
)
self.logger.debug(
'Currently processed Markdown file path mapped to source dir: ' +
f'{path_mapped_to_src_dir}'
)
return path_mapped_to_src_dir"
1483,"def _get_included_file_path(self, user_specified_path: str, current_processed_file_path: Path) -> Path:
'''Resolve user specified path to the local included file.
:param user_specified_path: User specified string that represents
the path to a local file
:param current_processed_file_path: Path to the currently processed Markdown file
that contains include statements
:returns: Local path of the included file relative to the currently processed Markdown file
'''
self.logger.debug(f'Currently processed Markdown file: {current_processed_file_path}')
included_file_path = (current_processed_file_path.parent / user_specified_path).resolve()
self.logger.debug(f'User-specified included file path: {included_file_path}')
if (
self.working_dir.resolve() in current_processed_file_path.parents
and
self.working_dir.resolve() not in included_file_path.parents
):
self.logger.debug(
'Currently processed file is located inside the working dir, ' +
'but included file is located outside the working dir. ' +
'So currently processed file path should be rewritten with the path of corresponding file ' +
'that is located inside the source dir'
)
included_file_path = (
self._get_src_file_path(current_processed_file_path).parent / user_specified_path
).resolve()
else:
self.logger.debug(
'Using these paths without changes'
)
self.logger.debug(f'Finally, included file path: {included_file_path}')