{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
module Filter(renderBlock, renderInline) where
import Text.Pandoc.JSON
import qualified Data.Text as T
import Prelude hiding(getLine)
import FindColumns ( tableColumns )
import Alignment ( Processed )
import Token ( MyTok )
import Render.ColSpan ( colspans, numColSpans )
import qualified Render.Debug
import qualified Render.Latex
import qualified Render.HTML
import Debug.Trace(trace)
renderBlock :: Format
-> Attr
-> [Processed]
-> Block
renderBlock :: Format -> Attr -> [Processed] -> Block
renderBlock (Format Text
"text" ) Attr
attrs = Attr -> Text -> Block
CodeBlock Attr
attrs (Text -> Block) -> ([Processed] -> Text) -> [Processed] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> Text
Render.Debug.render
renderBlock (Format Text
"latex") Attr
_attrs = Format -> Text -> Block
RawBlock (Text -> Format
Format Text
"latex") (Text -> Block) -> ([Processed] -> Text) -> [Processed] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> Text
processLatex
renderBlock (Format Text
"beamer") Attr
_attrs = Format -> Text -> Block
RawBlock (Text -> Format
Format Text
"latex") (Text -> Block) -> ([Processed] -> Text) -> [Processed] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> Text
processLatex
renderBlock (Format Text
"html" ) Attr
_attrs = Format -> Text -> Block
RawBlock (Text -> Format
Format Text
"html" ) (Text -> Block) -> ([Processed] -> Text) -> [Processed] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> Text
processHTML
renderBlock Format
other Attr
attrs = Attr -> Text -> Block
CodeBlock Attr
attrs (Text -> Block) -> ([Processed] -> Text) -> [Processed] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text) -> ([Processed] -> String) -> [Processed] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Format -> String
forall a. Show a => a -> String
show Format
other String -> String -> String
forall a. Semigroup a => a -> a -> a
<>) (String -> String)
-> ([Processed] -> String) -> [Processed] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> String
forall a. Show a => a -> String
show
renderInline :: Format
-> Attr
-> [(MyTok, T.Text)]
-> Inline
renderInline :: Format -> Attr -> [(MyTok, Text)] -> Inline
renderInline (Format Text
"text" ) Attr
attrs = Attr -> Text -> Inline
Code Attr
attrs (Text -> Inline)
-> ([(MyTok, Text)] -> Text) -> [(MyTok, Text)] -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(MyTok, Text)] -> Text
forall a. Field2 a a Text Text => [a] -> Text
Render.Debug.renderInline
renderInline (Format Text
"latex") Attr
_attrs = MathType -> Text -> Inline
Math MathType
InlineMath (Text -> Inline)
-> ([(MyTok, Text)] -> Text) -> [(MyTok, Text)] -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(MyTok, Text)] -> Text
Render.Latex.latexInline
renderInline (Format Text
"html" ) Attr
_attrs = Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"html" ) (Text -> Inline)
-> ([(MyTok, Text)] -> Text) -> [(MyTok, Text)] -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(MyTok, Text)] -> Text
Render.HTML.htmlInline
renderInline Format
other Attr
attrs = Attr -> Text -> Inline
Code Attr
attrs (Text -> Inline)
-> ([(MyTok, Text)] -> Text) -> [(MyTok, Text)] -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text)
-> ([(MyTok, Text)] -> String) -> [(MyTok, Text)] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(MyTok, Text)] -> String
forall a. Show a => a -> String
show
processLatex :: [Processed] -> T.Text
processLatex :: [Processed] -> Text
processLatex [Processed]
processed = Int -> [[TokensWithColSpan]] -> Text
Render.Latex.latexFromColSpans ([Processed] -> Int
numColSpans [Processed]
processed) [[TokensWithColSpan]]
cs
where
cs :: [[TokensWithColSpan]]
cs = [Processed] -> [[TokensWithColSpan]]
colspans [Processed]
processed
processHTML :: [Processed] -> T.Text
processHTML :: [Processed] -> Text
processHTML = [[TokensWithColSpan]] -> Text
Render.HTML.htmlFromColSpans
([[TokensWithColSpan]] -> Text)
-> ([Processed] -> [[TokensWithColSpan]]) -> [Processed] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Processed] -> [[TokensWithColSpan]]
colspans