aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-02 18:16:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-02 18:16:43 -0700
commitd975917509061e4dfbeb4d2444f5ef7ccbe1887b (patch)
treece5d3ee98104244ae45e8decdf34f5d3e6d05a65 /src
parent7bf80575b5e13cff864720a93505b0fe4d620480 (diff)
downloadpandoc-d975917509061e4dfbeb4d2444f5ef7ccbe1887b.tar.gz
Removed Text.Pandoc.Groff.
Moved groffEscape function to Text.Pandoc.Writers.Shared. [API change, since T.P.W.S is exported.]
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Groff.hs43
-rw-r--r--src/Text/Pandoc/Writers/Man.hs1
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs1
-rw-r--r--src/Text/Pandoc/Writers/Shared.hs11
4 files changed, 11 insertions, 45 deletions
diff --git a/src/Text/Pandoc/Groff.hs b/src/Text/Pandoc/Groff.hs
deleted file mode 100644
index 46acc8fa8..000000000
--- a/src/Text/Pandoc/Groff.hs
+++ /dev/null
@@ -1,43 +0,0 @@
-{-# LANGUAGE NoImplicitPrelude #-}
-{-
-Copyright (C) 2018 John MacFarlane <jgm@berkeley.edu>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--}
-
-{- |
- Module : Text.Pandoc.Groff
- Copyright : Copyright (C) 2018 John MacFarlane
- License : GNU GPL, version 2 or above
-
- Maintainer : John MacFarlane <jgm@berkeley.edu>
- Stability : alpha
- Portability : portable
-
-Shared functions for escaping and formatting groff.
--}
-module Text.Pandoc.Groff ( groffEscape )
-where
-
-import Prelude
-import Data.Char (isAscii, ord)
-import qualified Data.Text as T
-import Text.Printf (printf)
-
-groffEscape :: T.Text -> T.Text
-groffEscape = T.concatMap toUchar
- where toUchar c
- | isAscii c = T.singleton c
- | otherwise = T.pack $ printf "\\[u%04X]" (ord c)
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index c37d13841..81fa38bd7 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -45,7 +45,6 @@ import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Pretty
import Text.Pandoc.Shared
-import Text.Pandoc.Groff (groffEscape)
import Text.Pandoc.Templates
import Text.Pandoc.Writers.Math
import Text.Pandoc.Writers.Shared
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index 5eda77233..9a35a9693 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -60,7 +60,6 @@ import Text.Pandoc.Shared
import Text.Pandoc.Templates
import Text.Pandoc.Writers.Math
import Text.Pandoc.Writers.Shared
-import Text.Pandoc.Groff (groffEscape)
import Text.Printf (printf)
import Text.TeXMath (writeEqn)
diff --git a/src/Text/Pandoc/Writers/Shared.hs b/src/Text/Pandoc/Writers/Shared.hs
index 438a35ca4..ccf39c3c8 100644
--- a/src/Text/Pandoc/Writers/Shared.hs
+++ b/src/Text/Pandoc/Writers/Shared.hs
@@ -44,6 +44,7 @@ module Text.Pandoc.Writers.Shared (
, gridTable
, metaValueToInlines
, stripLeadingTrailingSpace
+ , groffEscape
)
where
import Prelude
@@ -63,6 +64,8 @@ import Text.Pandoc.Pretty
import Text.Pandoc.Walk (query)
import Text.Pandoc.UTF8 (toStringLazy)
import Text.Pandoc.XML (escapeStringForXML)
+import Text.Printf (printf)
+import Data.Char (isAscii, ord)
-- | Create JSON value for template from a 'Meta' and an association list
-- of variables, specified at the command line or in the writer.
@@ -340,3 +343,11 @@ metaValueToInlines (MetaInlines ils) = ils
metaValueToInlines (MetaBlocks bs) = query return bs
metaValueToInlines (MetaBool b) = [Str $ show b]
metaValueToInlines _ = []
+
+-- | Escape non-ASCII characters using groff \u[..] sequences.
+groffEscape :: T.Text -> T.Text
+groffEscape = T.concatMap toUchar
+ where toUchar c
+ | isAscii c = T.singleton c
+ | otherwise = T.pack $ printf "\\[u%04X]" (ord c)
+