diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# pandoc-crossref filter ![](https://travis-ci.org/lierdakil/pandoc-crossref.svg?branch=master)
+# pandoc-crossref filter [![Build Status](https://travis-ci.org/lierdakil/pandoc-crossref.svg?branch=master)](https://travis-ci.org/lierdakil/pandoc-crossref)
 
 pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 
@@ -23,7 +23,7 @@
 [lpdf]: http://lierdakil.github.io/pandoc-crossref/output-listings.pdf
 
 
-Tested with pandoc 1.13.2 and 1.14.
+Tested with Pandoc from 1.13.2 to 1.16.0.
 
 This work is inspired by [pandoc-fignos][1] and [pandoc-eqnos][2] by @tomduck.
 
@@ -46,7 +46,7 @@
 
 This only works on implicit figures, i.e. an image occurring by itself in a paragraph (which will be rendered as a figure with caption by pandoc)
 
-Image block and label *can* be separated by one or more spaces.
+Image block and label *can not* be separated by spaces.
 
 ### Equation labels
 
@@ -56,8 +56,6 @@
 
 To label a display equation, append `{#eq:label}` (with `label` being something unique to reference this equation by) immediately after math block.
 
-This only works if display math and label specification are in a paragraph of its own.
-
 Math block and label *can* be separated by one or more spaces.
 
 ### Table labels
@@ -195,7 +193,7 @@
 
 `pandoc --filter pandoc-crossref`
 
-If you installed with cabal, it's most likely located in `$HOME/.cabal/bin` on \*NIX systems, or in `%AppData%\cabal\bin` on Windows.
+If you installed with cabal, it's most likely located in `$HOME/.cabal/bin` on \*NIX systems, `$HOME/Library/Haskell/bin` on Macs, or in `%AppData%\cabal\bin` on Windows.
 
 ### Customization
 
@@ -235,7 +233,7 @@
   - "figs."
 ```
 
-Will result in all single-value references prefixed with "fig.", and all reference groups of two and more prefixed with "figs.":
+Will result in all single-value references prefixed with "fig.", and all reference groups of two and more will be prefixed with "figs.":
 
 ```markdown
 [@fig:one] -> fig. 1
diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal
--- a/pandoc-crossref.cabal
+++ b/pandoc-crossref.cabal
@@ -2,7 +2,7 @@
 -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                pandoc-crossref
-version:             0.1.6.0
+version:             0.1.6.2
 synopsis:            Pandoc filter for cross-references
 description:         pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 license:             GPL-2
@@ -24,7 +24,7 @@
 source-repository this
   type: git
   location: https://github.com/lierdakil/pandoc-crossref
-  tag: v0.1.6.0
+  tag: v0.1.6.2
 
 library
   exposed-modules:     Text.Pandoc.CrossRef
@@ -46,10 +46,10 @@
                      , Text.Pandoc.CrossRef.Util.Settings.Template
                      , Text.Pandoc.CrossRef.Util.Gap
   build-depends:       base >=4.2 && <5
-                     , pandoc >= 1.13 && <1.16
+                     , pandoc >= 1.13 && <1.17
                      , mtl >= 1.1 && <2.3
                      , containers >= 0.1 && <0.6
-                     , pandoc-types >= 1.12.4.1 && < 1.13
+                     , pandoc-types >= 1.12.4.1 && < 1.17
                      , yaml >= 0.8 && <0.9
                      , data-default >= 0.4 && <0.6
                      , bytestring >=0.9 && <0.11
@@ -63,10 +63,10 @@
 executable pandoc-crossref
   main-is:             pandoc-crossref.hs
   build-depends:       base >=4.2 && <5
-                     , pandoc >= 1.13 && <1.16
+                     , pandoc >= 1.13 && <1.17
                      , mtl >= 1.1 && <2.3
                      , containers >= 0.1 && <0.6
-                     , pandoc-types >= 1.12.4.1 && < 1.13
+                     , pandoc-types >= 1.12.4.1 && < 1.17
                      , yaml >= 0.8 && <0.9
                      , data-default >= 0.4 && <0.6
                      , bytestring >=0.9 && <0.11
@@ -80,15 +80,15 @@
   Main-Is:        test-pandoc-crossref.hs
   hs-source-dirs: test, src
   Build-Depends:   base >=4.2 && <5
-                 , pandoc >= 1.13 && <1.16
+                 , pandoc >= 1.13 && <1.17
                  , mtl >= 1.1 && <2.3
                  , containers >= 0.1 && <0.6
-                 , pandoc-types >= 1.12.4.1 && < 1.13
+                 , pandoc-types >= 1.12.4.1 && < 1.17
                  , yaml >= 0.8 && <0.9
                  , data-default >= 0.4 && <0.6
                  , bytestring >=0.9 && <0.11
                  , hspec
-                 , process >=1 && <1.3
+                 , process >=1 && <1.5
                  , pandoc-crossref
   other-modules: Native
   Ghc-Options:  -rtsopts -Wall -fno-warn-unused-do-bind -threaded
diff --git a/src/Text/Pandoc/CrossRef/References/Blocks.hs b/src/Text/Pandoc/CrossRef/References/Blocks.hs
--- a/src/Text/Pandoc/CrossRef/References/Blocks.hs
+++ b/src/Text/Pandoc/CrossRef/References/Blocks.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
 module Text.Pandoc.CrossRef.References.Blocks
   ( divBlocks
   , replaceBlocks
@@ -37,6 +38,8 @@
         in r{curChap=cc'}
       when ("sec:" `isPrefixOf` label') $ replaceAttrSec label' text' secRefs'
     return $ Header n (label', cls, attrs) text'
+#if MIN_VERSION_pandoc(1,16,0)
+#else
 replaceBlocks opts (Div (label,_,attrs) [Plain [Image alt img]])
   | "fig:" `isPrefixOf` label
   = do
@@ -46,6 +49,7 @@
             RawInline (Format "tex") ("\\label{"++label++"}") : alt
           _  -> applyTemplate idxStr alt $ figureTemplate opts
     return $ Para [Image alt' img]
+#endif
 replaceBlocks opts (Div (label,_,attrs) [Table title align widths header cells])
   | not $ null title
   , "tbl:" `isPrefixOf` label
@@ -119,12 +123,27 @@
         idxStr <- replaceAttr opts label (lookup "label" attrs) [] eqnRefs'
         let eq' = eq++"\\qquad("++stringify idxStr++")"
         return $ Math DisplayMath eq' : ils'
+#if MIN_VERSION_pandoc(1,16,0)
+replaceInlines opts (Image attr@(label,_,attrs) alt img:ils')
+  | "fig:" `isPrefixOf` label, "fig:" `isPrefixOf` snd img
+  = do
+    idxStr <- replaceAttr opts label (lookup "label" attrs) alt imgRefs'
+    let alt' = case outFormat opts of
+          f | isFormat "latex" f ->
+            RawInline (Format "tex") ("\\label{"++label++"}") : alt
+          _  -> applyTemplate idxStr alt $ figureTemplate opts
+    return $ Image attr alt' img : ils'
+#else
+#endif
 replaceInlines _ x = return x
 
 divBlocks :: Block -> Block
+#if MIN_VERSION_pandoc(1,16,0)
+#else
 divBlocks (Para (Image alt (img, title):c))
   | Just label <- getRefLabel "fig" c
   = Div (label,[],[]) [Plain [Image alt (img, "fig:" ++ title)]]
+#endif
 divBlocks (Table title align widths header cells)
   | not $ null title
   , Just label <- getRefLabel "tbl" [last title]
diff --git a/test/Native.hs b/test/Native.hs
--- a/test/Native.hs
+++ b/test/Native.hs
@@ -1,11 +1,160 @@
+{-# LANGUAGE CPP #-}
 module Native where
 
 import Text.Pandoc.Definition
 
 demo :: [Block]
+#if MIN_VERSION_pandoc(1,16,0)
 demo =
   [Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "demo",Space,Str "file",Space,Str "for",Space,Str "pandoc-crossref.",Space,Str "With",Space,Str "this",Space,Str "filter,",Space,Str "you",Space,Str "can",Space,Str "cross-reference",Space,Str "figures",Space,Str "(see",Space,Str "figs.\160\&2-4",Str "),",Space,Str "display",Space,Str "equations",Space,Str "(see",Space,Str "eq.\160\&1",Str "),",Space,Str "tables",Space,Str "(see",Space,Str "tbl.\160\&1",Str ")",Space,Str "and",Space,Str "sections",Space,Str "(",Str "secs.\160\&1,",Space,Str "2,",Space,Str "4.1-4.3",Str ")"]
   ,Para [Str "For",Space,Str "immediate",Space,Str "example,",Space,Str "see",Space,Str "fig.\160\&1"]
+  ,Para [Image ("fig:figure0",[],[]) [Str "Figure",Space,Str "#",Space,Str "1:",Space,Str "A",Space,Str "figure"] ("img1.jpg","fig:")]
+  ,Para [Str "There",Space,Str "is",Space,Str "also",Space,Str "support",Space,Str "for",Space,Str "code",Space,Str "blocks,",Space,Str "for",Space,Str "example,",Space,Str "lsts.\160\&1-3"]
+  ,Para [Str "It's",Space,Str "possible",Space,Str "to",Space,Str "capitalize",Space,Str "reference",Space,Str "prefixes,",Space,Str "like",Space,Str "this:",Space,Str "Fig.\160\&2",Str "."]
+  ,Para [Str "In",Space,Str "case",Space,Str "of",Space,Str "multiple",Space,Str "references,",Space,Str "capitalization",Space,Str "is",Space,Str "determined",Space,Str "by",Space,Str "first",Space,Str "reference.",Space,Str "Figs.\160\&2,",Space,Str "3",Space,Str "is",Space,Str "capitalized,",Space,Str "while",Space,Str "figs.\160\&2,",Space,Str "3",Space,Str "is",Space,Str "not."]
+  ,Para [Str "It",Space,Str "is",Space,Str "also",Space,Str "possible",Space,Str "to",Space,Str "mix",Space,Str "different",Space,Str "references,",Space,Str "like",Space,Str "fig.\160\&2",Str ",",Space,Str "tbl.\160\&1",Str ",",Space,Str "lsts.\160\&1,",Space,Str "2",Str ",",Space,Str "figs.\160\&3,",Space,Str "4",Str ",",Space,Str "which",Space,Str "will",Space,Str "be",Space,Str "grouped",Space,Str "in",Space,Str "order",Space,Str "they",Space,Str "are",Space,Str "specified.",Space,Str "You",Space,Str "can",Space,Str "even",Space,Str "intermix",Space,Str "this",Space,Str "with",Space,Str "regular",Space,Str "citations,",Space,Str "although",Space,Str "it's",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&2",Str ",",Space,Str "tbl.\160\&1",Str ",",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@unprocessedCitation]"]]
+  ,Para [Str "You",Space,Str "can",Space,Str "also",Space,Str "have",Space,Str "custom",Space,Str "chapter",Space,Str "reference",Space,Str "labels,",Space,Str "like",Space,Str "sec.\160AppA.CustLab"]
+  ,Header 1 ("sec:sec1",[],[]) [Str "Chapter",Space,Str "1.",Space,Str "Figures"]
+  ,Para [Image ("fig:figure1",[],[]) [Str "Figure",Space,Str "#",Space,Str "2:",Space,Str "First",Space,Str "figure"] ("img1.jpg","fig:")]
+  ,Para [Image ("fig:figure2",[],[]) [Str "Figure",Space,Str "#",Space,Str "3:",Space,Str "Second",Space,Str "figure"] ("img2.jpg","fig:")]
+  ,Para [Image ("fig:figure3",[],[]) [Str "Figure",Space,Str "#",Space,Str "4:",Space,Str "Third",Space,Str "figure"] ("img3.jpg","fig:")]
+  ,Para [Image ("",[],[]) [Str "Unlabelled",Space,Str "image"] ("img1.jpg","fig:")]
+  ,Header 1 ("sec:sec2",[],[]) [Str "Chapter",Space,Str "2.",Space,Str "Equations"]
+  ,Para [Str "Display",Space,Str "equations",Space,Str "are",Space,Str "labelled",Space,Str "and",Space,Str "numbered"]
+  ,Para [Math DisplayMath " P_i(x) = \\sum_i a_i x^i \\qquad(1)"]
+  ,Para [Str "Since",Space,Str "0.1.6.0",Space,Str "those",Space,Str "can",Space,Str "also",Space,Str "appear",Space,Str "in",Space,Str "the",Space,Str "middle",Space,Str "of",Space,Str "paragraph",SoftBreak,Math DisplayMath "a x^2 + b x^2 + c = 0\\qquad(2)",Space,Str "like",Space,Str "this."]
+  ,Header 1 ("sec:chapter-3.-tables",[],[]) [Str "Chapter",Space,Str "3.",Space,Str "Tables"]
+  ,Table [Emph [Str "Table",Space,Str "1"],Str ":",Space,Str "Table",Space,Str "example"] [AlignLeft,AlignLeft] [0.0,0.0]
+   [[Plain [Str "First",Space,Str "Header"]]
+   ,[Plain [Str "Second",Space,Str "Header"]]]
+   [[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]
+   ,[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]]
+  ,Para [Str "Table",Space,Str "without",Space,Str "caption:"]
+  ,Table [] [AlignLeft,AlignLeft] [0.0,0.0]
+   [[Plain [Str "First",Space,Str "Header"]]
+   ,[Plain [Str "Second",Space,Str "Header"]]]
+   [[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]
+   ,[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]]
+  ,Header 1 ("sec:chapter-4.-code-blocks",[],[]) [Str "Chapter",Space,Str "4.",Space,Str "Code",Space,Str "blocks"]
+  ,Para [Str "There",Space,Str "are",Space,Str "a",Space,Str "couple",Space,Str "options",Space,Str "for",Space,Str "code",Space,Str "block",Space,Str "labels.",Space,Str "Those",Space,Str "work",Space,Str "only",Space,Str "if",Space,Str "code",Space,Str "block",Space,Str "id",Space,Str "starts",Space,Str "with",Space,Code ("",[],[]) "lst:",Str ",",Space,Str "e.g.",Space,Code ("",[],[]) "{#lst:label}"]
+  ,Header 2 ("sec:caption-attr",[],[]) [Code ("",[],[]) "caption",Space,Str "attribute"]
+  ,Para [Code ("",[],[]) "caption",Space,Str "attribute",Space,Str "will",Space,Str "be",Space,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "has",Space,Str "both",Space,Str "id",Space,Str "and",Space,Code ("",[],[]) "caption",Space,Str "attributes,",Space,Str "it",Space,Str "will",Space,Str "be",Space,Str "treated",Space,Str "as",Space,Str "numbered",Space,Str "code",Space,Str "block."]
+  ,Div ("lst:captionAttr",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "1:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Para [RawInline (Format "tex") "\\pagebreak"]
+  ,Header 2 ("sec:table-capts",[],[]) [Str "Table-style",Space,Str "captions"]
+  ,Para [Str "Enabled",Space,Str "with",Space,Code ("",[],[]) "codeBlockCaptions",Space,Str "metadata",Space,Str "option.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "is",Space,Str "immediately",SoftBreak,Str "adjacent",Space,Str "to",Space,Str "paragraph,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "Listing:",Space,Str "or",Space,Code ("",[],[]) ":",Str ",",Space,Str "said",Space,Str "paragraph",Space,Str "will",Space,Str "be",SoftBreak,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."]
+  ,Div ("lst:tableCaption",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "2:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Header 2 ("sec:wrapping-div",[],[]) [Str "Wrapping",Space,Str "div"]
+  ,Para [Str "Wrapping",Space,Str "code",Space,Str "block",Space,Str "without",Space,Str "label",Space,Str "in",Space,Str "a",Space,Str "div",Space,Str "with",Space,Str "id",Space,Code ("",[],[]) "lst:...",Space,Str "and",Space,Str "class,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "listing",Str ",",Space,Str "and",Space,Str "adding",Space,Str "paragraph",Space,Str "before",Space,Str "code",Space,Str "block,",Space,Str "but",Space,Str "inside",Space,Str "div,",Space,Str "will",Space,Str "treat",Space,Str "said",Space,Str "paragraph",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."]
+  ,Div ("lst:wrappingDiv",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "3:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Header 1 ("sec:unnumbered-chapter.",["unnumbered"],[]) [Str "Unnumbered",Space,Str "chapter."]
+  ,Para [Str "This",Space,Str "chapter",Space,Str "doesn't",Space,Str "change",Space,Str "chapter",Space,Str "prefix",Space,Str "of",Space,Str "referenced",Space,Str "elements,",Space,Str "instead",Space,Str "keeping",Space,Str "number",Space,Str "of",Space,Str "previous",Space,Str "chapter,",Space,Str "e.g.",SoftBreak,Math DisplayMath " S(x) = \\int_{x_1}^{x_2} a x+b \\  \\mathrm{d}x \\qquad(3)"]
+  ,Header 1 ("sec:chapter-5.-reference-lists",[],[]) [Str "Chapter",Space,Str "5.",Space,Str "Reference",Space,Str "lists"]
+  ,Para [Str "It's",Space,Str "also",Space,Str "possible",Space,Str "to",Space,Str "show",Space,Str "lists",Space,Str "of",Space,Str "figures",Space,Str "and",Space,Str "tables,",Space,Str "like",Space,Str "this:"]
+  ,Header 2 ("list-of-figures",[],[]) [Str "List",Space,Str "of",Space,Str "Figures"]
+  ,OrderedList (1,DefaultStyle,DefaultDelim)
+   [[Plain [Str "A",Space,Str "figure"]]
+   ,[Plain [Str "First",Space,Str "figure"]]
+   ,[Plain [Str "Second",Space,Str "figure"]]
+   ,[Plain [Str "Third",Space,Str "figure"]]]
+  ,Header 2 ("list-of-tables",[],[]) [Str "List",Space,Str "of",Space,Str "Tables"]
+  ,OrderedList (1,DefaultStyle,DefaultDelim)
+   [[Plain [Str "Table",Space,Str "example"]]]
+  ,Header 1 ("",[],[]) [Str "List",Space,Str "of",Space,Str "Listings"]
+  ,OrderedList (1,DefaultStyle,DefaultDelim)
+   [[Plain [Str "Listing",Space,Str "caption"]]
+   ,[Plain [Str "Listing",Space,Str "caption"]]
+   ,[Plain [Str "Listing",Space,Str "caption"]]]
+  ,Header 1 ("sec:appendix-a.-custom-labels",[],[("label","AppA")]) [Str "Appendix",Space,Str "A.",Space,Str "Custom",Space,Str "labels"]
+  ,Header 2 ("sec:custlabs",[],[("label","CustLab")]) [Str "This",Space,Str "section",Space,Str "will",Space,Str "have",Space,Str "custom",Space,Str "label"]]
+
+demochapters :: [Block]
+demochapters =
+  [Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "demo",Space,Str "file",Space,Str "for",Space,Str "pandoc-crossref.",Space,Str "With",Space,Str "this",Space,Str "filter,",Space,Str "you",Space,Str "can",Space,Str "cross-reference",Space,Str "figures",Space,Str "(see",Space,Str "figs.\160\&1.1-1.3",Str "),",Space,Str "display",Space,Str "equations",Space,Str "(see",Space,Str "eq.\160\&2.1",Str "),",Space,Str "tables",Space,Str "(see",Space,Str "tbl.\160\&3.1",Str ")",Space,Str "and",Space,Str "sections",Space,Str "(",Str "secs.\160\&1,",Space,Str "2,",Space,Str "4.1-4.3",Str ")"]
+  ,Para [Str "For",Space,Str "immediate",Space,Str "example,",Space,Str "see",Space,Str "fig.\160\&1"]
+  ,Para [Image ("fig:figure0",[],[]) [Str "Figure",Space,Str "#",Space,Str "1:",Space,Str "A",Space,Str "figure"] ("img1.jpg","fig:")]
+  ,Para [Str "There",Space,Str "is",Space,Str "also",Space,Str "support",Space,Str "for",Space,Str "code",Space,Str "blocks,",Space,Str "for",Space,Str "example,",Space,Str "lsts.\160\&4.1-4.3"]
+  ,Para [Str "It's",Space,Str "possible",Space,Str "to",Space,Str "capitalize",Space,Str "reference",Space,Str "prefixes,",Space,Str "like",Space,Str "this:",Space,Str "Fig.\160\&1.1",Str "."]
+  ,Para [Str "In",Space,Str "case",Space,Str "of",Space,Str "multiple",Space,Str "references,",Space,Str "capitalization",Space,Str "is",Space,Str "determined",Space,Str "by",Space,Str "first",Space,Str "reference.",Space,Str "Figs.\160\&1.1,",Space,Str "1.2",Space,Str "is",Space,Str "capitalized,",Space,Str "while",Space,Str "figs.\160\&1.1,",Space,Str "1.2",Space,Str "is",Space,Str "not."]
+  ,Para [Str "It",Space,Str "is",Space,Str "also",Space,Str "possible",Space,Str "to",Space,Str "mix",Space,Str "different",Space,Str "references,",Space,Str "like",Space,Str "fig.\160\&1.1",Str ",",Space,Str "tbl.\160\&3.1",Str ",",Space,Str "lsts.\160\&4.1,",Space,Str "4.2",Str ",",Space,Str "figs.\160\&1.2,",Space,Str "1.3",Str ",",Space,Str "which",Space,Str "will",Space,Str "be",Space,Str "grouped",Space,Str "in",Space,Str "order",Space,Str "they",Space,Str "are",Space,Str "specified.",Space,Str "You",Space,Str "can",Space,Str "even",Space,Str "intermix",Space,Str "this",Space,Str "with",Space,Str "regular",Space,Str "citations,",Space,Str "although",Space,Str "it's",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&1.1",Str ",",Space,Str "tbl.\160\&3.1",Str ",",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@unprocessedCitation]"]]
+  ,Para [Str "You",Space,Str "can",Space,Str "also",Space,Str "have",Space,Str "custom",Space,Str "chapter",Space,Str "reference",Space,Str "labels,",Space,Str "like",Space,Str "sec.\160AppA.CustLab"]
+  ,Header 1 ("sec:sec1",[],[]) [Str "Chapter",Space,Str "1.",Space,Str "Figures"]
+  ,Para [Image ("fig:figure1",[],[]) [Str "Figure",Space,Str "#",Space,Str "1.1:",Space,Str "First",Space,Str "figure"] ("img1.jpg","fig:")]
+  ,Para [Image ("fig:figure2",[],[]) [Str "Figure",Space,Str "#",Space,Str "1.2:",Space,Str "Second",Space,Str "figure"] ("img2.jpg","fig:")]
+  ,Para [Image ("fig:figure3",[],[]) [Str "Figure",Space,Str "#",Space,Str "1.3:",Space,Str "Third",Space,Str "figure"] ("img3.jpg","fig:")]
+  ,Para [Image ("",[],[]) [Str "Unlabelled",Space,Str "image"] ("img1.jpg","fig:")]
+  ,Header 1 ("sec:sec2",[],[]) [Str "Chapter",Space,Str "2.",Space,Str "Equations"]
+  ,Para [Str "Display",Space,Str "equations",Space,Str "are",Space,Str "labelled",Space,Str "and",Space,Str "numbered"]
+  ,Para [Math DisplayMath " P_i(x) = \\sum_i a_i x^i \\qquad(2.1)"]
+  ,Para [Str "Since",Space,Str "0.1.6.0",Space,Str "those",Space,Str "can",Space,Str "also",Space,Str "appear",Space,Str "in",Space,Str "the",Space,Str "middle",Space,Str "of",Space,Str "paragraph",SoftBreak,Math DisplayMath "a x^2 + b x^2 + c = 0\\qquad(2.2)",Space,Str "like",Space,Str "this."]
+  ,Header 1 ("sec:chapter-3.-tables",[],[]) [Str "Chapter",Space,Str "3.",Space,Str "Tables"]
+  ,Table [Emph [Str "Table",Space,Str "3.1"],Str ":",Space,Str "Table",Space,Str "example"] [AlignLeft,AlignLeft] [0.0,0.0]
+   [[Plain [Str "First",Space,Str "Header"]]
+   ,[Plain [Str "Second",Space,Str "Header"]]]
+   [[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]
+   ,[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]]
+  ,Para [Str "Table",Space,Str "without",Space,Str "caption:"]
+  ,Table [] [AlignLeft,AlignLeft] [0.0,0.0]
+   [[Plain [Str "First",Space,Str "Header"]]
+   ,[Plain [Str "Second",Space,Str "Header"]]]
+   [[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]
+   ,[[Plain [Str "Content",Space,Str "Cell"]]
+    ,[Plain [Str "Content",Space,Str "Cell"]]]]
+  ,Header 1 ("sec:chapter-4.-code-blocks",[],[]) [Str "Chapter",Space,Str "4.",Space,Str "Code",Space,Str "blocks"]
+  ,Para [Str "There",Space,Str "are",Space,Str "a",Space,Str "couple",Space,Str "options",Space,Str "for",Space,Str "code",Space,Str "block",Space,Str "labels.",Space,Str "Those",Space,Str "work",Space,Str "only",Space,Str "if",Space,Str "code",Space,Str "block",Space,Str "id",Space,Str "starts",Space,Str "with",Space,Code ("",[],[]) "lst:",Str ",",Space,Str "e.g.",Space,Code ("",[],[]) "{#lst:label}"]
+  ,Header 2 ("sec:caption-attr",[],[]) [Code ("",[],[]) "caption",Space,Str "attribute"]
+  ,Para [Code ("",[],[]) "caption",Space,Str "attribute",Space,Str "will",Space,Str "be",Space,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "has",Space,Str "both",Space,Str "id",Space,Str "and",Space,Code ("",[],[]) "caption",Space,Str "attributes,",Space,Str "it",Space,Str "will",Space,Str "be",Space,Str "treated",Space,Str "as",Space,Str "numbered",Space,Str "code",Space,Str "block."]
+  ,Div ("lst:captionAttr",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "4.1:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Para [RawInline (Format "tex") "\\pagebreak"]
+  ,Header 2 ("sec:table-capts",[],[]) [Str "Table-style",Space,Str "captions"]
+  ,Para [Str "Enabled",Space,Str "with",Space,Code ("",[],[]) "codeBlockCaptions",Space,Str "metadata",Space,Str "option.",Space,Str "If",Space,Str "code",Space,Str "block",Space,Str "is",Space,Str "immediately",SoftBreak,Str "adjacent",Space,Str "to",Space,Str "paragraph,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "Listing:",Space,Str "or",Space,Code ("",[],[]) ":",Str ",",Space,Str "said",Space,Str "paragraph",Space,Str "will",Space,Str "be",SoftBreak,Str "treated",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."]
+  ,Div ("lst:tableCaption",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "4.2:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Header 2 ("sec:wrapping-div",[],[]) [Str "Wrapping",Space,Str "div"]
+  ,Para [Str "Wrapping",Space,Str "code",Space,Str "block",Space,Str "without",Space,Str "label",Space,Str "in",Space,Str "a",Space,Str "div",Space,Str "with",Space,Str "id",Space,Code ("",[],[]) "lst:...",Space,Str "and",Space,Str "class,",Space,Str "starting",Space,Str "with",Space,Code ("",[],[]) "listing",Str ",",Space,Str "and",Space,Str "adding",Space,Str "paragraph",Space,Str "before",Space,Str "code",Space,Str "block,",Space,Str "but",Space,Str "inside",Space,Str "div,",Space,Str "will",Space,Str "treat",Space,Str "said",Space,Str "paragraph",Space,Str "as",Space,Str "code",Space,Str "block",Space,Str "caption."]
+  ,Div ("lst:wrappingDiv",["listing","haskell"],[])
+   [Para [Str "Listing",Space,Str "4.3:",Space,Str "Listing",Space,Str "caption"]
+   ,CodeBlock ("",["haskell"],[]) "main :: IO ()\nmain = putStrLn \"Hello World!\""]
+  ,Header 1 ("sec:unnumbered-chapter.",["unnumbered"],[]) [Str "Unnumbered",Space,Str "chapter."]
+  ,Para [Str "This",Space,Str "chapter",Space,Str "doesn't",Space,Str "change",Space,Str "chapter",Space,Str "prefix",Space,Str "of",Space,Str "referenced",Space,Str "elements,",Space,Str "instead",Space,Str "keeping",Space,Str "number",Space,Str "of",Space,Str "previous",Space,Str "chapter,",Space,Str "e.g.",SoftBreak,Math DisplayMath " S(x) = \\int_{x_1}^{x_2} a x+b \\  \\mathrm{d}x \\qquad(4.1)"]
+  ,Header 1 ("sec:chapter-5.-reference-lists",[],[]) [Str "Chapter",Space,Str "5.",Space,Str "Reference",Space,Str "lists"]
+  ,Para [Str "It's",Space,Str "also",Space,Str "possible",Space,Str "to",Space,Str "show",Space,Str "lists",Space,Str "of",Space,Str "figures",Space,Str "and",Space,Str "tables,",Space,Str "like",Space,Str "this:"]
+  ,Header 2 ("list-of-figures",[],[]) [Str "List",Space,Str "of",Space,Str "Figures"]
+  ,Div ("",["list"],[])
+   [Para [Str "1",Space,Str "A",Space,Str "figure"]
+   ,Para [Str "1",Str ".",Str "1",Space,Str "First",Space,Str "figure"]
+   ,Para [Str "1",Str ".",Str "2",Space,Str "Second",Space,Str "figure"]
+   ,Para [Str "1",Str ".",Str "3",Space,Str "Third",Space,Str "figure"]]
+  ,Header 2 ("list-of-tables",[],[]) [Str "List",Space,Str "of",Space,Str "Tables"]
+  ,Div ("",["list"],[])
+   [Para [Str "3",Str ".",Str "1",Space,Str "Table",Space,Str "example"]]
+  ,Header 1 ("",[],[]) [Str "List",Space,Str "of",Space,Str "Listings"]
+  ,Div ("",["list"],[])
+   [Para [Str "4",Str ".",Str "1",Space,Str "Listing",Space,Str "caption"]
+   ,Para [Str "4",Str ".",Str "2",Space,Str "Listing",Space,Str "caption"]
+   ,Para [Str "4",Str ".",Str "3",Space,Str "Listing",Space,Str "caption"]]
+  ,Header 1 ("sec:appendix-a.-custom-labels",[],[("label","AppA")]) [Str "Appendix",Space,Str "A.",Space,Str "Custom",Space,Str "labels"]
+  ,Header 2 ("sec:custlabs",[],[("label","CustLab")]) [Str "This",Space,Str "section",Space,Str "will",Space,Str "have",Space,Str "custom",Space,Str "label"]]
+#else
+demo =
+  [Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "demo",Space,Str "file",Space,Str "for",Space,Str "pandoc-crossref.",Space,Str "With",Space,Str "this",Space,Str "filter,",Space,Str "you",Space,Str "can",Space,Str "cross-reference",Space,Str "figures",Space,Str "(see",Space,Str "figs.\160\&2-4",Str "),",Space,Str "display",Space,Str "equations",Space,Str "(see",Space,Str "eq.\160\&1",Str "),",Space,Str "tables",Space,Str "(see",Space,Str "tbl.\160\&1",Str ")",Space,Str "and",Space,Str "sections",Space,Str "(",Str "secs.\160\&1,",Space,Str "2,",Space,Str "4.1-4.3",Str ")"]
+  ,Para [Str "For",Space,Str "immediate",Space,Str "example,",Space,Str "see",Space,Str "fig.\160\&1"]
   ,Para [Image [Str "Figure",Space,Str "#",Space,Str "1:",Space,Str "A",Space,Str "figure"] ("img1.jpg","fig:")]
   ,Para [Str "There",Space,Str "is",Space,Str "also",Space,Str "support",Space,Str "for",Space,Str "code",Space,Str "blocks,",Space,Str "for",Space,Str "example,",Space,Str "lsts.\160\&1-3"]
   ,Para [Str "It's",Space,Str "possible",Space,Str "to",Space,Str "capitalize",Space,Str "reference",Space,Str "prefixes,",Space,Str "like",Space,Str "this:",Space,Str "Fig.\160\&2",Str "."]
@@ -149,4 +298,4 @@
    ,Para [Str "4",Str ".",Str "3",Space,Str "Listing",Space,Str "caption"]]
   ,Header 1 ("sec:appendix-a.-custom-labels",[],[("label","AppA")]) [Str "Appendix",Space,Str "A.",Space,Str "Custom",Space,Str "labels"]
   ,Header 2 ("sec:custlabs",[],[("label","CustLab")]) [Str "This",Space,Str "section",Space,Str "will",Space,Str "have",Space,Str "custom",Space,Str "label"]]
-
+#endif
diff --git a/test/test-pandoc-crossref.hs b/test/test-pandoc-crossref.hs
--- a/test/test-pandoc-crossref.hs
+++ b/test/test-pandoc-crossref.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
 import Test.Hspec
 import Text.Pandoc hiding (readMarkdown)
 import Text.Pandoc.Builder
@@ -26,6 +27,8 @@
 import qualified Native
 import Paths_pandoc_crossref
 
+import Prelude
+
 main :: IO ()
 main = hspec $ do
     describe "References.Blocks.replaceInlines" $ do
@@ -65,10 +68,17 @@
     -- describe "References.Blocks.divBlocks"
 
     describe "References.Blocks.replaceBlocks" $ do
+#if MIN_VERSION_pandoc(1,16,0)
       it "Labels images" $
         testBlocks (figure "test.jpg" [] "Test figure" "figure")
+        (figure "test.jpg" [] "Figure 1: Test figure" "figure",
+          def{imgRefs=M.fromList $ refRec' "fig:figure" 1 "Test figure"})
+#else
+      it "Labels images" $
+        testBlocks (figure "test.jpg" [] "Test figure" "figure")
         (figure "test.jpg" "fig:" "Figure 1: Test figure" [],
           def{imgRefs=M.fromList $ refRec' "fig:figure" 1 "Test figure"})
+#endif
       it "Labels equations" $
         testBlocks (equation "a^2+b^2=c^2" "equation")
         (equation "a^2+b^2=c^2\\qquad(1)" [],
@@ -263,7 +273,11 @@
 testList bs st res = runState (bottomUpM (References.List.listOf defaultOptions) (toList bs)) st `shouldBe` (toList res,st)
 
 figure :: String -> String -> String -> String -> Blocks
+#if MIN_VERSION_pandoc(1,16,0)
+figure src title alt ref = para (imageWith ("fig:" ++ ref, [], []) src ("fig:" ++ title) (text alt))
+#else
 figure src title alt ref = para (image src title (text alt) <> ref' "fig" ref)
+#endif
 
 section :: String -> Int -> String -> Blocks
 section text' level label = headerWith ("sec:" ++ label,[],[]) level (text text')
