Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_test_md(name):
return preprocessing(
open(os.path.join(DATA, name), encoding='utf-8').read(),
)
def fix(src, dst):
file_content = preprocessing(src.read())
text_elements = transform(file_content)
correction_handler = ErrorCorrectionHandler(file_content, text_elements)
for text_element in text_elements:
process_errors(correction_handler, text_element)
try:
correction_executor = DiffOperationExecutor(
correction_handler.diffs,
correction_handler.raw_lines,
)
fixed = correction_executor.apply_diff_operations()
except RuntimeError:
click.echo('Something Wrong.')
sys.exit(1)
def validate_markdown(self, markdown):
m = mistune.Markdown()
blocks = m.block(mistune.preprocessing(markdown))
for block in blocks:
if block['type'] == 'heading':
# we dont want colon after section names
assert not block['text'].endswith(':')
if block['text'] in self.required_sections:
self.required_sections.remove(block['text'])
try:
assert len(self.required_sections) == 0
except AssertionError as e:
print("Missing required sections: {}".format(self.required_sections))
raise e