Skip to content

Commit 30ba73e

Browse files
Disallow unmatched inline code guards (#1414)
1 parent 0d890c3 commit 30ba73e

19 files changed

+70
-30
lines changed

scripts/markdown_conventions.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
empty_block_pattern = re.compile(
1414
r'^```\S+.*\n(\s*\n)*\n```\s*$(?!\n(\s*\n)*</details>)', flags=re.MULTILINE)
1515

16+
# Pattern to detect unmatched inline code guards
17+
unclosed_backtick_pattern = re.compile(r'^([^`]*`[^`]*`)*[^`]+`[^`]*$')
18+
1619

1720
def find_ill_formed_block(mdcode):
1821
"""
19-
Checks if in a markdown file, every (specified) opening block tag is paired
20-
with a closing block tag before a new one is opened.
22+
Checks if in a markdown file, every (specified) opening block guard is
23+
paired with a closing block guard before a new one is opened.
2124
22-
Returns the line number of the first offending guard, as well as whether it is identified as a closing or opening guard.
25+
Returns the line number of the first offending guard, as well as whether it
26+
is identified as a closing or opening guard.
2327
2428
Note: This also disallows unspecified code blocks.
2529
"""
@@ -53,11 +57,39 @@ def find_ill_formed_block(mdcode):
5357
empty_section_eof = re.compile(
5458
r'^(.*\n)*#+\s([^\n]*)\n(\s*\n)*$', flags=re.MULTILINE)
5559

60+
61+
def check_unclosed_inline_code_guard(mdcode):
62+
"""
63+
Checks if in a markdown file, every opening inline code block guard is
64+
paired with a closing guard.
65+
66+
Returns a list of line numbers.
67+
"""
68+
# Split the content into lines for line number tracking
69+
lines = mdcode.split('\n')
70+
71+
# Check each line that's not in a code block
72+
in_code_block = False
73+
problematic_lines = []
74+
75+
for i, line in enumerate(lines, 1): # Start counting from 1 for line numbers
76+
stripped = line.strip()
77+
if stripped.startswith('```'):
78+
in_code_block = not in_code_block
79+
continue
80+
81+
if not in_code_block and unclosed_backtick_pattern.match(line):
82+
problematic_lines.append(i)
83+
84+
return problematic_lines
85+
86+
5687
if __name__ == '__main__':
5788

5889
STATUS_UNSPECIFIED_OR_ILL_FORMED_BLOCK = 1
5990
STATUS_TOP_LEVEL_HEADER_AFTER_FIRST_LINE = 2
6091
STATUS_EMPTY_SECTION = 4
92+
STATUS_UNCLOSED_BACKTICK = 8
6193

6294
status = 0
6395

@@ -80,6 +112,14 @@ def find_ill_formed_block(mdcode):
80112

81113
status |= STATUS_UNSPECIFIED_OR_ILL_FORMED_BLOCK
82114

115+
# Check for unmatched backticks outside of Agda code blocks
116+
backtick_lines = check_unclosed_inline_code_guard(output)
117+
if backtick_lines:
118+
line_list = ", ".join(str(line) for line in backtick_lines)
119+
print(
120+
f"Error! File '{fpath}' line(s) {line_list} contain backticks (`) for guarding inline code blocks that don't have matching closing or opening guards. Please add the matching backtick(s).")
121+
status |= STATUS_UNCLOSED_BACKTICK
122+
83123
if top_level_header_after_first_line.search(output):
84124
print(
85125
f"Error! File '{fpath}' has a top level header after the first line. Please increase the header's level.")

src/elementary-number-theory/based-induction-natural-numbers.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ family `P` of types over `ℕ` and any natural number `k : ℕ`, equipped with
3131

3232
such that
3333

34-
1. `based-ind-ℕ k P p0 pS k K = p0` for any `K : k ≤-ℕ k, and
34+
1. `based-ind-ℕ k P p0 pS k K = p0` for any `K : k ≤-ℕ k`, and
3535
2. `based-ind-ℕ k P p0 pS (n + 1) N' = pS n N (based-ind-ℕ k P p0 pS n N` for
3636
any `N : k ≤-ℕ n` and any `N' : k ≤-ℕ n + 1`.
3737

src/foundation/diagonals-of-morphisms-arrows.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ maps `i` and `j`, which fit in a naturality square
4141
```
4242

4343
In other words, the diagonal of a morphism of arrows `h : hom-arrow f g` is a
44-
morphism of arrows `Δ h : hom-arrow f (functoriality Δ g).
44+
morphism of arrows `Δ h : hom-arrow f (functoriality Δ g)`.
4545

4646
Note that this operation preserves
4747
[cartesian squares](foundation.cartesian-morphisms-arrows.md). Furthermore, by a

src/foundation/equivalences.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ equivalences are contractible maps, it follows that the
113113
at `id : A → A` is contractible, i.e., the type `Σ (B → A) (λ h → h ∘ f = id)`
114114
is contractible. Furthermore, since fiberwise equivalences induce equivalences
115115
on total spaces, it follows from
116-
[function extensionality](foundation.function-extensionality.md)` that the type
116+
[function extensionality](foundation.function-extensionality.md) that the type
117117

118118
```text
119119
Σ (B → A) (λ h → h ∘ f ~ id)

src/foundation/regensburg-extension-fundamental-theorem-of-identity-types.lagda.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ The Regensburg extension of the fundamental theorem is used in the following
293293
files:
294294

295295
- In
296-
[`higher-group-theory.free-higher-group-actions.md`](higher-group-theory.free-higher-group-actions.md)
296+
[`higher-group-theory.free-higher-group-actions`](higher-group-theory.free-higher-group-actions.md)
297297
it is used to show that a higher group action is free if and only its total
298298
space is a set.
299299
- In
300-
[`higher-group-theory.transitive-higher-group-actions.md`](higher-group-theory.transitive-higher-group-actions.md)
300+
[`higher-group-theory.transitive-higher-group-actions`](higher-group-theory.transitive-higher-group-actions.md)
301301
it is used to show that a higher group action is transitive if and only if its
302302
total space is connected.
303303

src/graph-theory/dependent-reflexive-graphs.lagda.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Alternatively, a dependent reflexive graph `B` over `A` can be defined by
4444
- A family `B₀ : A₀ → Reflexive-Graph` of reflexive graphs as the type family of
4545
vertices
4646
- A family `B₁ : {x y : A₀} → A₁ x y → (B₀ x)₀ → (B₀ y)₀ → 𝒰`.
47-
- A [family of equivalences](foundation.families-of-equivalences.md) `refl B :
48-
(x : A₀) (y y' : B₀ x) → B₁ (refl A x) y y' ≃ (B₀ x)₁ y y'.
47+
- A [family of equivalences](foundation.families-of-equivalences.md)
48+
`refl B : (x : A₀) (y y' : B₀ x) → B₁ (refl A x) y y' ≃ (B₀ x)₁ y y'`.
4949

5050
This definition is more closely related to the concept of morphism into the
5151
universal reflexive graph.

src/group-theory/conjugation.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ the map `y ↦ (xy)x⁻¹`. This can be seen as a homomorphism `G → G` as well
4040
group action of `G` onto itself.
4141

4242
The delooping of the conjugation homomorphism is defined in
43-
[`structured-types.conjugation-pointed-types.md`](structured-types.conjugation-pointed-types.md)`.
43+
[`structured-types.conjugation-pointed-types`](structured-types.conjugation-pointed-types.md).
4444

4545
## Definitions
4646

src/group-theory/pullbacks-subsemigroups.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module _
8181
is-closed-under-eq-Subsemigroup' G pullback-Subsemigroup
8282
```
8383

84-
### The order preserving operation `pullback-Subsemigroup
84+
### The order preserving operation `pullback-Subsemigroup`
8585

8686
```agda
8787
module _

src/group-theory/subgroups.lagda.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ module _
657657

658658
The subset consisting of elements `x : G` such that `(1 = x) ∨ P` holds is
659659
always a subgroup of `G`. This subgroup consists only of the unit element if `P`
660-
is false, and it is the [full subgroup](group-theory.full-subgroups.md)`if`P` is
661-
true.
660+
is false, and it is the [full subgroup](group-theory.full-subgroups.md) if `P`
661+
is true.
662662

663663
```agda
664664
module _

src/orthogonal-factorization-systems/extensions-lifts-families-of-elements.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ diagram
269269
f g
270270
```
271271

272-
The composite `g ∘ f` is then an extension of `c` along `a.
272+
The composite `g ∘ f` is then an extension of `c` along `a`.
273273

274274
```agda
275275
module _

0 commit comments

Comments
 (0)