pandoc-types 1.12.4.7 → 1.16
raw patch · 6 files changed
+81/−33 lines, 6 files
Files
- Text/Pandoc/Builder.hs +51/−15
- Text/Pandoc/Definition.hs +3/−2
- Text/Pandoc/Generic.hs +1/−1
- Text/Pandoc/Walk.hs +20/−14
- changelog +4/−0
- pandoc-types.cabal +2/−1
Text/Pandoc/Builder.hs view
@@ -58,7 +58,7 @@ > [Para [Str "item",Space,Str "one"] > ,Para [Str "continuation"]] > ,[Plain [Str "item",Space,Str "two",Space,Str "and",Space,-> Str "a",Space,Link [Str "link"] ("/url","go to url")]]]]+> Str "a",Space,Link nullAttr [Str "link"] ("/url","go to url")]]]] And of course, you can use Haskell to define your own builders: @@ -117,12 +117,15 @@ , codeWith , code , space+ , softbreak , linebreak , math , displayMath , rawInline , link+ , linkWith , image+ , imageWith , note , spanWith , trimInlines@@ -203,6 +206,8 @@ (xs' :> x, y :< ys') -> Many (meld `mappend` ys') where meld = case (x, y) of (Space, Space) -> xs' |> Space+ (Space, SoftBreak) -> xs' |> SoftBreak+ (SoftBreak, Space) -> xs' |> SoftBreak (Str t1, Str t2) -> xs' |> Str (t1 <> t2) (Emph i1, Emph i2) -> xs' |> Emph (i1 <> i2) (Strong i1, Strong i2) -> xs' |> Strong (i1 <> i2)@@ -210,23 +215,30 @@ (Superscript i1, Superscript i2) -> xs' |> Superscript (i1 <> i2) (Strikeout i1, Strikeout i2) -> xs' |> Strikeout (i1 <> i2) (Space, LineBreak) -> xs' |> LineBreak+ (LineBreak, Space) -> xs' |> LineBreak+ (SoftBreak, LineBreak) -> xs' |> LineBreak+ (LineBreak, SoftBreak) -> xs' |> LineBreak+ (SoftBreak, SoftBreak) -> xs' |> SoftBreak _ -> xs' |> x |> y instance IsString Inlines where fromString = text --- | Trim leading and trailing Sp (spaces) from an Inlines.+-- | Trim leading and trailing spaces and softbreaks from an Inlines. trimInlines :: Inlines -> Inlines #if MIN_VERSION_containers(0,4,0)-trimInlines (Many ils) = Many $ Seq.dropWhileL (== Space) $- Seq.dropWhileR (== Space) $ ils+trimInlines (Many ils) = Many $ Seq.dropWhileL isSp $+ Seq.dropWhileR isSp $ ils #else -- for GHC 6.12, we need to workaround a bug in dropWhileR -- see http://hackage.haskell.org/trac/ghc/ticket/4157-trimInlines (Many ils) = Many $ Seq.dropWhileL (== Space) $- Seq.reverse $ Seq.dropWhileL (== Space) $+trimInlines (Many ils) = Many $ Seq.dropWhileL isSp $+ Seq.reverse $ Seq.dropWhileL isSp $ Seq.reverse ils #endif+ where isSp Space = True+ isSp SoftBreak = True+ isSp _ = False -- Document builders @@ -279,19 +291,26 @@ -- Inline list builders --- | Convert a 'String' to 'Inlines', treating interword spaces as 'Space's.--- If you want a 'Str' with literal spaces, use 'str'.+-- | Convert a 'String' to 'Inlines', treating interword spaces as 'Space's+-- or 'SoftBreak's. If you want a 'Str' with literal spaces, use 'str'. text :: String -> Inlines text = fromList . map conv . breakBySpaces where breakBySpaces = groupBy sameCategory sameCategory x y = (is_space x && is_space y) || (not $ is_space x || is_space y)- conv xs | all is_space xs = Space+ conv xs | all is_space xs =+ if any is_newline xs+ then SoftBreak+ else Space conv xs = Str xs- is_space ' ' = True- is_space '\n' = True- is_space '\t' = True- is_space _ = False+ is_space ' ' = True+ is_space '\r' = True+ is_space '\n' = True+ is_space '\t' = True+ is_space _ = False+ is_newline '\r' = True+ is_newline '\n' = True+ is_newline _ = False str :: String -> Inlines str = singleton . Str@@ -337,6 +356,9 @@ space :: Inlines space = singleton Space +softbreak :: Inlines+softbreak = singleton SoftBreak+ linebreak :: Inlines linebreak = singleton LineBreak @@ -355,13 +377,27 @@ -> String -- ^ Title -> Inlines -- ^ Label -> Inlines-link url title x = singleton $ Link (toList x) (url, title)+link = linkWith nullAttr +linkWith :: Attr -- ^ Attributes+ -> String -- ^ URL+ -> String -- ^ Title+ -> Inlines -- ^ Label+ -> Inlines+linkWith attr url title x = singleton $ Link attr (toList x) (url, title)+ image :: String -- ^ URL -> String -- ^ Title -> Inlines -- ^ Alt text -> Inlines-image url title x = singleton $ Image (toList x) (url, title)+image = imageWith nullAttr++imageWith :: Attr -- ^ Attributes+ -> String -- ^ URL+ -> String -- ^ Title+ -> Inlines -- ^ Alt text+ -> Inlines+imageWith attr url title x = singleton $ Image attr (toList x) (url, title) note :: Blocks -> Inlines note = singleton . Note . toList
Text/Pandoc/Definition.hs view
@@ -233,11 +233,12 @@ | Cite [Citation] [Inline] -- ^ Citation (list of inlines) | Code Attr String -- ^ Inline code (literal) | Space -- ^ Inter-word space+ | SoftBreak -- ^ Soft line break | LineBreak -- ^ Hard line break | 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+ | Link Attr [Inline] Target -- ^ Hyperlink: 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)
Text/Pandoc/Generic.hs view
@@ -94,7 +94,7 @@ > extractURL :: Inline -> [String] > extractURL (Link _ (u,_)) = [u]-> extractURL (Image _ (u,_)) = [u]+> extractURL (Image _ _ (u,_)) = [u] > extractURL _ = [] > > extractURLs :: Pandoc -> [String]
Text/Pandoc/Walk.hs view
@@ -55,8 +55,8 @@ linked to in a document: > extractURL :: Inline -> [String]-> extractURL (Link _ (u,_)) = [u]-> extractURL (Image _ (u,_)) = [u]+> extractURL (Link _ _ (u,_)) = [u]+> extractURL (Image _ _ (u,_)) = [u] > extractURL _ = [] > > extractURLs :: Pandoc -> [String]@@ -111,11 +111,12 @@ walk f (Cite cs xs) = f $ Cite (walk f cs) (walk f xs) walk f (Code attr s) = f $ Code attr s walk f Space = f Space+ walk f SoftBreak = f SoftBreak walk f LineBreak = f LineBreak 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 (Link atr xs t) = f $ Link atr (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) @@ -132,11 +133,12 @@ f $ Cite cs' xs' walkM f (Code attr s) = f $ Code attr s walkM f Space = f Space+ walkM f SoftBreak = f SoftBreak walkM f LineBreak = f LineBreak 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 (Link atr xs t) = Link atr <$> 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 @@ -151,11 +153,12 @@ query f (Cite cs xs) = f (Cite cs xs) <> query f cs <> query f xs query f (Code attr s) = f (Code attr s) query f Space = f Space+ query f SoftBreak = f SoftBreak query f LineBreak = f LineBreak 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 (Link atr xs t) = f (Link atr 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 @@ -266,11 +269,12 @@ walk f (Cite cs xs) = Cite (walk f cs) (walk f xs) walk f (Code attr s) = Code attr s walk f Space = Space+ walk f SoftBreak = SoftBreak walk f LineBreak = LineBreak 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 (Link atr xs t) = Link atr (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) @@ -287,11 +291,12 @@ return $ Cite cs' xs' walkM f (Code attr s) = return $ Code attr s walkM f Space = return $ Space+ walkM f SoftBreak = return $ SoftBreak walkM f LineBreak = return $ LineBreak 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 (Link atr xs t) = (\lab -> Link atr 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 @@ -306,11 +311,12 @@ query f (Cite cs xs) = query f cs <> query f xs query f (Code attr s) = mempty query f Space = mempty+ query f SoftBreak = mempty query f LineBreak = mempty 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 (Link atr 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
+ changelog view
@@ -0,0 +1,4 @@+[1.16]++* Added Attr field to Image and Link.+* Added SoftBreak constructor to Inline
pandoc-types.cabal view
@@ -1,5 +1,5 @@ Name: pandoc-types-Version: 1.12.4.7+Version: 1.16 Synopsis: Types for representing a structured document Description: @Text.Pandoc.Definition@ defines the 'Pandoc' data structure, which is used by pandoc to represent@@ -32,6 +32,7 @@ Category: Text Build-type: Simple Cabal-version: >=1.6+Extra-Source-Files: changelog Source-repository head type: git location: git://github.com/jgm/pandoc-types.git