Hard line break support

This commit is contained in:
Nathan McCarty 2025-02-27 05:28:06 -05:00
parent e4fe5f98e6
commit 72c73ec99d
5 changed files with 48 additions and 4 deletions

View file

@ -22,6 +22,7 @@ public export
data Inline : Type where data Inline : Type where
Text : (text : String) -> Inline Text : (text : String) -> Inline
SoftLineBreak : Inline SoftLineBreak : Inline
HardLineBreak : Inline
%runElab derive "Inline" [Eq, Show, Pretty] %runElab derive "Inline" [Eq, Show, Pretty]
@ -145,9 +146,18 @@ softLineBreak = do
_ <- many horiz _ <- many horiz
pure () pure ()
hardLineBreak : IParser Inline
hardLineBreak = do
_ <- exactly "\\"
_ <- many horiz
_ <- vert
_ <- many horiz
pure HardLineBreak
-- Definition of pInline -- Definition of pInline
pInline = oneOf pInline = oneOf
[ softLineBreak [ hardLineBreak
, softLineBreak
, text , text
] ]
@ -223,3 +233,8 @@ testTrailingSoftLineBreak =
testTrailingSoftLineBreaks : IO Bool testTrailingSoftLineBreaks : IO Bool
testTrailingSoftLineBreaks = testTrailingSoftLineBreaks =
golden "Hello\n\nWorld!\n\n\n" [Text "Hello", SoftLineBreak, Text "World!"] 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!"]

View file

@ -13,6 +13,7 @@ renderInline : Inline -> Maybe (t ** Html t)
-- FIXME: escape text -- FIXME: escape text
renderInline (Text text) = Just (_ ** Text text) renderInline (Text text) = Just (_ ** Text text)
renderInline SoftLineBreak = Nothing renderInline SoftLineBreak = Nothing
renderInline HardLineBreak = Just (_ ** Void "br" [])
||| Render a list of inline elments to html ||| Render a list of inline elments to html
export export

View file

@ -12,5 +12,22 @@
A multiline paragraph A multiline paragraph
with some indentation with some indentation
</p> </p>
<p>
This is a hard
<br>
line break
</p>
<p>
And again
<br>
with some spaces afterwards
</p>
<p>
And now we
mix soft
<br>
and hard
linebreaks
</p>
</body> </body>
</html> </html>

View file

@ -10,3 +10,14 @@ Two line breaks
A multiline paragraph A multiline paragraph
with some indentation with some indentation
This is a hard\
line break
And again\
with some spaces afterwards
And now we
mix soft\
and hard
linebreaks

View file

@ -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 Refine =location= in =ParserLocation=
** TODO Error messages ** TODO Error messages
** TODO Combinators for predictive parsing ** TODO Combinators for predictive parsing
* Djot [2/38] * Djot [3/38]
:PROPERTIES: :PROPERTIES:
:COOKIE_DATA: recursive :COOKIE_DATA: recursive
:END: :END:
** Parsing [2/33] ** Parsing [3/33]
*** Block Level *** Block Level
**** TODO Heading **** TODO Heading
**** TODO Block Quote **** 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 Smart Puncuation
**** TODO Math **** TODO Math
**** TODO Footnote Reference **** TODO Footnote Reference
**** TODO Linebreak
**** TODO Comment **** TODO Comment
**** TODO Symbols **** TODO Symbols
**** TODO Raw Inline **** TODO Raw Inline
**** TODO Inline Attributes **** TODO Inline Attributes
**** DONE Ordinary Text **** DONE Ordinary Text
**** DONE Linebreak
*** Lines effect *** Lines effect
**** TODO =IO= Backed implementation **** TODO =IO= Backed implementation
*** Known Inaccuracies *** Known Inaccuracies