mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-23 07:55:45 +00:00
Org reader: support smart quotes export option
Reading of smart quotes can be toggled using the `'` option.
This commit is contained in:
@@ -29,7 +29,7 @@ module Text.Pandoc.Readers.Org ( readOrg ) where
|
||||
|
||||
import Text.Pandoc.Readers.Org.Blocks ( blockList, meta )
|
||||
import Text.Pandoc.Readers.Org.Parsing ( OrgParser, readWithM )
|
||||
import Text.Pandoc.Readers.Org.ParserState ( OrgParserState (..) )
|
||||
import Text.Pandoc.Readers.Org.ParserState ( optionsToParserState )
|
||||
|
||||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.Error
|
||||
@@ -42,7 +42,8 @@ import Control.Monad.Reader ( runReader )
|
||||
readOrg :: ReaderOptions -- ^ Reader options
|
||||
-> String -- ^ String to parse (assuming @'\n'@ line endings)
|
||||
-> Either PandocError Pandoc
|
||||
readOrg opts s = flip runReader def $ readWithM parseOrg def{ orgStateOptions = opts } (s ++ "\n\n")
|
||||
readOrg opts s = flip runReader def $
|
||||
readWithM parseOrg (optionsToParserState opts) (s ++ "\n\n")
|
||||
|
||||
--
|
||||
-- Parser
|
||||
|
||||
@@ -500,7 +500,7 @@ addLinkFormat key formatter = updateState $ \s ->
|
||||
exportSetting :: OrgParser ()
|
||||
exportSetting = choice
|
||||
[ booleanSetting "^" setExportSubSuperscripts
|
||||
, ignoredSetting "'"
|
||||
, booleanSetting "'" setExportSmartQuotes
|
||||
, ignoredSetting "*"
|
||||
, ignoredSetting "-"
|
||||
, ignoredSetting ":"
|
||||
|
||||
@@ -730,6 +730,7 @@ smart = do
|
||||
|
||||
singleQuoted :: OrgParser (F Inlines)
|
||||
singleQuoted = try $ do
|
||||
guard . exportSmartQuotes . orgStateExportSettings =<< getState
|
||||
singleQuoteStart
|
||||
updatePositions '\''
|
||||
withQuoteContext InSingleQuote $
|
||||
@@ -741,6 +742,7 @@ singleQuoted = try $ do
|
||||
-- in the same paragraph.
|
||||
doubleQuoted :: OrgParser (F Inlines)
|
||||
doubleQuoted = try $ do
|
||||
guard . exportSmartQuotes . orgStateExportSettings =<< getState
|
||||
doubleQuoteStart
|
||||
updatePositions '"'
|
||||
contents <- mconcat <$> many (try $ notFollowedBy doubleQuoteEnd >> inline)
|
||||
|
||||
@@ -42,9 +42,11 @@ module Text.Pandoc.Readers.Org.ParserState
|
||||
, returnF
|
||||
, ExportSettingSetter
|
||||
, ExportSettings (..)
|
||||
, setExportSubSuperscripts
|
||||
, setExportDrawers
|
||||
, setExportSmartQuotes
|
||||
, setExportSubSuperscripts
|
||||
, modifyExportSettings
|
||||
, optionsToParserState
|
||||
) where
|
||||
|
||||
import Control.Monad (liftM, liftM2)
|
||||
@@ -77,11 +79,12 @@ type OrgLinkFormatters = M.Map String (String -> String)
|
||||
-- | Export settings <http://orgmode.org/manual/Export-settings.html>
|
||||
-- These settings can be changed via OPTIONS statements.
|
||||
data ExportSettings = ExportSettings
|
||||
{ exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
|
||||
, exportDrawers :: Either [String] [String]
|
||||
{ exportDrawers :: Either [String] [String]
|
||||
-- ^ Specify drawer names which should be exported. @Left@ names are
|
||||
-- explicitly excluded from the resulting output while @Right@ means that
|
||||
-- only the listed drawer names should be included.
|
||||
, exportSmartQuotes :: Bool -- ^ Parse quotes, ellipses, apostrophs smartly
|
||||
, exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
|
||||
}
|
||||
|
||||
-- | Org-mode parser state
|
||||
@@ -152,25 +155,35 @@ defaultOrgParserState = OrgParserState
|
||||
|
||||
defaultExportSettings :: ExportSettings
|
||||
defaultExportSettings = ExportSettings
|
||||
{ exportSubSuperscripts = True
|
||||
, exportDrawers = Left ["LOGBOOK"]
|
||||
{ exportDrawers = Left ["LOGBOOK"]
|
||||
, exportSmartQuotes = True
|
||||
, exportSubSuperscripts = True
|
||||
}
|
||||
|
||||
optionsToParserState :: ReaderOptions -> OrgParserState
|
||||
optionsToParserState opts =
|
||||
def { orgStateOptions = opts }
|
||||
|
||||
|
||||
--
|
||||
-- Setter for exporting options
|
||||
--
|
||||
type ExportSettingSetter a = a -> ExportSettings -> ExportSettings
|
||||
|
||||
-- | Set export options for drawers. See the @exportDrawers@ in ADT
|
||||
-- @ExportSettings@ for details.
|
||||
setExportDrawers :: ExportSettingSetter (Either [String] [String])
|
||||
setExportDrawers val es = es { exportDrawers = val }
|
||||
|
||||
-- | Set export options for sub/superscript parsing. The short syntax will
|
||||
-- not be parsed if this is set set to @False@.
|
||||
setExportSubSuperscripts :: ExportSettingSetter Bool
|
||||
setExportSubSuperscripts val es = es { exportSubSuperscripts = val }
|
||||
|
||||
-- | Set export options for drawers. See the @exportDrawers@ in ADT
|
||||
-- @ExportSettings@ for details.
|
||||
setExportDrawers :: ExportSettingSetter (Either [String] [String])
|
||||
setExportDrawers val es = es { exportDrawers = val }
|
||||
-- | Set export options for sub/superscript parsing. The short syntax will
|
||||
-- not be parsed if this is set set to @False@.
|
||||
setExportSmartQuotes :: ExportSettingSetter Bool
|
||||
setExportSmartQuotes val es = es { exportSmartQuotes = val }
|
||||
|
||||
-- | Modify a parser state
|
||||
modifyExportSettings :: ExportSettingSetter a -> a -> OrgParserState -> OrgParserState
|
||||
|
||||
Reference in New Issue
Block a user