From 8846e63a6f1fe51ee9a68dc511cc6fcdbf54efa6 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 3 Oct 2020 16:32:29 -0400 Subject: Verify html link line at the top of markdown files when converting --- md.bqn | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'md.bqn') diff --git a/md.bqn b/md.bqn index a5fe9021..cae918ab 100644 --- a/md.bqn +++ b/md.bqn @@ -153,6 +153,24 @@ Base64 ← { (v⊏b64)∾(3|-l)⥊'=' } +# HTML and JS for demo REPL used in main README +repl ← 1↓" +
+
+
+ + +
+
""B Q N""
+
" +loadRepl ← "" + +# Various URLs +siteURL ← "https://mlochbaum.github.io/BQN/" +tryURL ← siteURL∾"try.html#code=" +repoURL ← "https://github.com/mlochbaum/BQN" +blobURL ← repoURL∾"/blob/master/" + ################################ Markdown ← {filename𝕊𝕩: @@ -213,8 +231,7 @@ Markdown ← {filename𝕊𝕩: } 𝕩 Link ← { - try←"https://mlochbaum.github.io/BQN/try.html#code=" - c ← try ∾ "&run" ∾˜ Base64 ¯1 ↓ JoinLines 4↓¨𝕩 + c ← tryURL ∾ "&run" ∾˜ Base64 ¯1 ↓ JoinLines 4↓¨𝕩 ("a class=""replLink"" title=""Open in the REPL"" target=""_blank"" href="∾""""(∾∾⊣)c) Html "↗️" } mod ← ⟨em,e∾c∾r,ei∾ci∾ri⟩ Modify code @@ -294,17 +311,8 @@ Markdown ← {filename𝕊𝕩: # Lazy rule: if it starts with < and contains >, it's probably HTML IsHtmlBlock ← ⊑ ">"⊸∊ useRepl ← 0 - loadRepl ← "" ProcHtmlBlock ← (""∾lf)⊸≢◶{𝕩⋄ - useRepl ↩ 1 -"
-
-
- - -
-
""B Q N""
-
" + useRepl ↩ 1 ⋄ repl }‿{ codeMask ← "" (6⥊0)⊸»⊸(>○(⌈`(1+↕∘≠)⊸×))○(⍷⟜𝕩 ∾ 0⥊˜1-˜≠) "" (1¨ <⊸∾ codeMask⊸GetMultiHighlights)⊸Modify 𝕩 @@ -362,7 +370,7 @@ Markdown ← {filename𝕊𝕩: ProcLink ← {text 𝕊 target: ∾⟨"",ProcInline text,""⟩ } - ghPath ← "https://github.com/mlochbaum/BQN/blob/master/"∾path + ghPath ← blobURL∾path AdjustTarget ← { # Adjust relative *.md links, and make other relative links # absolute (pointing to github.com instead of github.io). @@ -430,9 +438,6 @@ Markdown ← {filename𝕊𝕩: ###### # Create the block structure using line classifications. - # First remove the html link line: the output *is* the html file. - 𝕩 ↩ 2⊸↓⍟("*View this file" (⊣ ≡ ⌊○≠↑⊢) ⊑) 𝕩 - lengths ← ≠¨ 𝕩 # Length of each line blanks ← (Lead ' '⊸=)¨ 𝕩 # Number of leading blanks nonEmptyMask ← blanks < lengths # Empty ←→ all leading blanks @@ -609,8 +614,18 @@ Fmt ← ⍕ _fmtm ################################ # Creating HTML files ConvertFile ← { + MatchStart‿MatchEnd ← { ≤○≠◶0‿(⊣ ≡ (𝕩×≠)⊸↑) }¨ 1‿¯1 + + # Input file 𝕩 should be markdown; output file is fileout + ! ".md" MatchEnd 𝕩 + fileout ← ".html" ∾˜ (¯6⊸↓∾"index"˙)⍟("README"⊸MatchEnd) ¯3↓𝕩 + + # Contents of file to convert md ← •LNS •path∾𝕩 - out ← 𝕩 Markdown md + # Verify and remove the html link line: the output *is* the html file. + ! ("*View this file"⊸MatchStart ∧ (siteURL∾fileout∾").*")⊸MatchEnd) ⊑md + out ← 𝕩 Markdown 2↓md + parts ← (1-˜·(¬×1++`)'/'⊸=)⊸⊔ (⊑⊐⟜".")⊸↑ 𝕩 root ← ⊑ up ← ⥊∘/⟜≍⟜"../"¨ ⌽↕≠parts isInd ← "README" ≡ ¯1⊑parts @@ -621,9 +636,9 @@ ConvertFile ← { "stylesheet" Link "style.css" "title" Html "BQN: " ∾⍟(¬·∨´"BQN"⍷⊢) 2↓⊑(2≤≠)◶0‿("# "≡2⊸↑)¨⊸/md ⟩ - gh ← "a href='https://github.com/mlochbaum/BQN'"Html"BQN" + repo ← "a href='"‿repoURL‿"'" ∾⊸Html "BQN" crumbs ← up ("a href='"∾∾⟜"index.html'")⊸Html¨○((-isInd)⊸↓) (<"main")»parts - nav ← RQ "div class='nav'" Html 3↓∾ " / "⊸∾¨ gh <⊸∾ crumbs + nav ← RQ "div class='nav'" Html 3↓∾ " / "⊸∾¨ repo <⊸∾ crumbs front ← head ∾○(∾⟜lf) nav front ∾ out } -- cgit v1.2.3