Pi66

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

← back to log

fix: patch attr_list to use [ ] instead of { } to avoid Jinja2 conflicts

author: pi66
date: 2026-06-26 01:04
hash: 3736c27ff05a35d696187f1c9bb6b08f2e714899

Diffstat:

M

src/build.py
15 ++++++++++++++++++++++++------
 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
diff --git a/src/build.py b/src/build.py
index 77b96b0..5802c12 100644
--- a/src/build.py
+++ b/src/build.py
@@ -1,14 +1,23 @@
+import importlib.util
+import re
+
+from jinja2 import Environment, FileSystemLoader
+from markdown import markdown
+from markdown.extensions.attr_list import AttrListTreeprocessor
 from os import getcwd, makedirs, path, walk
 from os.path import abspath, dirname
-from markdown import markdown
-from jinja2 import Environment, FileSystemLoader
-import importlib.util

 from .config import find_project_from_path, load_tree_config
 from .errors import fatal, html_fatal
 from .fileops import read_file, write_file
 from .log import GRAY, info

+# patch [ ] instead of { }
+AttrListTreeprocessor.BASE_RE   = r'\[\:?[ ]*([^\]\n ][^\n]*)[ ]*\]'
+AttrListTreeprocessor.BLOCK_RE  = re.compile(r'\n[ ]*{}[ ]*$'.format(AttrListTreeprocessor.BASE_RE))
+AttrListTreeprocessor.HEADER_RE = re.compile(r'[ ]+{}[ ]*$'.format(AttrListTreeprocessor.BASE_RE))
+AttrListTreeprocessor.INLINE_RE = re.compile(r'^{}'.format(AttrListTreeprocessor.BASE_RE))
+
 replace_filters = [
     ("<p>{%" ,  "{%" ),
     ("%}</p>",  "%}" ),