heist-extra 0.2.0.0 → 0.3.0.0
raw patch · 8 files changed
+41/−36 lines, 8 filesdep ~basedep ~pandoc-typesPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, pandoc-types
API changes (from Hackage documentation)
- Heist.Extra.Splices.Tree: treeSplice :: forall a sortKey. Ord sortKey => (NonEmpty a -> sortKey) -> [Tree a] -> (NonEmpty a -> [Tree a] -> Splices (Splice Identity)) -> Splice Identity
+ Heist.Extra.Splices.Tree: treeSplice :: forall a sortKey. Ord sortKey => (NonEmpty a -> [Tree a] -> sortKey) -> [Tree a] -> (NonEmpty a -> [Tree a] -> Splices (Splice Identity)) -> Splice Identity
Files
- CHANGELOG.md +6/−0
- README.md +2/−2
- heist-extra.cabal +4/−4
- src/Heist/Extra.hs +2/−2
- src/Heist/Extra/Splices/List.hs +2/−2
- src/Heist/Extra/Splices/Pandoc/Footnotes.hs +2/−2
- src/Heist/Extra/Splices/Pandoc/Render.hs +15/−18
- src/Heist/Extra/Splices/Tree.hs +8/−6
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for heist-extra +## 0.3.0.0 (2023-08-09)++- `treeSplice`: pass children to sortKey function (#2)+- Remove video format hack (#4)+- Require `pandoc-types >= 1.23` (adds `Figure` block support)+ ## 0.2.0.0 (2022-11-14) - Drop `heist-emanote`, and depend instead of the updated `heist` package.
README.md view
@@ -2,7 +2,7 @@ [](https://hackage.haskell.org/package/heist-extra) -Extensions on top of [heist](https://srid.ca/heist-start), that are especially useful for [Ema](https://ema.srid.ca/) apps.+Extra functionality for [heist](https://srid.ca/heist-start) that are especially useful for [Ema](https://ema.srid.ca/) apps. ## Getting Started @@ -15,4 +15,4 @@ | Example | Use cases | | ------------------------------------------ | ------------------------------------------ | | https://github.com/EmaApps/timedot-invoice | Template file management |-| https://github.com/EmaApps/emanote | Template file management; Pandoc rendering |+| https://github.com/srid/emanote | Template file management; Pandoc rendering |
heist-extra.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: heist-extra-version: 0.2.0.0+version: 0.3.0.0 license: MIT copyright: 2022 Sridhar Ratnakumar maintainer: srid@srid.ca@@ -12,9 +12,9 @@ bug-reports: https://github.com/srid/heist-extra extra-source-files:+ CHANGELOG.md LICENSE README.md- CHANGELOG.md common shared ghc-options:@@ -69,13 +69,13 @@ ViewPatterns build-depends:- , base >=4.13.0.0 && <=4.18.0.0+ , base >=4.13.0.0 && <4.18.0.0.0 , data-default , filepath , heist >=1.1.1.0 , map-syntax , mtl- , pandoc-types+ , pandoc-types >=1.23 , relude >=1.0 , xmlhtml
src/Heist/Extra.hs view
@@ -13,8 +13,8 @@ HI.runNode node <&> \case [resNode] | X.elementTag resNode == X.elementTag node ->- -- Get rid of the `node` itself.- X.elementChildren resNode+ -- Get rid of the `node` itself.+ X.elementChildren resNode res -> res
src/Heist/Extra/Splices/List.hs view
@@ -10,6 +10,6 @@ if null xs then pure mempty else HI.runChildrenWith $ do- childTag- ## (HI.runChildrenWith . childSplice)+ childTag ##+ (HI.runChildrenWith . childSplice) `foldMapM` xs
src/Heist/Extra/Splices/Pandoc/Footnotes.hs view
@@ -36,8 +36,8 @@ let footnotesWithIdx = zip [1 :: Int ..] fs Just $ runCustomNode renderNode $ do- "footnote"- ## (HI.runChildrenWith . uncurry (footnoteSplices ctx)) `foldMapM` footnotesWithIdx+ "footnote" ##+ (HI.runChildrenWith . uncurry (footnoteSplices ctx)) `foldMapM` footnotesWithIdx footnoteSplices :: RenderCtx -> Int -> [B.Block] -> H.Splices (HI.Splice Identity) footnoteSplices ctx idx bs = do
src/Heist/Extra/Splices/Pandoc/Render.hs view
@@ -56,21 +56,12 @@ one . X.Element "div" (rpAttr $ bAttr b) $ one . X.Element "pre" mempty $ one . X.Element "code" (rpAttr (id', classes, attrs)) $- one $ X.TextNode s+ one $+ X.TextNode s B.RawBlock (B.Format fmt) s -> do pure $ case fmt of "html" -> rawNode "div" s- "video" ->- -- HACK format. TODO: replace with ![[foo.mp4]]- one . X.Element "video" [("autoplay", ""), ("loop", ""), ("muted", "")] $- one . X.Element "source" [("src", T.strip s)] $- one . X.Element "p" mempty $- [ X.TextNode "Your browser doesn't support HTML5 video. Here is a "- , X.Element "a" [("href", T.strip s)] $- one . X.TextNode $ "link to the video"- , X.TextNode " instead."- ] _ -> one . X.Element "pre" [("class", "pandoc-raw-" <> show fmt)] $ one . X.TextNode $ s B.BlockQuote bs ->@@ -123,8 +114,9 @@ B.Div attr bs -> one . X.Element (getTag "div" attr) (rpAttr $ rewriteClass ctx attr) <$> foldMapM (rpBlock ctx) bs- B.Null ->- pure []+ B.Figure attr _caption bs ->+ -- TODO: support caption+ one . X.Element "figure" (rpAttr attr) <$> foldMapM (rpBlock ctx) bs where getTag defaultTag (_, _, Map.fromList -> attrs) = Map.lookup "tag" attrs & fromMaybe defaultTag@@ -194,7 +186,8 @@ B.Code attr s -> pure $ one . X.Element "code" (rpAttr $ concatAttr attr $ iAttr i) $- one . X.TextNode $ s+ one . X.TextNode $+ s B.Space -> pure $ one . X.TextNode $ " " B.SoftBreak -> pure $ one . X.TextNode $ " " B.LineBreak ->@@ -205,17 +198,20 @@ else pure $ one . X.Element "pre" [("class", "pandoc-raw-" <> show fmt)] $- one . X.TextNode $ s+ one . X.TextNode $+ s B.Math mathType s -> case mathType of B.InlineMath -> pure $ one . X.Element "span" [("class", "math inline")] $- one . X.TextNode $ "\\(" <> s <> "\\)"+ one . X.TextNode $+ "\\(" <> s <> "\\)" B.DisplayMath -> pure $ one . X.Element "span" [("class", "math display")] $- one . X.TextNode $ "$$" <> s <> "$$"+ one . X.TextNode $+ "$$" <> s <> "$$" B.Link attr is (url, tit) -> do let attrs = catMaybes [Just ("href", url), guard (not $ T.null tit) >> pure ("title", tit)]@@ -272,7 +268,8 @@ rawNode :: Text -> Text -> [X.Node] rawNode wrapperTag s = one . X.Element wrapperTag (one ("xmlhtmlRaw", "")) $- one . X.TextNode $ s+ one . X.TextNode $+ s -- | Convert Pandoc AST inlines to raw text. plainify :: [B.Inline] -> Text
src/Heist/Extra/Splices/Tree.hs view
@@ -10,7 +10,7 @@ forall a sortKey. (Ord sortKey) => -- | How to sort children- (NonEmpty a -> sortKey) ->+ (NonEmpty a -> [Tree a] -> sortKey) -> -- | Input tree [Tree a] -> -- | How to render a (sub-)tree root@@ -19,14 +19,16 @@ treeSplice = go [] where- go :: [a] -> (NonEmpty a -> sortKey) -> [Tree a] -> (NonEmpty a -> [Tree a] -> H.Splices (HI.Splice Identity)) -> HI.Splice Identity+ go :: [a] -> (NonEmpty a -> [Tree a] -> sortKey) -> [Tree a] -> (NonEmpty a -> [Tree a] -> H.Splices (HI.Splice Identity)) -> HI.Splice Identity go pars sortKey trees childSplice = do let extendPars x = maybe (one x) (<> one x) $ nonEmpty pars- flip foldMapM (sortOn (sortKey . extendPars . rootLabel) trees) $ \(Node lbl children) -> do+ nodeKey x = sortKey (extendPars $ rootLabel x) (subForest x)+ flip foldMapM (sortOn nodeKey trees) $ \(Node lbl children) -> do HI.runChildrenWith $ do let herePath = extendPars lbl childSplice herePath children "has-children" ## Heist.ifElseISplice (not . null $ children)- let childrenSorted = sortOn (sortKey . (herePath <>) . one . rootLabel) children- "children"- ## go (toList herePath) sortKey childrenSorted childSplice+ let childKey x = sortKey (herePath <> one (rootLabel x)) (subForest x)+ childrenSorted = sortOn childKey children+ "children" ##+ go (toList herePath) sortKey childrenSorted childSplice