pandoc-stylefrommeta 0.2.0.2 → 0.2.1.0
raw patch · 4 files changed
+53/−43 lines, 4 files
Files
- Changelog.md +5/−0
- LICENSE +1/−1
- pandoc-stylefrommeta.cabal +29/−23
- styleFromMeta.hs +18/−19
Changelog.md view
@@ -1,3 +1,8 @@+### 0.2.1.0++- Ensure that *para_style* is always found (different versions of Pandoc may+ render contents of *MetaBlocks* as *Para* or *Plain*).+ ### 0.2.0.0 - Render substitutions using Pandoc's writers.
LICENSE view
@@ -1,7 +1,7 @@ The following license covers this documentation, and the source code, except where otherwise indicated. -Copyright 2016, Alexey Radkov. All rights reserved.+Copyright 2016-2019, Alexey Radkov. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
pandoc-stylefrommeta.cabal view
@@ -1,28 +1,34 @@-name: pandoc-stylefrommeta-version: 0.2.0.2-synopsis: Pandoc filter to customize links, images and paragraphs-description: Pandoc filter to customize links, images and paragraphs+name: pandoc-stylefrommeta+version: 0.2.1.0+synopsis: Pandoc filter to customize links, images and paragraphs+description: Pandoc filter to customize links, images and paragraphs (with restrictions). Styles are read from the metadata of the document: they may reside inside the document or in a separate YAML file.-homepage: http://github.com/lyokha/styleFromMeta-license: BSD3-license-file: LICENSE-extra-source-files: Changelog.md README.md-author: Alexey Radkov <alexey.radkov@gmail.com>-maintainer: Alexey Radkov <alexey.radkov@gmail.com>-copyright: 2016-2017 Alexey Radkov-category: Text-build-type: Simple-cabal-version: >= 1.8+homepage: http://github.com/lyokha/styleFromMeta+license: BSD3+license-file: LICENSE+extra-source-files: Changelog.md README.md+author: Alexey Radkov <alexey.radkov@gmail.com>+maintainer: Alexey Radkov <alexey.radkov@gmail.com>+stability: stable+copyright: 2016-2019 Alexey Radkov+category: Text+build-type: Simple+cabal-version: 1.20 +source-repository head+ type: git+ location: git@github.com:lyokha/styleFromMeta.git+ executable styleFromMeta- build-depends: base >= 4.7 && < 5- , pandoc >= 1.12- , pandoc-types >= 1.12- , containers >= 0.2- , MissingH >= 1.0.0- , text- , bytestring- extensions: CPP- main-is: styleFromMeta.hs+ default-language: Haskell2010+ build-depends: base >= 4.7 && < 5+ , pandoc >= 1.12+ , pandoc-types >= 1.12+ , containers >= 0.2+ , MissingH >= 1.0.0+ , text+ , bytestring+ default-extensions: CPP+ main-is: styleFromMeta.hs
styleFromMeta.hs view
@@ -13,12 +13,8 @@ import qualified Data.ByteString.Lazy.Char8 as C8L import qualified Data.Text as T import Control.Exception (displayException)--#define MBPLAIN Plain #else import Text.Pandoc (Writer (..), getWriter)--#define MBPLAIN Para #endif #if MIN_TOOL_VERSION_ghc(7,10,1)@@ -59,10 +55,13 @@ | all isImage is = b -- do not apply para_style to standalone images where isImage Image {} = True isImage _ = False-substBlockStyle (Format fmt) m (Para cnt)+substBlockStyle (Format fmt) m b@(Para cnt) | Just (MetaMap mm) <- M.lookup "para_style" m- , Just (MetaBlocks [MBPLAIN [Span attr _]]) <- M.lookup fmt mm =- Plain [Span attr cnt]+ , Just (MetaBlocks [p]) <- M.lookup fmt mm =+ case p of+ Para [Span attr _] -> Plain [Span attr cnt]+ Plain [Span attr _] -> Plain [Span attr cnt]+ _ -> b substBlockStyle _ _ b = b substInlineStyle :: Format -> MMap -> Inline -> Inline@@ -77,16 +76,16 @@ RawInline fm $ renderInlines fm $ map substInlineStyle'' mbs where substInlineStyle'' mb = case mb of- Plain is -> substPlainParams is- Para is -> substPlainParams is- d@Div {} ->+ Plain is -> substPlainParams is+ Para is -> substPlainParams is+ d@Div {} -> RawInline fm $ substParamsInRawBlock fm params $ renderBlocks fm [d] RawBlock bfm b -> RawInline bfm $ substParamsInRawBlock bfm params b- _ -> i+ _ -> i substInlineStyle' Nothing = cons alt tgt substInlineStyle' _ = i in substInlineStyle' $ M.lookup fmt mm@@ -100,16 +99,16 @@ toInlineParams _ = Nothing substParams :: Format -> PureInlineParams -> Inline -> Inline-substParams _ (alt, _) (Subst "ALT") = Span nullAttr alt-substParams fm params (SubstVerbatim "ALT") = RawInline fm $+substParams _ (alt, _) (Subst "ALT") = Span nullAttr alt+substParams fm params (SubstVerbatim "ALT") = RawInline fm $ stringify $ substParams fm params $ Subst "ALT"-substParams _ (_, (src, _)) (Subst "SRC") = Str src-substParams fm (_, (src, _)) (SubstVerbatim "SRC") = RawInline fm src-substParams _ (_, (_, title)) (Subst "TITLE") = Str title-substParams fm (_, (_, title)) (SubstVerbatim "TITLE") = RawInline fm title-substParams _ params (RawInline fm s) = RawInline fm $+substParams _ (_, (src, _)) (Subst "SRC") = Str src+substParams fm (_, (src, _)) (SubstVerbatim "SRC") = RawInline fm src+substParams _ (_, (_, title)) (Subst "TITLE") = Str title+substParams fm (_, (_, title)) (SubstVerbatim "TITLE") = RawInline fm title+substParams _ params (RawInline fm s) = RawInline fm $ substParamsInRawBlock fm params s-substParams _ _ i = i+substParams _ _ i = i substParamsInRawBlock :: Format -> PureInlineParams -> String -> String substParamsInRawBlock fm (alt, (src, title)) s =