From 72c73ec99d31587297f0c8d626b7e8a3a7faddaa Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Thu, 27 Feb 2025 05:28:06 -0500 Subject: [PATCH] Hard line break support --- src/SSG/Djot/Inline.idr | 17 ++++++++++++++++- src/SSG/Djot/Render.idr | 1 + test/djotToHtml/001-paragraph/expected | 17 +++++++++++++++++ test/djotToHtml/001-paragraph/test.dj | 11 +++++++++++ todo.org | 6 +++--- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/SSG/Djot/Inline.idr b/src/SSG/Djot/Inline.idr index 80d11f1..d547c43 100644 --- a/src/SSG/Djot/Inline.idr +++ b/src/SSG/Djot/Inline.idr @@ -22,6 +22,7 @@ public export data Inline : Type where Text : (text : String) -> Inline SoftLineBreak : Inline + HardLineBreak : Inline %runElab derive "Inline" [Eq, Show, Pretty] @@ -145,9 +146,18 @@ softLineBreak = do _ <- many horiz pure () +hardLineBreak : IParser Inline +hardLineBreak = do + _ <- exactly "\\" + _ <- many horiz + _ <- vert + _ <- many horiz + pure HardLineBreak + -- Definition of pInline pInline = oneOf - [ softLineBreak + [ hardLineBreak + , softLineBreak , text ] @@ -223,3 +233,8 @@ testTrailingSoftLineBreak = testTrailingSoftLineBreaks : IO Bool testTrailingSoftLineBreaks = golden "Hello\n\nWorld!\n\n\n" [Text "Hello", SoftLineBreak, Text "World!"] + +-- @@test Hard line break smoke +smokeHardLineBreak : IO Bool +smokeHardLineBreak = + golden "Hello\\\nWorld!" [Text "Hello", HardLineBreak, Text "World!"] diff --git a/src/SSG/Djot/Render.idr b/src/SSG/Djot/Render.idr index a6b8b03..b610349 100644 --- a/src/SSG/Djot/Render.idr +++ b/src/SSG/Djot/Render.idr @@ -13,6 +13,7 @@ renderInline : Inline -> Maybe (t ** Html t) -- FIXME: escape text renderInline (Text text) = Just (_ ** Text text) renderInline SoftLineBreak = Nothing +renderInline HardLineBreak = Just (_ ** Void "br" []) ||| Render a list of inline elments to html export diff --git a/test/djotToHtml/001-paragraph/expected b/test/djotToHtml/001-paragraph/expected index 6875061..612076b 100644 --- a/test/djotToHtml/001-paragraph/expected +++ b/test/djotToHtml/001-paragraph/expected @@ -12,5 +12,22 @@ A multiline paragraph with some indentation

+

+ This is a hard +
+ line break +

+

+ And again +
+ with some spaces afterwards +

+

+ And now we + mix soft +
+ and hard + linebreaks +

diff --git a/test/djotToHtml/001-paragraph/test.dj b/test/djotToHtml/001-paragraph/test.dj index d4ab1bf..1525f0b 100644 --- a/test/djotToHtml/001-paragraph/test.dj +++ b/test/djotToHtml/001-paragraph/test.dj @@ -10,3 +10,14 @@ Two line breaks A multiline paragraph with some indentation + +This is a hard\ +line break + +And again\ +with some spaces afterwards + +And now we +mix soft\ +and hard +linebreaks diff --git a/todo.org b/todo.org index ce5e9de..cce0eed 100644 --- a/todo.org +++ b/todo.org @@ -10,11 +10,11 @@ Decided to rename =Tag= to =Html=, and =Raw= to =Text=, which makes this make se ** TODO Refine =location= in =ParserLocation= ** TODO Error messages ** TODO Combinators for predictive parsing -* Djot [2/38] +* Djot [3/38] :PROPERTIES: :COOKIE_DATA: recursive :END: -** Parsing [2/33] +** Parsing [3/33] *** Block Level **** TODO Heading **** TODO Block Quote @@ -43,12 +43,12 @@ Decided to rename =Tag= to =Html=, and =Raw= to =Text=, which makes this make se **** TODO Smart Puncuation **** TODO Math **** TODO Footnote Reference -**** TODO Linebreak **** TODO Comment **** TODO Symbols **** TODO Raw Inline **** TODO Inline Attributes **** DONE Ordinary Text +**** DONE Linebreak *** Lines effect **** TODO =IO= Backed implementation *** Known Inaccuracies