Skip to content

Commit

Permalink
Fix pause-after-list issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Feb 4, 2025
1 parent ae98245 commit d75c133
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 45 deletions.
61 changes: 46 additions & 15 deletions lib/Patat/Presentation/Fragment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ splitOnThreeDots blocks = case break (== threeDots) blocks of

fragmentBlocks
:: FragmentSettings -> [Block] -> FragmentM [Block]
fragmentBlocks fs blocks = case splitOnThreeDots blocks of
[] -> pure []
[_] -> concat <$> traverse (fragmentBlock fs) blocks
sections0@(_ : _) -> do
counterID <- CounterID <$> state freshUnique
sections1 <- traverse (fragmentBlocks fs) sections0
let pauses = length sections1 - 1
triggers = case sections1 of
[] -> replicate pauses counterID
(sh : st) -> blocksTriggers sh ++
[c | s <- st, c <- counterID : blocksTriggers s]
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
triggers
[(S.fromList [i .. pauses], s) | (i, s) <- zip [0 ..] sections1]
fragmentBlocks fs blocks = (>>= fragmentAgainAfterLists) $
case splitOnThreeDots blocks of
[] -> pure []
[_] -> concat <$> traverse (fragmentBlock fs) blocks
sections0@(_ : _) -> do
counterID <- CounterID <$> state freshUnique
sections1 <- traverse (fragmentBlocks fs) sections0
let pauses = length sections1 - 1
triggers = case sections1 of
[] -> replicate pauses counterID
(sh : st) -> blocksTriggers sh ++
[c | s <- st, c <- counterID : blocksTriggers s]
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
triggers
[(S.fromList [i .. pauses], s) | (i, s) <- zip [0 ..] sections1]

fragmentBlock :: FragmentSettings -> Block -> FragmentM [Block]
fragmentBlock _fs (Para inlines) = pure [Para inlines]
Expand Down Expand Up @@ -125,3 +126,33 @@ fragmentList fs fragmentThisList fw items0 = do
[ (S.fromList [i .. pauses], s)
| (i, s) <- zip [1 ..] items1
]

-- Insert a final pause after any incremental lists. This needs to happen
-- on the list containing these blocks.
fragmentAgainAfterLists :: [Block] -> FragmentM [Block]
fragmentAgainAfterLists blocks = case splitAfterLists [] blocks of
[] -> pure []
[_] -> pure blocks
sections@(_ : _) -> do
counterID <- CounterID <$> state freshUnique
let pauses = length sections - 1
triggers = init
-- Use init to skip the final counter (we don't want to add
-- a pause at the very end since everything is displayed at
-- that point).
[c | s <- sections, c <- blocksTriggers s ++ [counterID]]
pure $ pure $ Fragmented ConcatWrapper $ Fragment
counterID
triggers
[(S.fromList [i .. pauses + 1], s) | (i, s) <- zip [0 ..] sections]
where
splitAfterLists :: [Block] -> [Block] -> [[Block]]
splitAfterLists acc [] = [reverse acc]
splitAfterLists acc (b@(Fragmented w _) : bs)
| isListWrapper w, not (null bs) =
reverse (b : acc) : splitAfterLists [] bs
splitAfterLists acc (b : bs) = splitAfterLists (b : acc) bs

isListWrapper BulletListWrapper = True
isListWrapper (OrderedListWrapper _) = True
isListWrapper ConcatWrapper = False
16 changes: 14 additions & 2 deletions tests/golden/inputs/margins01.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
title: 'Installing software'
patat:
incrementalLists: true
margins:
Expand All @@ -10,7 +9,8 @@ patat:

# Introduction

Make sure to note the difference in between using a fragment or not.
Make sure there is no difference in between using a fragment at the end
of a list, or not. This test case also tests margins very well.

# Entirely fragmented

Expand All @@ -33,3 +33,15 @@ Hahaha!

- Here is
- A second list

# Extra stuff at end

1. This is
2. An ordered list

Hahaha!

- Here is
- A second list

Extra stuff
27 changes: 27 additions & 0 deletions tests/golden/outputs/fragments02.md.dump
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,33 @@



 3 / 3 

{fragment}
 fragments02.md 

# Slide 3

 - A simple list
 - And two
 - And three

















 3 / 3 

{fragment}
Expand Down
Loading

0 comments on commit d75c133

Please sign in to comment.