aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-16 20:41:55 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-16 20:44:47 -0400
commit9792de2630a9b40da00b2eefb46eb9977c2c6b08 (patch)
tree51e4759767eb4dc28abfd70abbf8dc70793191a2 /doc
parent1880ee9d6ec6744cc0ea990572293480ce756c89 (diff)
Add basic table support
Diffstat (limited to 'doc')
-rw-r--r--doc/md.bqn23
1 files changed, 18 insertions, 5 deletions
diff --git a/doc/md.bqn b/doc/md.bqn
index 632f2d78..8d9c7648 100644
--- a/doc/md.bqn
+++ b/doc/md.bqn
@@ -76,6 +76,9 @@ Markdown ← {
last ⊏ 𝕨
}
+ # Remove leading and trailing spaces
+ Trim ← { 𝕩 /˜ ¬ (∧` ∨ ∧`⌾⌽) ' '=𝕩 }
+
######
# First we classify each line based on the type of block it can start.
ClassifyLine ← (0<≠)◶(0‿0)‿{
@@ -108,8 +111,7 @@ Markdown ← {
tail ← ∧`⌾⌽ trsp∨𝕩='#' # Mask of trailing hashes
f ← tail < 0 Shr tail # Character before trailing hashes
𝕩 /˜↩ ¬ f (⊑⟨"\"," ",""⟩⊐<f/𝕩)◶⟨⊣,⊢,⊢,0¨⊢⟩ tail
- 𝕩 /˜↩ ¬ (∧` ∨ ∧`⌾⌽) ' '=𝕩
- tag Html ProcInline 𝕩
+ tag Html ProcInline Trim 𝕩
}⟜⊑
# List items start with a bullet (unordered) or number (ordered).
@@ -122,8 +124,19 @@ Markdown ← {
l ∧ (" " ≡ 1↓t) ∧ ⊑(")." ∊˜ 1↑t)
}
- # Tables are not yet supported
- IsTable ← 0˜
+ # Any line that starts with a | is a table, at least in my lazy version
+ IsTable ← 1˜
+ ProcTable ← {
+ rows ← (Trim¨ ((1-˜¬×+`)'|'⊸=)⊸⊔)¨ 𝕩
+ inc ← ¬ rule ← ∧´∘∾¨'-'=rows
+ rows ↩ ProcInline¨¨⌾(inc⊸/) rows
+ rowType ← inc / +` rule # Head or body
+ DoRow ← { lf ∾ JoinLines 𝕨⊸Html¨ 𝕩 }
+ rows ↩ (rowType ⊏ "th"‿"td") DoRow¨ inc/rows
+ rowGroups ← ¯1 ↓ rowType ⊔○(∾⟜2) "tr"⊸Html¨ rows
+ sections ← "thead"‿"tbody" Html⟜(lf ∾ JoinLines)¨ rowGroups
+ "table" Html lf ∾ JoinLines (0 < ≠¨rowGroups) / sections
+ }
# Paragraphs
ProcParagraph ← {
@@ -138,7 +151,7 @@ Markdown ← {
" " ‿ IsCode ‿ ProcCode
# "-+*" ‿ LenBullet ‿ ProcBullet
# •d ‿ LenListNum ‿ ProcListNum
- # "|" ‿ IsTable ‿ ProcTable
+ "|" ‿ IsTable ‿ ProcTable
######