MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / mask_inactive

Function mask_inactive

scripts/theme_gate.py:55–99  ·  view source on GitHub ↗

Blank what Liquid never renders, keeping every newline so line numbers hold. Covers nested ``{% comment %}`` (depth counter; a ``{% raw %}`` inside hides its ``comment``/``endcomment``), ``raw``, ``doc``, ``schema``, ``{% # … %}`` and ``#`` / comment lines inside ``{% liquid %}``.

(text: str)

Source from the content-addressed store, hash-verified

53
54
55def mask_inactive(text: str) -> str:
56 """Blank what Liquid never renders, keeping every newline so line numbers hold.
57
58 Covers nested ``{% comment %}`` (depth counter; a ``{% raw %}`` inside hides
59 its ``comment``/``endcomment``), ``raw``, ``doc``, ``schema``, ``{% # … %}``
60 and ``#`` / comment lines inside ``{% liquid %}``.
61 """
62 out = list(text)
63 depth = 0
64 comment_from = 0 # where the outermost open comment started; its whole body is blanked when it closes
65 resume = 0 # tags before this offset were consumed by a raw/doc/schema skip
66 for m in _TAG.finditer(text):
67 if m.start() < resume:
68 continue
69 nm = _TAG_NAME.match(m.group(1))
70 name = nm.group(1) if nm else ""
71 if depth:
72 _blank(text, m.start(), m.end(), out)
73 if name == "comment":
74 depth += 1
75 elif name == "endcomment":
76 depth -= 1
77 if depth == 0:
78 _blank(text, comment_from, m.end(), out)
79 elif name == "raw":
80 end = _END_RAW.search(text, m.end())
81 resume = end.end() if end else len(text)
82 _blank(text, m.end(), resume, out)
83 continue
84 if name == "comment":
85 depth = 1
86 comment_from = m.start()
87 _blank(text, m.start(), m.end(), out)
88 elif name == "#":
89 _blank(text, m.start(), m.end(), out)
90 elif name in ("raw", "doc", "schema"):
91 closer = re.compile(r"\{%-?\s*end" + name + r"\s*-?%\}")
92 end = closer.search(text, m.end())
93 resume = end.end() if end else len(text)
94 _blank(text, m.start(), resume, out)
95 elif name == "liquid":
96 _mask_liquid_tag_body(text, m.start() + 2, m.end() - 2, out)
97 if depth:
98 _blank(text, comment_from, len(text), out)
99 return "".join(out)
100
101
102def norm(label: str) -> str:

Callers 7

cases_aFunction · 0.85
css_selectorsFunction · 0.85
cases_bFunction · 0.85
cases_cFunction · 0.85
cases_dFunction · 0.85
cases_fFunction · 0.85
cases_eFunction · 0.85

Calls 4

_mask_liquid_tag_bodyFunction · 0.85
_blankFunction · 0.70
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected