git.iko.soy/typeable/pandoc
on master help sign in
Escape starting periods in ms writer code blocks

If a line of ms code block output starts with a period (.), it should be prepended by '\&' so that it is not interpreted as a roff command. Fixes #6505

commit695e864e5d636dff45861fa3d6a4fdc5d69f41eb authorMichael Hoffmann <brennan.brisad@gmail.com> dateWed 8 Jul 2020, 23:37 (6 years ago) parentc853684
4 files changed+43−1
pandoc.cabal+1 src/Text/Pandoc/Writers/Ms.hs+3−1 test/Tests/Writers/Ms.hs+37 test/test-pandoc.hs+2
pandoc.cabal+1
@@ -816,6 +816,7 @@ test-suite test-pandoc
816816 Tests.Writers.FB2
817817 Tests.Writers.Powerpoint
818818 Tests.Writers.OOXML
819+ Tests.Writers.Ms
819820 if os(windows)
820821 cpp-options: -D_WINDOWS
821822 default-language: Haskell2010
src/Text/Pandoc/Writers/Ms.hs+3−1
@@ -204,7 +204,9 @@ blockToMs opts (CodeBlock attr str) = do
204204 literal ".IP" $$
205205 literal ".nf" $$
206206 literal "\\f[C]" $$
207− hlCode $$
207+ ((case T.uncons str of
208+ Just ('.',_) -> literal "\\&"
209+ _ -> mempty) <> hlCode) $$
208210 literal "\\f[]" $$
209211 literal ".fi"
210212blockToMs opts (LineBlock ls) = do
test/Tests/Writers/Ms.hsnew file+37
@@ -0,0 +1,37 @@
1+{-# LANGUAGE NoImplicitPrelude #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+module Tests.Writers.Ms (tests) where
4+
5+import Prelude
6+import Test.Tasty
7+import Tests.Helpers
8+import Text.Pandoc
9+import Text.Pandoc.Builder
10+
11+infix 4 =:
12+(=:) :: (ToString a, ToPandoc a)
13+ => String -> (a, String) -> TestTree
14+(=:) = test (purely (writeMs def . toPandoc))
15+
16+tests :: [TestTree]
17+tests = [ testGroup "code blocks"
18+ [ "basic"
19+ =: codeBlock "hello"
20+ =?> unlines
21+ [ ".IP"
22+ , ".nf"
23+ , "\\f[C]"
24+ , "hello"
25+ , "\\f[]"
26+ , ".fi"]
27+ , "escape starting ."
28+ =: codeBlock ". hello"
29+ =?> unlines
30+ [ ".IP"
31+ , ".nf"
32+ , "\\f[C]"
33+ , "\\&. hello"
34+ , "\\f[]"
35+ , ".fi"]
36+ ]
37+ ]
test/test-pandoc.hs+2
@@ -37,6 +37,7 @@ import qualified Tests.Writers.JATS
3737import qualified Tests.Writers.Jira
3838import qualified Tests.Writers.LaTeX
3939import qualified Tests.Writers.Markdown
40+import qualified Tests.Writers.Ms
4041import qualified Tests.Writers.Muse
4142import qualified Tests.Writers.Native
4243import qualified Tests.Writers.Org
@@ -70,6 +71,7 @@ tests pandocPath = testGroup "pandoc tests"
7071 , testGroup "Muse" Tests.Writers.Muse.tests
7172 , testGroup "FB2" Tests.Writers.FB2.tests
7273 , testGroup "PowerPoint" Tests.Writers.Powerpoint.tests
74+ , testGroup "Ms" Tests.Writers.Ms.tests
7375 ]
7476 , testGroup "Readers"
7577 [ testGroup "LaTeX" Tests.Readers.LaTeX.tests