aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-16 21:57:42 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-16 21:57:42 -0400
commit9d069443f0315c30b59d5923159e0233a93fc139 (patch)
tree61d772f1368234ad08c101a2e68e638e7fa76317
parentd18f2e1cac5c8dfdb2b2c7d21bf6bd81633d623b (diff)
Add header ids for linking
-rw-r--r--doc/md.bqn10
1 files changed, 8 insertions, 2 deletions
diff --git a/doc/md.bqn b/doc/md.bqn
index b840817a..acb264ba 100644
--- a/doc/md.bqn
+++ b/doc/md.bqn
@@ -47,8 +47,7 @@ JoinLines ← ∾ ∾⟜lf¨
# Create an html node from a tag name and interior text
Html ← {
- 𝕨 ∾↩ ">"
- ∾ ⟨"<",𝕨 , 𝕩 , "</",𝕨⟩
+ ∾ ⟨"<",𝕨,">" , 𝕩 , "</",(⊑⊐⟜" ")⊸↑𝕨,">"⟩
}
################################
@@ -111,6 +110,13 @@ Markdown ← {
tail ← ∧`⌾⌽ trsp∨𝕩='#' # Mask of trailing hashes
f ← tail < 0 Shr tail # Character before trailing hashes
𝕩 /˜↩ ¬ f (⊑⟨"\"," ",""⟩⊐<f/𝕩)◶⟨⊣,⊢,⊢,0¨⊢⟩ tail
+ # Add an id: lowercase the header, replacing non-•a with hyphens
+ Slugify ← {
+ ch ← •UCS "-Aa"
+ bounds ← ⥊ (1↓ch) +⌜ 0‿26 # Of the upper and lowercase alphabet
+ (bounds⊸⍋ {(⊑ch)¨⌾((¬2|𝕨)⊸/)𝕩+32×1=𝕨} ⊢)⌾•UCS 𝕩
+ }
+ tag ∾↩ " id="∾""""(∾∾⊣) Slugify 𝕩
tag Html ProcInline Trim 𝕩
}⟜⊑