Skip to content

Commit

Permalink
image attributes, pandoc #261
Browse files Browse the repository at this point in the history
  • Loading branch information
mb21 committed Jul 25, 2015
1 parent f9db313 commit 545a57e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
21 changes: 19 additions & 2 deletions Text/Pandoc/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ module Text.Pandoc.Builder ( module Text.Pandoc.Definition
, displayMath
, rawInline
, link
, linkWith
, image
, imageWith
, note
, spanWith
, trimInlines
Expand Down Expand Up @@ -355,13 +357,28 @@ link :: String -- ^ URL
-> String -- ^ Title
-> Inlines -- ^ Label
-> Inlines
link url title x = singleton $ Link (toList x) (url, title)
link url title = linkWith url title nullAttr

linkWith :: String -- ^ URL
-> String -- ^ Title
-> Attr -- ^ attributes, currenlty ignored
-> Inlines -- ^ Label
-> Inlines
linkWith url title _ x = singleton $ Link (toList x) (url, title)

image :: String -- ^ URL
-> String -- ^ Title
-> Inlines -- ^ Alt text
-> Inlines
image url title x = singleton $ Image (toList x) (url, title)
image url title = imageWith url title nullAttr

imageWith :: String -- ^ URL
-> String -- ^ Title
-> Attr -- ^ attributes
-> Inlines -- ^ Alt text
-> Inlines
imageWith url title attr x =
singleton $ Image attr (toList x) (url, title)

note :: Blocks -> Inlines
note = singleton . Note . toList
Expand Down
2 changes: 1 addition & 1 deletion Text/Pandoc/Definition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ data Inline
| Math MathType String -- ^ TeX math (literal)
| RawInline Format String -- ^ Raw inline
| Link [Inline] Target -- ^ Hyperlink: text (list of inlines), target
| Image [Inline] Target -- ^ Image: alt text (list of inlines), target
| Image Attr [Inline] Target -- ^ Image: alt text (list of inlines), target
| Note [Block] -- ^ Footnote or endnote
| Span Attr [Inline] -- ^ Generic inline container with attributes
deriving (Show, Eq, Ord, Read, Typeable, Data, Generic)
Expand Down
2 changes: 1 addition & 1 deletion Text/Pandoc/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ linked to in a document:
> extractURL :: Inline -> [String]
> extractURL (Link _ (u,_)) = [u]
> extractURL (Image _ (u,_)) = [u]
> extractURL (Image _ _ (u,_)) = [u]
> extractURL _ = []
>
> extractURLs :: Pandoc -> [String]
Expand Down
14 changes: 7 additions & 7 deletions Text/Pandoc/Walk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ linked to in a document:
> extractURL :: Inline -> [String]
> extractURL (Link _ (u,_)) = [u]
> extractURL (Image _ (u,_)) = [u]
> extractURL (Image _ _ (u,_)) = [u]
> extractURL _ = []
>
> extractURLs :: Pandoc -> [String]
Expand Down Expand Up @@ -115,7 +115,7 @@ instance Walkable Inline Inline where
walk f (Math mt s) = f (Math mt s)
walk f (RawInline t s) = f $ RawInline t s
walk f (Link xs t) = f $ Link (walk f xs) t
walk f (Image xs t) = f $ Image (walk f xs) t
walk f (Image atr xs t) = f $ Image atr (walk f xs) t
walk f (Note bs) = f $ Note (walk f bs)
walk f (Span attr xs) = f $ Span attr (walk f xs)

Expand All @@ -136,7 +136,7 @@ instance Walkable Inline Inline where
walkM f (Math mt s) = f (Math mt s)
walkM f (RawInline t s) = f $ RawInline t s
walkM f (Link xs t) = Link <$> walkM f xs >>= f . ($ t)
walkM f (Image xs t) = Image <$> walkM f xs >>= f . ($ t)
walkM f (Image atr xs t)= Image atr <$> walkM f xs >>= f . ($ t)
walkM f (Note bs) = Note <$> walkM f bs >>= f
walkM f (Span attr xs) = Span attr <$> walkM f xs >>= f

Expand All @@ -155,7 +155,7 @@ instance Walkable Inline Inline where
query f (Math mt s) = f (Math mt s)
query f (RawInline t s) = f (RawInline t s)
query f (Link xs t) = f (Link xs t) <> query f xs
query f (Image xs t) = f (Image xs t) <> query f xs
query f (Image atr xs t)= f (Image atr xs t) <> query f xs
query f (Note bs) = f (Note bs) <> query f bs
query f (Span attr xs) = f (Span attr xs) <> query f xs

Expand Down Expand Up @@ -270,7 +270,7 @@ instance Walkable Block Inline where
walk f (Math mt s) = Math mt s
walk f (RawInline t s) = RawInline t s
walk f (Link xs t) = Link (walk f xs) t
walk f (Image xs t) = Image (walk f xs) t
walk f (Image atr xs t)= Image atr (walk f xs) t
walk f (Note bs) = Note (walk f bs)
walk f (Span attr xs) = Span attr (walk f xs)

Expand All @@ -291,7 +291,7 @@ instance Walkable Block Inline where
walkM f (Math mt s) = return $ Math mt s
walkM f (RawInline t s) = return $ RawInline t s
walkM f (Link xs t) = (\lab -> Link lab t) <$> walkM f xs
walkM f (Image xs t) = (\lab -> Image lab t) <$> walkM f xs
walkM f (Image atr xs t)= (\lab -> Image atr lab t) <$> walkM f xs
walkM f (Note bs) = Note <$> walkM f bs
walkM f (Span attr xs) = Span attr <$> walkM f xs

Expand All @@ -310,7 +310,7 @@ instance Walkable Block Inline where
query f (Math mt s) = mempty
query f (RawInline t s) = mempty
query f (Link xs t) = query f xs
query f (Image xs t) = query f xs
query f (Image atr xs t)= query f xs
query f (Note bs) = query f bs
query f (Span attr xs) = query f xs

Expand Down
2 changes: 1 addition & 1 deletion pandoc-types.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: pandoc-types
Version: 1.12.4
Version: 1.14
Synopsis: Types for representing a structured document
Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data
structure, which is used by pandoc to represent
Expand Down

0 comments on commit 545a57e

Please sign in to comment.