Skip to content

Commit

Permalink
Support arbitrary element names.
Browse files Browse the repository at this point in the history
Standard HTML elements can now be defined using a combination of `frag`
and `el` as shown in the example `.slab` file.
  • Loading branch information
noteed committed Jun 18, 2024
1 parent 7afd1fb commit 1ee5ec0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
20 changes: 20 additions & 0 deletions examples/el.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<x>
Hello.
</x>
<x>
<p>
Hello.
</p>
</x>
<y>
Hello.
</y>
<y>
<p>
Hello.
</p>
</y>
<y>
</y>
<z class="a">
</z>
17 changes: 17 additions & 0 deletions examples/el.slab
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
el x Hello.

el x
p Hello.

frag y
el y
default content

y Hello.

y
p Hello.

y

el z.a
4 changes: 3 additions & 1 deletion src/Slab/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ parserNameWithAttrs :: Parser (Elem, [Attr], TrailingSym)
parserNameWithAttrs =
lexeme
( do
a <- parserElem
a <-
parserElem
<|> (lexeme (string "el") *> (Elem <$> lexeme parserName))
-- `try` because we want to backtrack if there is a dot
-- not followed by a class name, for mdot to succeed.
b <- many parserAttrs'
Expand Down
2 changes: 2 additions & 0 deletions src/Slab/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Text.Blaze.Html.Renderer.Text (renderHtml)
import Text.Blaze.Html5 (Html, (!))
import Text.Blaze.Html5 qualified as H
import Text.Blaze.Html5.Attributes qualified as A
import Text.Blaze.Internal qualified as I
import Text.Blaze.Svg11 qualified as S

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -195,3 +196,4 @@ renderElem = \case
Syntax.Svg -> S.svg
Syntax.Textarea -> H.textarea
Syntax.Canvas -> H.canvas
Syntax.Elem name -> I.customParent (H.textTag name)
2 changes: 2 additions & 0 deletions src/Slab/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ data Elem
| Svg
| Textarea
| Canvas
| -- | Arbitrary element name, using the @el@ keyword.
Elem Text
deriving (Show, Eq)

data TrailingSym = HasDot | HasEqual | NoSym
Expand Down

0 comments on commit 1ee5ec0

Please sign in to comment.