git.iko.soy/typeable/pandoc
on master help sign in
ICML writer: support custom-styles (#5137)

see #2106

commite4340b384fc6390cbebcc4dcc6f5039af893d6dd authorMauro Bieg <mb21@users.noreply.github.com> dateWed 12 Dec 2018, 20:51 (8 years ago) parentdc8caf1
2 files changed+20−11
MANUAL.txt+10−8 src/Text/Pandoc/Writers/ICML.hs+10−3
MANUAL.txt+10−8
@@ -2051,7 +2051,7 @@ output formats
20512051Read all docx styles as divs (for paragraph styles) and spans (for
20522052character styles) regardless of whether pandoc understands the meaning
20532053of 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.
20552055
20562056input formats
20572057: `docx`
@@ -4763,8 +4763,10 @@ To disable highlighting, use the `--no-highlight` option.
47634763
47644764[skylighting]: https://github.com/jgm/skylighting
47654765
4766−Custom Styles in Docx
4767−=====================
4766+Custom Styles
4767+=============
4768+
4769+Custom styles can be used in the docx and ICML formats.
47684770
47694771Input
47704772-----
@@ -4817,8 +4819,8 @@ same styles in your input and output files.
48174819Output
48184820------
48194821
4820−By default, pandoc's docx output applies a predefined set of styles for
4821−blocks such as paragraphs and block quotes, and uses largely default
4822+By default, pandoc's docx and ICML output applies a predefined set of styles
4823+for blocks such as paragraphs and block quotes, and uses largely default
48224824formatting (italics, bold) for inlines. This will work for most
48234825purposes, especially alongside a `reference.docx` file. However, if you
48244826need 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,
48434845
48444846would style the two contained lines with the `Poetry` paragraph style.
48454847
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−defined, pandoc will not alter the definition.
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.
4850+If they are already defined, pandoc will not alter the definition.
48494851
48504852This feature allows for greatest customization in conjunction with
48514853[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
2121import Control.Monad.Except (catchError)
2222import Control.Monad.State.Strict
2323import Data.List (intersperse, isInfixOf, isPrefixOf, stripPrefix)
24−import Data.Maybe (fromMaybe)
24+import Data.Maybe (fromMaybe, maybeToList)
2525import qualified Data.Set as Set
2626import Data.Text as Text (breakOnAll, pack)
2727import Data.Text (Text)
@@ -287,6 +287,9 @@ hyperlinksToDoc (x:xs) = hyp x $$ hyperlinksToDoc xs
287287 $ inTags False "BorderColor" [("type","enumeration")] (text "Black")
288288 $$ inTags False "Destination" [("type","object")] (text $ "HyperlinkURLDestination/"++escapeColons (escapeStringForXML url)) -- HyperlinkURLDestination with more than one colon crashes CS6
289289
290+-- | Key for specifying user-defined styles
291+dynamicStyleKey :: String
292+dynamicStyleKey = "custom-style"
290293
291294-- | Convert a list of Pandoc blocks to ICML.
292295blocksToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc
@@ -365,7 +368,9 @@ blockToICML opts style (Table caption aligns widths headers rows) =
365368 , ("ColumnCount", show nrCols)
366369 ] (colDescs $$ cells)
367370 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
369374blockToICML _ _ Null = return empty
370375
371376-- | Convert a list of lists of blocks to ICML list items.
@@ -463,7 +468,9 @@ inlineToICML opts style (Link _ lst (url, title)) = do
463468 in (cont, newst)
464469inlineToICML opts style (Image attr _ target) = imageICML opts style attr target
465470inlineToICML 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
467474
468475-- | Convert a list of block elements to an ICML footnote.
469476footnoteToICML :: PandocMonad m => WriterOptions -> Style -> [Block] -> WS m Doc