diff options
| author | Christoph Schlosser <christoph@linux.com> | 2025-09-19 20:14:59 +0200 |
|---|---|---|
| committer | Christoph Schlosser <christoph@linux.com> | 2025-09-19 20:14:59 +0200 |
| commit | 04f8d5f3093e1b13aa704590f4d0bf9dce6afce9 (patch) | |
| tree | 163392588adcd735a7ab805b24740fdb1120b8ec /src/g2h/file_page.py | |
| parent | cebadfcfbe74a9b892854e860d6d50565dffa7be (diff) | |
| download | git2hugo-04f8d5f3093e1b13aa704590f4d0bf9dce6afce9.tar.gz | |
g2h: Make sure backticks in plaintext doesn't break page rendering
Diffstat (limited to 'src/g2h/file_page.py')
| -rw-r--r-- | src/g2h/file_page.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/g2h/file_page.py b/src/g2h/file_page.py index a558254..d64cb84 100644 --- a/src/g2h/file_page.py +++ b/src/g2h/file_page.py @@ -1,6 +1,7 @@ import base64 import filetype import os +import re from .file import generate_breadcrumbs, sanitize_file_name, tree_join from .page import Page @@ -35,8 +36,13 @@ class FilePage(Page): def context(self): file_bytes = self.read_file() content, file_type = bytes_to_content(file_bytes) + backtick_max = 2 + if file_type == 'text': + matches = re.findall('`+', content) + backtick_max = max(max(len(match) for match in matches) if matches else 0, backtick_max) return { + 'backtick_max': backtick_max + 1, 'breadcrumbs': generate_breadcrumbs(self.content_subdir, self.commit, os.path.join(self.file_path, self.file_name), self.tree.blobs), 'content': content, 'content_subdir': self.content_subdir, |