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
src/SSG/Djot
test/djotToHtml/001-paragraph
todo.org

View file

@ -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!"]

View file

@ -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

View file

@ -12,5 +12,22 @@
A multiline paragraph
with some indentation
</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>
</html>

View file

@ -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

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 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