diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-10-10 17:38:00 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-10-10 17:38:00 +0200 |
| commit | 87dba241820b33111017b041f624a88e74e4220a (patch) | |
| tree | 0599325624560548f86f5c09a44365da6eef8fff | |
| parent | 85da4abc206f2cc8819836bb0e8727de3a51d24c (diff) | |
| download | git2hugo-87dba241820b33111017b041f624a88e74e4220a.tar.gz | |
g2h: Escape markdown code blocks that specify a non-word language
This is mostly a workaround for the early version of the file.md which had ```{{
| -rw-r--r-- | src/g2h/file_page.py | 1 | ||||
| -rw-r--r-- | tests/file_page_test.py | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/g2h/file_page.py b/src/g2h/file_page.py index f2e0550..c317454 100644 --- a/src/g2h/file_page.py +++ b/src/g2h/file_page.py @@ -40,6 +40,7 @@ class FilePage(Page): if file_type == 'text': if self.file_name.lower().endswith('.md'): backtick_max = -1 + content = re.sub(r'(`{3,}\W)', r'\\\1', content) else: matches = re.findall('`+', content) backtick_max = max(max(len(match) for match in matches) if matches else 0, backtick_max) diff --git a/tests/file_page_test.py b/tests/file_page_test.py index 5c380b8..63a086a 100644 --- a/tests/file_page_test.py +++ b/tests/file_page_test.py @@ -106,3 +106,16 @@ def test_markdown(): file.data_stream.read.return_value = '```'.encode() context = page.context() assert(context['backtick_max'] == 0) + +def test_markdown_invalid_code_tag(): + file = MagicMock() + tree = MagicMock() + commit = MagicMock() + commit.hexsha = '123' + commit.tree = tree + commit.tree.join.return_value = file + page = FilePage('test/file', 'file test', commit, 'file.Md', '', 'file/content') + file.data_stream.read.return_value = '```{'.encode() + context = page.context() + assert(context['backtick_max'] == 0) + assert(context['content'] == '\\```{') |