mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Refactor double brace parsing
This commit is contained in:
parent
cbb7e69f68
commit
8852921b3d
1 changed files with 7 additions and 11 deletions
|
@ -214,23 +214,19 @@ class MTex(LabelledString):
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
# Match paired double braces (`{{...}}`).
|
# Match paired double braces (`{{...}}`).
|
||||||
reversed_brace_spans_dict = dict(sorted([
|
sorted_brace_spans = sorted(
|
||||||
pair[::-1] for pair in self.brace_spans
|
self.brace_spans, key=lambda span: span[1]
|
||||||
]))
|
)
|
||||||
skip = False
|
skip = False
|
||||||
for prev_brace_end, brace_end in self.get_neighbouring_pairs(
|
for prev_span, span in self.get_neighbouring_pairs(
|
||||||
list(reversed_brace_spans_dict.keys())
|
sorted_brace_spans
|
||||||
):
|
):
|
||||||
if skip:
|
if skip:
|
||||||
skip = False
|
skip = False
|
||||||
continue
|
continue
|
||||||
if brace_end != prev_brace_end + 1:
|
if span[0] != prev_span[0] - 1 or span[1] != prev_span[1] + 1:
|
||||||
continue
|
continue
|
||||||
brace_begin = reversed_brace_spans_dict[brace_end]
|
result.append(span)
|
||||||
prev_brace_begin = reversed_brace_spans_dict[prev_brace_end]
|
|
||||||
if brace_begin != prev_brace_begin - 1:
|
|
||||||
continue
|
|
||||||
result.append((brace_begin, brace_end))
|
|
||||||
skip = True
|
skip = True
|
||||||
|
|
||||||
result.extend(it.chain(*[
|
result.extend(it.chain(*[
|
||||||
|
|
Loading…
Add table
Reference in a new issue