git.iko.soy/typeable/pandoc
on master help sign in
ICML writer: support custom-styles (#5137)
e4340b3Mauro Bieg
MANUAL.txt+10−8
@@ -2051,7 +2051,7 @@ output formats
2051Read all docx styles as divs (for paragraph styles) and spans (for
2051Read all docx styles as divs (for paragraph styles) and spans (for
2052character styles) regardless of whether pandoc understands the meaning
2052character styles) regardless of whether pandoc understands the meaning
2053of these styles. This can be used with [docx custom
2053of these styles. This can be used with [docx custom
2054−styles](#custom-styles-in-docx). Disabled by default.
2054+styles](#custom-styles). Disabled by default.
2055
2055
2056input formats
2056input formats
2057: `docx`
2057: `docx`
@@ -4763,8 +4763,10 @@ To disable highlighting, use the `--no-highlight` option.
4763
4763
4764[skylighting]: https://github.com/jgm/skylighting
4764[skylighting]: https://github.com/jgm/skylighting
4765
4765
4766−Custom Styles in Docx
4766+Custom Styles
4767−=====================
4767+=============
4768+
4769+Custom styles can be used in the docx and ICML formats.
4768
4770
4769Input
4771Input
4770-----
4772-----
@@ -4817,8 +4819,8 @@ same styles in your input and output files.
4817Output
4819Output
4818------
4820------
4819
4821
4820−By default, pandoc's docx output applies a predefined set of styles for
4822+By default, pandoc's docx and ICML output applies a predefined set of styles
4821−blocks such as paragraphs and block quotes, and uses largely default
4823+for blocks such as paragraphs and block quotes, and uses largely default
4822formatting (italics, bold) for inlines. This will work for most
4824formatting (italics, bold) for inlines. This will work for most
4823purposes, especially alongside a `reference.docx` file. However, if you
4825purposes, especially alongside a `reference.docx` file. However, if you
4824need to apply your own styles to blocks, or match a preexisting set of
4826need to apply your own styles to blocks, or match a preexisting set of
@@ -4843,9 +4845,9 @@ style `Emphatically`. Similarly, using the `fenced_divs` syntax,
4843
4845
4844would style the two contained lines with the `Poetry` paragraph style.
4846would style the two contained lines with the `Poetry` paragraph style.
4845
4847
4846−If the styles are not yet in your reference.docx, they will be defined
4847−in the output file as inheriting from normal text. If they are already
4848+For docx output, styles will be defined in the output file as inheriting
4849+from normal text, if the styles are not yet in your reference.docx.
4848−defined, pandoc will not alter the definition.
4850+If they are already defined, pandoc will not alter the definition.
4849
4851
4850This feature allows for greatest customization in conjunction with
4852This feature allows for greatest customization in conjunction with
4851[pandoc filters]. If you want all paragraphs after block quotes to be
4853[pandoc filters]. If you want all paragraphs after block quotes to be
src/Text/Pandoc/Writers/ICML.hs+10−3
@@ -21,7 +21,7 @@ import Prelude
21import Control.Monad.Except (catchError)
21import Control.Monad.Except (catchError)
22import Control.Monad.State.Strict
22import Control.Monad.State.Strict
23import Data.List (intersperse, isInfixOf, isPrefixOf, stripPrefix)
23import Data.List (intersperse, isInfixOf, isPrefixOf, stripPrefix)
24−import Data.Maybe (fromMaybe)
24+import Data.Maybe (fromMaybe, maybeToList)
25import qualified Data.Set as Set
25import qualified Data.Set as Set
26import Data.Text as Text (breakOnAll, pack)
26import Data.Text as Text (breakOnAll, pack)
27import Data.Text (Text)
27import Data.Text (Text)
@@ -287,6 +287,9 @@ hyperlinksToDoc (x:xs) = hyp x $$ hyperlinksToDoc xs
287 $ inTags False "BorderColor" [("type","enumeration")] (text "Black")
287 $ inTags False "BorderColor" [("type","enumeration")] (text "Black")
288 $$ inTags False "Destination" [("type","object")] (text $ "HyperlinkURLDestination/"++escapeColons (escapeStringForXML url)) -- HyperlinkURLDestination with more than one colon crashes CS6
288 $$ inTags False "Destination" [("type","object")] (text $ "HyperlinkURLDestination/"++escapeColons (escapeStringForXML url)) -- HyperlinkURLDestination with more than one colon crashes CS6
289
289
290+-- | Key for specifying user-defined styles
291+dynamicStyleKey :: String
292+dynamicStyleKey = "custom-style"
290
293
291-- | Convert a list of Pandoc blocks to ICML.
294-- | Convert a list of Pandoc blocks to ICML.
292blocksToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc
295blocksToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc
@@ -365,7 +368,9 @@ blockToICML opts style (Table caption aligns widths headers rows) =
365 , ("ColumnCount", show nrCols)
368 , ("ColumnCount", show nrCols)
366 ] (colDescs $$ cells)
369 ] (colDescs $$ cells)
367 liftM2 ($$) tableDoc $ parStyle opts (tableCaptionName:style) caption
370 liftM2 ($$) tableDoc $ parStyle opts (tableCaptionName:style) caption
368−blockToICML opts style (Div _ lst) = blocksToICML opts style lst
371+blockToICML opts style (Div (_, _, kvs) lst) =
372+ let dynamicStyle = maybeToList $ lookup dynamicStyleKey kvs
373+ in blocksToICML opts (dynamicStyle <> style) lst
369blockToICML _ _ Null = return empty
374blockToICML _ _ Null = return empty
370
375
371-- | Convert a list of lists of blocks to ICML list items.
376-- | Convert a list of lists of blocks to ICML list items.
@@ -463,7 +468,9 @@ inlineToICML opts style (Link _ lst (url, title)) = do
463 in (cont, newst)
468 in (cont, newst)
464inlineToICML opts style (Image attr _ target) = imageICML opts style attr target
469inlineToICML opts style (Image attr _ target) = imageICML opts style attr target
465inlineToICML opts style (Note lst) = footnoteToICML opts style lst
470inlineToICML opts style (Note lst) = footnoteToICML opts style lst
466−inlineToICML opts style (Span _ lst) = inlinesToICML opts style lst
471+inlineToICML opts style (Span (_, _, kvs) lst) =
472+ let dynamicStyle = maybeToList $ lookup dynamicStyleKey kvs
473+ in inlinesToICML opts (dynamicStyle <> style) lst
467
474
468-- | Convert a list of block elements to an ICML footnote.
475-- | Convert a list of block elements to an ICML footnote.
469footnoteToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc
476footnoteToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc