diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-19 14:32:38 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-19 14:38:35 -0400 |
| commit | 09affe23f2e4977a1225eaf27b2abf7fa6b4715f (patch) | |
| tree | 8412984c7c8d10ab1e9944940f271c481dbfcc2b /md.bqn | |
| parent | 8b2806ea128128e0ff411b71a973909c6f9a022d (diff) | |
Handle bracket/parenthesis nesting in inline links
Diffstat (limited to 'md.bqn')
| -rw-r--r-- | md.bqn | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -261,12 +261,18 @@ Markdown ← {𝕊𝕩:1𝕊𝕩; extensions𝕊𝕩: ReplaceMDSub ← { ¯2 ("README"•_r_"index"∘↓∾"html"˜)⍟(("md"≡↑)∧':'∧´∘≠⊢) 𝕩 } ReplaceMD ← { ReplaceMDSub⌾((⊑𝕩⊐"#")⊸↑) 𝕩 } ProcLink ← { ∾⟨"<a href=""",(ReplaceMD 𝕩),""">",𝕨,"</a>"⟩ } - brak ← /∘(unused ∧ 𝕩⊸=)¨ "]()[" - link ← (∊/⊣)´ 0‿¯1 + 2 ↑ brak - chains ← (⍋˜ ⊏ ⊢∾(≠𝕩)˜)` ¯1 ⌽ (<link) ∾ 2 ↓ brak - chains ↩ > (∧´ (∊ ∧ <⟜(≠𝕩))¨ 1 ↓ chains)⊸/¨ chains - linkPos ← 0 ⊏ chains - lInds ← 1‿0‿2‿0⊸+˘ (⥊2⊸↕)˘ ⍉ chains + # Find matched-depth [] and () pairs, then join adjacent ones + brak ← (unused ∧ 𝕩⊸=)¨ 2‿2⥊"[]()" + depth ← (+`-0⌊⊢)∘(-´)˘ brak + FindPairs ← ⟨⟩‿2 ⥊ 1⊸⊏ /˜ 2⊸⊏ ≠ (¯∞⊸Shl⊸=(∧+⊢)∞⊸Shr⊸=)∘⊏ + pairs ← depth <∘(FindPairs⍟(0<≠))∘⍉∘(∧(⊏˜≍˘⊢)⟜∾∾˘·/≠¨∘⊢)˘ /¨brak + JoinPairs ← { + e←1+1⊏˘𝕨 ⋄ b←⊏˘𝕩 ⋄ m←(≠b)>i←b⊐e + (m/𝕨) ∾˘ (m/i)⊏𝕩 + } + lInds ← ∧○(0<≠)◶(0‿4⥊0)‿JoinPairs´ pairs + linkPos ← ⊏˘ lInds + lInds +⎉1↩ 1‿0‿1‿0 unused ∧↩ include ∧↩ ¬ ≠` I2M ⥊ (¯1‿1+0‿3⊸⊏)˘ lInds linkGroup ← 1 -˜ (1‿0⥊˜≢)⊸(/ (⊣×>)○(+`I2M) ¬⊸/) ⥊lInds links ← <∘ProcLink´˘ (lInds≠⊸∾2) (⊣⥊×´⊸↑) linkGroup ⊔ 𝕩 |
