From 0658c2806b69e46dd32ca27a9233467265d1174c Mon Sep 17 00:00:00 2001 From: Pagwin Date: Sun, 21 Sep 2025 17:52:22 -0400 Subject: [PATCH] ??? --- TODO.md | 6 +++++- app/IR.hs | 3 +-- app/Markdown.hs | 29 +++++++++++++++++++++-------- markdown.abnf | 6 ++---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/TODO.md b/TODO.md index 9829dfe..ede89b7 100644 --- a/TODO.md +++ b/TODO.md @@ -4,6 +4,10 @@ - minify js and css when copying over instead of just copying -- look into adding postcss support perhaps +- setup fingerprinting in file names for css and js + +- dev server setup (with live reloading) - see if performance can be improved (it isn't slow atm but it definitely feels like there's a bottleneck) + +- look into adding postcss support perhaps diff --git a/app/IR.hs b/app/IR.hs index 321baba..ecab637 100644 --- a/app/IR.hs +++ b/app/IR.hs @@ -20,7 +20,6 @@ data List = L {list_type :: ListType, items :: [ListItem]} data Table = T {header :: TableHeader, rows :: [TableRow]} --- TODO: layout/sizing info? newtype TableHeader = TH [Text] newtype TableRow = TR Text @@ -29,7 +28,7 @@ newtype HTML = Raw Text newtype Paragraph = P [InlineText] -data InlineText = Normal Text | Bold InlineText | Italic InlineText | CodeLine Text | Link {nest :: InlineText, href :: Text} +data InlineText = Normal Text | Escaped Char | Bold InlineText | Italic InlineText | CodeLine Text | Link {nest :: InlineText, href :: Text} | HTMLIn Text data BlankLine = BL diff --git a/app/Markdown.hs b/app/Markdown.hs index 763aa1d..3a3e466 100644 --- a/app/Markdown.hs +++ b/app/Markdown.hs @@ -39,7 +39,8 @@ paragraph :: Parser Element paragraph = do first <- paragraphLine rem <- many paragraphContinuation - pure $ Paragraph $ P [] + let combined = Prelude.concat (first : rem) + pure $ Paragraph $ P combined paragraphLine :: Parser [InlineText] paragraphLine = many inlineText <* endOfLine @@ -48,12 +49,24 @@ paragraphContinuation :: Parser [InlineText] paragraphContinuation = notFollowedBy blockElemStart *> paragraphLine inlineText :: Parser InlineText -inlineText = choice [emphasis, strong, inlineCode, link, image, inlineHTML, paragraphLineBreak, escapedChar, plainText] +inlineText = choice [emphasis, strong, inlineCode, link, image, inlineHTML, escapedChar, plainText] -plainText :: Parser Text -plainText = +plainText :: Parser InlineText +-- abnf is very specific about what's allowed due to actual ABNF not allowing negation but I'm lazy +plainText = fmap (Normal . pack) $ many $ noneOf "*_`[]()<>#+-.!&\\\n" -blankLine :: Parser Element -blankLine = do - endOfLine - pure $ BlankLine BL +escapedChar :: Parser InlineText +escapedChar = char '\\' *> fmap Escaped visibleChar + +htmlInline :: Parser InlineText +htmlInline = do + _ <- char '<' + remaining <- htmlInlineRemainder + pure $ HTMLIn $ pack $ '<' : remaining + where + htmlInlineRemainder = tagName *> attrList + tagName = many $ choice [alphaNum, char '-', char ':'] + +visibleChar :: Parser Char +-- technically more strict but I'm just going to hope I never have to deal with that +visibleChar = anyChar diff --git a/markdown.abnf b/markdown.abnf index 9b80f2d..feaf1e6 100644 --- a/markdown.abnf +++ b/markdown.abnf @@ -73,11 +73,11 @@ paragraph-continuation = paragraph-first-element *( inline-element ) line-ending ; First element of paragraph - anything that's not a block starter paragraph-first-element = emphasis / strong / code-span / link / image / - html-inline / line-break / escaped-char / plain-text + html-inline / escaped-char / plain-text ; Inline elements inline-element = emphasis / strong / code-span / link / image / - html-inline / line-break / escaped-char / plain-text + html-inline / escaped-char / plain-text ; Emphasis and strong (left-factored by delimiter) emphasis = emphasis-asterisk / emphasis-underscore @@ -135,8 +135,6 @@ attribute-value-squote = *( %x20-26 / %x28-10FFFF ) ; Everything except ' attribute-value-unquoted = 1*( %x21-22 / %x24-26 / %x28-2F / %x30-3D / %x3F-10FFFF ) html-content = *( %x20-3B / %x3D-10FFFF ) ; Everything except < -; Line breaks and escaped characters -line-break = 2*WSP line-ending escaped-char = "\" VCHAR ; Plain text variations (to avoid conflicts)