Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

refactor: remove escape_code_blocks.

author: pi66
date: 2026-07-18 04:06
hash: 931320814c068fc2b854d242610d7477cd8b3017

Diffstat:

M

src/build.py
20 ++----------------------------

M

src/hooks.py
1 --
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
diff --git a/src/build.py b/src/build.py
index f95bbf5..75db296 100644
--- a/src/build.py
+++ b/src/build.py
@@ -103,22 +103,6 @@ def jinja_handler(config, html_content, plugins=None):
         hook_call("on_jinja_error", e)
         return html_fatal(e, f"Template error")

-def escape_code_blocks(html_content: str) -> str:
-    """ Neutralize '{' inside rendered <pre>/<code> blocks so Jinja never
-    reads {% %} or {{ }} out of code samples, even if a sample's text
-    literally contains Jinja syntax (e.g. docs showing `{% raw %}`).
-    &#123; renders back to '{' in the browser, so output is unaffected. """
-    def neutralize(m):
-        block = m.group(0)
-        block = block.replace("${", "__JINJA_OPEN__")
-        block = block.replace("{", "&#123;")
-        block = block.replace("__JINJA_OPEN__", "{")
-        return block
-
-    html_content = re.sub(r'<pre\b[\s\S]*?</pre>', neutralize, html_content)
-    html_content = re.sub(r'<code\b[\s\S]*?</code>', neutralize, html_content)
-    return html_content
-
 def save_html(html_content:str, html_dest:str):
     makedirs(path.dirname(html_dest), exist_ok=True )
     write_file( html_dest, html_content)
@@ -163,9 +147,7 @@ def md_to_html(config, md_content:str):
         }
     )
     raw_html_content = hook_call("on_md_to_html", raw_html_content) or raw_html_content
-    escaped_html = escape_code_blocks(raw_html_content)
-    escaped_html = hook_call("on_escape_code", escaped_html) or escaped_html
-    filtered_html = html_filter(escaped_html)
+    filtered_html = html_filter(raw_html_content)
     filtered_html = hook_call("on_html_filter", filtered_html) or filtered_html
     return filtered_html

diff --git a/src/hooks.py b/src/hooks.py
index 050bde9..baea0aa 100644
--- a/src/hooks.py
+++ b/src/hooks.py
@@ -4,7 +4,6 @@ hooks = {
     "on_build_end"              : None,
     "on_build_start"            : None,
     "on_config_load"            : None,
-    "on_escape_code"            : None,
     "on_file_changed"           : None,
     "on_page_skip"              : None,
     "on_hash_check"             : None,