markdown
Markdown processing utilities
The intended use case is for pre-formatting / correcting markdown headings that are not correctly formatted and/or are at the incorrect levels. The algorithm works in the following steps:
- Get a list of all chapter names from the source document.
- Identify the top-level headings.
- Increase the indent of all headings in the source document.
- Apply corrected headings.
- Run through TextProc/fix.
Classes
MarkdownProcessor
Attributes
Functions
build_heading_map
Returns a heading map of line numbers and heading texts from the source text.
Parameters:
-
source_text
(str
) –The markdown content as a string.
Returns:
-
Dict[int, str]
–Dict[int, str]: A dictionary where the keys are line numbers and the values are heading texts.
decrease_heading_level
Decreases the heading level for a heading text string.
Parameters:
-
heading_text
(str
) –The heading text to decrease the level of.
Returns:
-
str
(str
) –The modified markdown content with a decreased heading level.
Raises:
-
ValueError
–If the heading text is not found in the source data.
get_heading_level
Gets entries in the heading map at a specific level.
Parameters:
-
heading_map
(Dict[int, str]
) –A dictionary where the keys are line numbers and the values are heading texts.
-
level
(int
) –The heading level to filter by.
Returns:
-
Dict[int, str]
–Dict[int, str]: A dictionary of headings at the specified level.
increase_all_headings
Increases the heading level of all headings in the source text.
Parameters:
-
heading_map
(Dict[int, str]
) –A dictionary where the keys are line numbers and the values are heading texts.
Returns:
-
Dict[int, str]
–Dict[int, str]: A new dictionary with all heading levels increased.
increase_heading_level
Increases the heading level for a heading text string.
Parameters:
-
source_text
(str
) –The markdown content as a string.
-
heading_text
(str
) –The heading text to increase the level of.
Returns:
-
str
(str
) –The modified markdown content with an increased heading level.