pandoc-filter-indent 0.2.2.0 → 0.2.3.0
raw patch · 5 files changed
+23/−19 lines, 5 files
Files
- ChangeLog.md +3/−0
- app/Main.hs +11/−8
- pandoc-filter-indent.cabal +2/−2
- src/Filter.hs +3/−5
- src/Render/Latex.hs +4/−4
ChangeLog.md view
@@ -3,6 +3,9 @@ ## Unreleased changes ## Unreleased changes +0.2.3.0 Jan 12 2020+ - fixed minor issue that disabled inline rendering.+ 0.2.2.0 Jan 12 2020 - Fixed problem with declaring too few columns in LaTeX - Inline code formatting
app/Main.hs view
@@ -17,10 +17,11 @@ import Filter (renderBlock, renderInline) import FindColumns (findColumns) import Alignment (Processed)+import System.IO data Options = Options { inlineSyntax :: Text- }+ } deriving (Show) main :: IO () main = toJSONFilter runner@@ -28,9 +29,10 @@ -- | Main body of Pandoc filter. -- Reads format option, metadata, -- and calls `walk` with `blockFormatter`.-runner :: Maybe Format -> Pandoc -> Pandoc-runner (fromMaybe (Format "text") -> format) input@(Pandoc (Meta meta) _) =- walk (blockFormatter opts format) input+runner :: Maybe Format -> Pandoc -> IO Pandoc+runner (fromMaybe (Format "text") -> format) input@(Pandoc (Meta meta) _) = do+ hPutStrLn stderr (show opts)+ return $ walk (blockFormatter opts format) input where opts = case Map.lookup "inline-code" meta of Nothing -> Options "haskell" -- default@@ -47,12 +49,12 @@ -> Format -- ^ Output format, defaults to "plain" if not found -> Block -> Block-blockFormatter _opts format (CodeBlock attrs content) =+blockFormatter _opts format (CodeBlock attrs content) = case fmap findColumns $ getTokenizer attrs content of Just processed -> renderBlock format attrs processed Nothing -> CodeBlock attrs content -- fallback -- Do not touch other blocks than 'CodeBock'-blockFormatter opts format x =+blockFormatter opts format x = do walk (inlineFormatter opts format) x -- | Select the desired format output then process it.@@ -63,8 +65,9 @@ -> Inline -> Inline inlineFormatter Options {inlineSyntax} format (Code attrs txt) =- case getTokenizer attrs txt of- Just processed -> renderInline format attrs $ map discardLoc processed+ case getTokenizer (addClass attrs) txt of+ Just processed -> renderInline format attrs+ $ map discardLoc processed Nothing -> Code attrs txt -- fallback where discardLoc (a, _, b) = (a, b)
pandoc-filter-indent.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 506b1106212a197e0660fa32faa540c66b93cd8f032fb5b7863977a230d9ebd9+-- hash: ad9eff137e5b4615f1392709efb99056fe4ba12434353892298d8e7d8d4099b0 name: pandoc-filter-indent-version: 0.2.2.0+version: 0.2.3.0 synopsis: Pandoc filter formatting Haskell code fragments using GHC lexer. description: Formats marked code fragments, and allows `pandoc` to safely process rest of your literate program: .
src/Filter.hs view
@@ -25,15 +25,13 @@ -> Attr -- ^ Attributes -> [Processed] -- ^ Data about alignment -> Block-renderBlock (Format "text" ) _attrs = RawBlock (Format "html" ) . T.pack . show . map (sum . map (\(_,c,_) -> c)) . colspans---renderBlock (Format "text" ) attrs = CodeBlock attrs . Render.Debug.render+--renderBlock (Format "text" ) _attrs = RawBlock (Format "html" ) . T.pack . show . colspans+renderBlock (Format "text" ) attrs = CodeBlock attrs . Render.Debug.render renderBlock (Format "latex") _attrs = RawBlock (Format "latex") . processLatex renderBlock (Format "html" ) _attrs = RawBlock (Format "html" ) . processHTML -- Debugging option renderBlock other attrs = CodeBlock attrs . T.pack . (show other <>) . show -sumColSpans = map (sum . map (\(_,c,_) -> c)) . colspans- -- TODO: inline should strip colspans, and ignore table -- | Render a list of `Processed` token records into the target output format. renderInline :: Format -- ^ Format string@@ -42,7 +40,7 @@ -> Inline --render "text" attrs aligned = RawBlock (Format "latex") $ processLatex aligned -- debug renderInline (Format "text" ) attrs = Code attrs . Render.Debug.renderInline-renderInline (Format "latex") _attrs = RawInline (Format "latex") . Render.Latex.latexInline+renderInline (Format "latex") _attrs = Math InlineMath . Render.Latex.latexInline renderInline (Format "html" ) _attrs = RawInline (Format "html" ) . Render.HTML.htmlInline -- Debugging option renderInline other attrs = Code attrs . T.pack . show
src/Render/Latex.hs view
@@ -29,7 +29,7 @@ T.concat [ "\\multicolumn{", T.pack $ show colSpan , "}{p{", T.pack $ show $ T.length txt , "ex}}{", protectText txt- , "}" ]+ , "\\,}" ] renderColSpan (toks, colSpan, alignment) = T.concat [ "\\multicolumn{", T.pack $ show colSpan , "}{", alignMark alignment@@ -66,9 +66,8 @@ -- Preprocesses then and calls `formatToken` for each. latexInline :: [(MyTok, Text)] -> Text latexInline = T.concat- . fmap formatToken- . preformatTokens- -- . (\t -> trace ("Tokens: " <> show t) t) -- debug+ . fmap formatToken+ . preformatTokens -- Workaround with joinEscapedOperators til w consider spaces only. -- | Render a simple token.@@ -143,6 +142,7 @@ formatToken (TOther, "[" ) = protectText "[" formatToken (TOther, "}" ) = protectText "}" formatToken (TOther, "{" ) = protectText "{"+-- formatToken (TBlank, txt ) = "\\textit{\\textcolor{gray}{" <> protectText txt <> "}}" formatToken (_, txt ) = "\\textit{" <> protectText txt <> "}" mathop :: Text -> Text