Skip to content

Commit

Permalink
Fix: don't add whitespace in blank lines.
Browse files Browse the repository at this point in the history
In the example

    script.
      a
        b

        c

Slab was generating whitespaces for the line between b and c (as if
there was a character to be indented as much as b and c). This is no
longer the case.
  • Loading branch information
noteed committed Jun 20, 2024
1 parent 9d7a98b commit 6358e98
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
c
b
</script>
<script>
a
b

c
</script>
5 changes: 5 additions & 0 deletions examples/script.slab
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ script.
script.
c
b
script.
a
b

c
5 changes: 3 additions & 2 deletions src/Slab/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ parserElement = do
header <- parserDiv
parserElemBody ref header

-- | Parse the indented content of an HTML element or a fragment call.
parserElemBody :: Pos -> ([Block] -> Block) -> Parser (L.IndentOpt Parser Block Block)
parserElemBody ref header =
case trailingSym $ header [] of
Expand Down Expand Up @@ -154,7 +155,7 @@ textBlock ref p = go
l <- p
ls <- go
let prefix = T.replicate (unPos pos - unPos ref) " "
n' = replicate (n - 1) prefix
n' = replicate (n - 1) ""
l' = prefix <> l
pure $ n' <> (l' : ls)

Expand All @@ -164,7 +165,7 @@ textBlock ref p = go
realign :: [Text] -> [Text]
realign xs = map (T.drop n) xs
where
n = minimum $ map (T.length . T.takeWhile (== ' ')) xs
n = minimum $ map (T.length . T.takeWhile (== ' ')) $ filter (not . T.null) xs

-- | Parse multiple lines starting each with a pipe prefix. Most of our parsers
-- parse a single line (and optional indented child lines) and most nodes map
Expand Down

0 comments on commit 6358e98

Please sign in to comment.