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
+