diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.3.8.2
+
+-   [Fix] Escape LaTeX caption attribute when taken from Markdown
+
+    Apparently, pandoc (up to 2.11) doesn't escape `caption` code block attribute for LaTeX when used with `--listings`. This may be intentional, but when caption is defined in pandoc-crossref using div or table-style caption syntax, this can lead to inconsistencies. Hence, caption defined in Markdown (as opposed to as string in the attribute) is now escaped when outputting to LaTeX with `--listings` enabled.
+
 ## 0.3.8.1
 
 -   Fix parsing multiple inlines in block
diff --git a/lib/Text/Pandoc/CrossRef/References/Blocks.hs b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
--- a/lib/Text/Pandoc/CrossRef/References/Blocks.hs
+++ b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
@@ -247,7 +247,7 @@
       f
         --if used with listings package, return code block with caption
         | isLatexFormat f, listings opts ->
-          replaceNoRecurse $ CodeBlock (label,classes,("caption",stringify caption):attrs) code
+          replaceNoRecurse $ CodeBlock (label,classes,("caption",escapeLaTeX $ stringify caption):attrs) code
         --if not using listings, however, wrap it in a codelisting environment
         | isLatexFormat f ->
           replaceNoRecurse $ Div nullAttr [
diff --git a/lib/Text/Pandoc/CrossRef/Util/Util.hs b/lib/Text/Pandoc/CrossRef/Util/Util.hs
--- a/lib/Text/Pandoc/CrossRef/Util/Util.hs
+++ b/lib/Text/Pandoc/CrossRef/Util/Util.hs
@@ -116,6 +116,12 @@
             runPure (writeLaTeX def $ Pandoc nullMeta [Div (l, [], []) []])
   in T.takeWhile (/='}') . T.drop 1 . T.dropWhile (/='{') $ ll
 
+escapeLaTeX :: T.Text -> T.Text
+escapeLaTeX l =
+  let ll = either (error . show) id $
+            runPure (writeLaTeX def $ Pandoc nullMeta [Plain [Str l]])
+  in ll
+
 getRefLabel :: T.Text -> [Inline] -> Maybe T.Text
 getRefLabel _ [] = Nothing
 getRefLabel tag ils
diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal
--- a/pandoc-crossref.cabal
+++ b/pandoc-crossref.cabal
@@ -4,10 +4,10 @@
 --
 -- see: https://github.com/sol/hpack
 --
--- hash: 60aff0647917782b159c09b84eb53496da9ed0f414fe0eb7d77857567ba27dfb
+-- hash: cf1ac7c0170023b09f559c841b981a19b613914459110ccb971ff6763f609b61
 
 name:           pandoc-crossref
-version:        0.3.8.1
+version:        0.3.8.2
 synopsis:       Pandoc filter for cross-references
 description:    pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 category:       Text
@@ -49,6 +49,9 @@
     test/m2m/listing-captions-ids/expect.md
     test/m2m/listing-captions-ids/expect.tex
     test/m2m/listing-captions-ids/input.md
+    test/m2m/listings-code-block-caption-278/expect.md
+    test/m2m/listings-code-block-caption-278/expect.tex
+    test/m2m/listings-code-block-caption-278/input.md
     test/m2m/multiple-eqn-same-para/expect.md
     test/m2m/multiple-eqn-same-para/expect.tex
     test/m2m/multiple-eqn-same-para/input.md
@@ -107,8 +110,8 @@
     , directory >=1 && <1.4
     , filepath >=1.1 && <1.5
     , mtl >=1.1 && <2.3
-    , pandoc >=2.10 && <2.11
-    , pandoc-types >=1.21 && <1.22
+    , pandoc >=2.10 && <2.12
+    , pandoc-types >=1.21 && <1.23
     , roman-numerals ==0.5.*
     , syb >=0.4 && <0.8
     , template-haskell >=2.7.0.0 && <3.0.0.0
@@ -138,9 +141,9 @@
     , mtl >=1.1 && <2.3
     , open-browser >=0.2 && <0.3
     , optparse-applicative >=0.13 && <0.16
-    , pandoc >=2.10 && <2.11
+    , pandoc >=2.10 && <2.12
     , pandoc-crossref
-    , pandoc-types >=1.21 && <1.22
+    , pandoc-types >=1.21 && <1.23
     , roman-numerals ==0.5.*
     , syb >=0.4 && <0.8
     , template-haskell >=2.7.0.0 && <3.0.0.0
@@ -166,9 +169,9 @@
     , filepath >=1.1 && <1.5
     , hspec >=2.4.4 && <3
     , mtl >=1.1 && <2.3
-    , pandoc >=2.10 && <2.11
+    , pandoc >=2.10 && <2.12
     , pandoc-crossref
-    , pandoc-types >=1.21 && <1.22
+    , pandoc-types >=1.21 && <1.23
     , roman-numerals ==0.5.*
     , syb >=0.4 && <0.8
     , template-haskell >=2.7.0.0 && <3.0.0.0
@@ -215,8 +218,8 @@
     , filepath >=1.1 && <1.5
     , hspec >=2.4.4 && <3
     , mtl >=1.1 && <2.3
-    , pandoc >=2.10 && <2.11
-    , pandoc-types >=1.21 && <1.22
+    , pandoc >=2.10 && <2.12
+    , pandoc-types >=1.21 && <1.23
     , roman-numerals ==0.5.*
     , syb >=0.4 && <0.8
     , template-haskell >=2.7.0.0 && <3.0.0.0
diff --git a/test/demo-chapters.inc b/test/demo-chapters.inc
--- a/test/demo-chapters.inc
+++ b/test/demo-chapters.inc
@@ -4,7 +4,7 @@
   ,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\8217s",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."]
   ,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,",Space,Str "tbl.\160\&3.1,",Space,Str "lsts.\160\&4.1,",Space,Str "4.2,",Space,Str "figs.\160\&1.2,",Space,Str "1.3,",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\8217s",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&1.1,",Space,Str "tbl.\160\&3.1,",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@unprocessedCitation]"]]
+  ,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,",Space,Str "tbl.\160\&3.1,",Space,Str "lsts.\160\&4.1,",Space,Str "4.2,",Space,Str "figs.\160\&1.2,",Space,Str "1.3,",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\8217s",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&1.1,",Space,Str "tbl.\160\&3.1,",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 11, 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"]
   ,Para [Str "Subfigures",Space,Str "are",Space,Str "supported,",Space,Str "see",Space,Str "figs.\160\&1.4,",Space,Str "1.4",Space,Str "(b)"]
   ,Header 1 ("sec:sec1",[],[]) [Str "Chapter",Space,Str "1.",Space,Str "Figures"]
diff --git a/test/demo.inc b/test/demo.inc
--- a/test/demo.inc
+++ b/test/demo.inc
@@ -4,7 +4,7 @@
   ,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\8217s",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."]
   ,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,",Space,Str "tbl.\160\&1,",Space,Str "lsts.\160\&1,",Space,Str "2,",Space,Str "figs.\160\&3,",Space,Str "4,",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\8217s",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&2,",Space,Str "tbl.\160\&1,",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@unprocessedCitation]"]]
+  ,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,",Space,Str "tbl.\160\&1,",Space,Str "lsts.\160\&1,",Space,Str "2,",Space,Str "figs.\160\&3,",Space,Str "4,",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\8217s",Space,Str "not",Space,Str "recommended:",Space,Str "fig.\160\&2,",Space,Str "tbl.\160\&1,",Space,Cite [Citation {citationId = "unprocessedCitation", citationPrefix = [], citationSuffix = [], citationMode = NormalCitation, citationNoteNum = 11, 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"]
   ,Para [Str "Subfigures",Space,Str "are",Space,Str "supported,",Space,Str "see",Space,Str "figs.\160\&5,",Space,Str "5",Space,Str "(b)"]
   ,Header 1 ("sec:sec1",[],[]) [Str "Chapter",Space,Str "1.",Space,Str "Figures"]
diff --git a/test/m2m/listings-code-block-caption-278/expect.md b/test/m2m/listings-code-block-caption-278/expect.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/listings-code-block-caption-278/expect.md
@@ -0,0 +1,5 @@
+This is \#278 regression test
+
+::: {#lst:some_listing .listing}
+Listing 1: some_listing
+:::
diff --git a/test/m2m/listings-code-block-caption-278/expect.tex b/test/m2m/listings-code-block-caption-278/expect.tex
new file mode 100644
--- /dev/null
+++ b/test/m2m/listings-code-block-caption-278/expect.tex
@@ -0,0 +1,4 @@
+This is \#278 regression test
+
+\begin{lstlisting}[caption={some\_listing}, label=lst:some_listing]
+\end{lstlisting}
diff --git a/test/m2m/listings-code-block-caption-278/input.md b/test/m2m/listings-code-block-caption-278/input.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/listings-code-block-caption-278/input.md
@@ -0,0 +1,11 @@
+---
+codeBlockCaptions: true
+listings: true
+...
+
+This is #278 regression test
+
+```{#lst:some_listing}
+```
+
+Listing: some_listing
diff --git a/test/test-integrative.hs b/test/test-integrative.hs
--- a/test/test-integrative.hs
+++ b/test/test-integrative.hs
@@ -29,6 +29,9 @@
 import Text.Pandoc.Highlighting
 import qualified Data.Text as T
 
+listingsDirs :: [String]
+listingsDirs = ["listings-code-block-caption-278"]
+
 m2m :: String -> Spec
 m2m dir
   | dir == "." = return ()
@@ -38,7 +41,9 @@
     input <- runIO $ readFile ("test" </> "m2m" </> dir </> "input.md")
     expect_md <- runIO $ readFile ("test" </> "m2m" </> dir </> "expect.md")
     let ro = def { readerExtensions = pandocExtensions }
-        wo = def { writerExtensions = pandocExtensions, writerHighlightStyle=Just pygments }
+        wo = def { writerExtensions = pandocExtensions
+                 , writerHighlightStyle=Just pygments
+                 , writerListings = dir `elem` listingsDirs }
     p@(Pandoc meta _) <- runIO $ either (error . show) id <$> P.runIO (readMarkdown ro $ T.pack input)
     let actual_md = either (fail . show) T.unpack $ runPure $ writeMarkdown wo $ runCrossRef meta (Just $ Format "markdown") defaultCrossRefAction p
     it "Markdown" $ do
