packages feed

pandoc-link-context 1.0.0.0 → 1.2.0.0

raw patch · 3 files changed

+19/−11 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Text.Pandoc.LinkContext: queryLinksWithContext :: Pandoc -> Map Url [Block]
+ Text.Pandoc.LinkContext: queryLinksWithContext :: Pandoc -> Map Url (NonEmpty ([OtherAttr], [Block]))

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for pandoc-link-context +## 1.2.0.0++- Include Link attributes (excluded id/class) in results +- Allow mulitple links using the same Url+ ## 1.0.0.0  * First version. Released on an unsuspecting world.
@@ -1,6 +1,6 @@ cabal-version:      2.2 name:               pandoc-link-context-version:            1.0.0.0+version:            1.2.0.0 synopsis:           Extract "contextual links" from Pandoc description:        A library to pull out all links with their surrounding context in your Pandoc documents. Useful for software dealing with wiki-links and Zettelkasten. category:           Text
src/Text/Pandoc/LinkContext.hs view
@@ -8,20 +8,22 @@  type Url = Text +-- | Attributes other than id and class+type OtherAttr = (Text, Text)+ -- | Query the pandoc document for all links -- -- Return a map, containing the "surrounding context" (as Pandoc blocks) for -- each link.-queryLinksWithContext :: Pandoc -> Map Url [Block]+queryLinksWithContext :: Pandoc -> Map Url (NonEmpty ([OtherAttr], [Block])) queryLinksWithContext =-  fmap nub+  fmap (fmap $ second nub)     . Map.fromListWith (<>)-    . fmap (second one)     . W.query go   where-    go :: Block -> [(Url, Block)]+    go :: Block -> [(Url, NonEmpty ([OtherAttr], [Block]))]     go blk =-      fmap (,blk) $ case blk of+      fmap (\(url, attr) -> (url, one (attr, [blk]))) $ case blk of         B.Para is ->           queryLinkUrls is         B.Plain is ->@@ -37,16 +39,17 @@             xs <&> \(is, bss) ->               let def = queryLinkUrls is                   body = fmap (fmap (fmap fst . go)) bss-               in def <> concat (concat body)+               in def <> fmap (,[]) (concat (concat body))         _ -> mempty -    queryLinkUrls :: W.Walkable Inline b => b -> [Url]+    queryLinkUrls :: W.Walkable Inline b => b -> [(Url, [OtherAttr])]     queryLinkUrls =       W.query (maybeToList . getLinkUrl) -    getLinkUrl :: Inline -> Maybe Url+    getLinkUrl :: Inline -> Maybe (Url, [OtherAttr])     getLinkUrl = \case-      Link _attr _inlines (url, _title) -> do-        pure url+      Link (_, _, attrs) _inlines (url, title) -> do+        -- Put title in attrs, as it *is* an attribute+        pure (url, ("title", title) : attrs)       _ ->         Nothing