{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Shared (
splitBy,
splitTextBy,
splitTextByIndices,
ordNub,
findM,
inquotes,
tshow,
elemText,
notElemText,
stripTrailingNewlines,
trim,
triml,
trimr,
trimMath,
stripFirstAndLast,
camelCaseToHyphenated,
camelCaseStrToHyphenated,
toRomanNumeral,
escapeURI,
tabFilter,
crFilter,
normalizeDate,
orderedListMarkers,
extractSpaces,
removeFormatting,
deNote,
deLink,
stringify,
capitalize,
compactify,
compactifyDL,
linesToPara,
makeSections,
uniqueIdent,
inlineListToIdentifier,
isHeaderBlock,
headerShift,
stripEmptyParagraphs,
onlySimpleTableCells,
isTightList,
taskListItemFromAscii,
taskListItemToAscii,
handleTaskListItem,
addMetaField,
makeMeta,
eastAsianLineBreakFilter,
htmlSpanLikeElements,
filterIpynbOutput,
renderTags',
inDirectory,
collapseFilePath,
uriPathToPath,
filteredFilesFromArchive,
schemes,
isURI,
mapLeft,
blocksToInlines,
blocksToInlines',
blocksToInlinesWithSep,
defaultBlocksSeparator,
safeRead,
safeStrRead,
defaultUserDataDir,
pandocVersion
) where
import Codec.Archive.Zip
import qualified Control.Exception as E
import Control.Monad (MonadPlus (..), msum, unless)
import qualified Control.Monad.State.Strict as S
import qualified Data.ByteString.Lazy as BL
import qualified Data.Bifunctor as Bifunctor
import Data.Char (isAlpha, isLower, isSpace, isUpper, toLower, isAlphaNum,
generalCategory, GeneralCategory(NonSpacingMark,
SpacingCombiningMark, EnclosingMark, ConnectorPunctuation))
import Data.List (find, intercalate, intersperse, sortOn, foldl')
import qualified Data.Map as M
import Data.Maybe (mapMaybe, fromMaybe)
import Data.Monoid (Any (..))
import Data.Sequence (ViewL (..), ViewR (..), viewl, viewr)
import qualified Data.Set as Set
import qualified Data.Text as T
import Data.Version (showVersion)
import Network.URI (URI (uriScheme), escapeURIString, parseURI)
import Paths_pandoc (version)
import System.Directory
import System.FilePath (isPathSeparator, splitDirectories)
import qualified System.FilePath.Posix as Posix
import Text.HTML.TagSoup (RenderOptions (..), Tag (..), renderOptions,
renderTagsOptions)
import Text.Pandoc.Builder (Blocks, Inlines, ToMetaValue (..))
import qualified Text.Pandoc.Builder as B
import Data.Time
import Text.Pandoc.Asciify (toAsciiText)
import Text.Pandoc.Definition
import Text.Pandoc.Extensions (Extensions, Extension(..), extensionEnabled)
import Text.Pandoc.Generic (bottomUp)
import Text.DocLayout (charWidth)
import Text.Pandoc.Walk
pandocVersion :: T.Text
pandocVersion :: Text
pandocVersion = FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ Version -> FilePath
showVersion Version
version
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy :: forall a. (a -> Bool) -> [a] -> [[a]]
splitBy a -> Bool
_ [] = []
splitBy a -> Bool
isSep [a]
lst =
let ([a]
first, [a]
rest) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break a -> Bool
isSep [a]
lst
in [a]
first[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:(a -> Bool) -> [a] -> [[a]]
forall a. (a -> Bool) -> [a] -> [[a]]
splitBy a -> Bool
isSep ((a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile a -> Bool
isSep [a]
rest)
splitTextBy :: (Char -> Bool) -> T.Text -> [T.Text]
splitTextBy :: (Char -> Bool) -> Text -> [Text]
splitTextBy Char -> Bool
isSep Text
t
| Text -> Bool
T.null Text
t = []
| Bool
otherwise = let (Text
first, Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
T.break Char -> Bool
isSep Text
t
in Text
first Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: (Char -> Bool) -> Text -> [Text]
splitTextBy Char -> Bool
isSep ((Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isSep Text
rest)
splitTextByIndices :: [Int] -> T.Text -> [T.Text]
splitTextByIndices :: [Int] -> Text -> [Text]
splitTextByIndices [Int]
ns = [Int] -> FilePath -> [Text]
splitTextByRelIndices ((Int -> Int -> Int) -> [Int] -> [Int] -> [Int]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (-) [Int]
ns (Int
0Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
ns)) (FilePath -> [Text]) -> (Text -> FilePath) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
where
splitTextByRelIndices :: [Int] -> FilePath -> [Text]
splitTextByRelIndices [] FilePath
cs = [FilePath -> Text
T.pack FilePath
cs]
splitTextByRelIndices (Int
x:[Int]
xs) FilePath
cs =
let (FilePath
first, FilePath
rest) = Int -> FilePath -> (FilePath, FilePath)
splitAt' Int
x FilePath
cs
in FilePath -> Text
T.pack FilePath
first Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Int] -> FilePath -> [Text]
splitTextByRelIndices [Int]
xs FilePath
rest
splitAt' :: Int -> [Char] -> ([Char],[Char])
splitAt' :: Int -> FilePath -> (FilePath, FilePath)
splitAt' Int
_ [] = ([],[])
splitAt' Int
n FilePath
xs | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 = ([],FilePath
xs)
splitAt' Int
n (Char
x:FilePath
xs) = (Char
xChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath
ys,FilePath
zs)
where (FilePath
ys,FilePath
zs) = Int -> FilePath -> (FilePath, FilePath)
splitAt' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Char -> Int
charWidth Char
x) FilePath
xs
ordNub :: (Ord a) => [a] -> [a]
ordNub :: forall a. Ord a => [a] -> [a]
ordNub [a]
l = Set a -> [a] -> [a]
forall {a}. Ord a => Set a -> [a] -> [a]
go Set a
forall a. Set a
Set.empty [a]
l
where
go :: Set a -> [a] -> [a]
go Set a
_ [] = []
go Set a
s (a
x:[a]
xs) = if a
x a -> Set a -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set a
s then Set a -> [a] -> [a]
go Set a
s [a]
xs
else a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: Set a -> [a] -> [a]
go (a -> Set a -> Set a
forall a. Ord a => a -> Set a -> Set a
Set.insert a
x Set a
s) [a]
xs
findM :: forall m t a. (Monad m, Foldable t) => (a -> m Bool) -> t a -> m (Maybe a)
findM :: forall (m :: * -> *) (t :: * -> *) a.
(Monad m, Foldable t) =>
(a -> m Bool) -> t a -> m (Maybe a)
findM a -> m Bool
p = (a -> m (Maybe a) -> m (Maybe a))
-> m (Maybe a) -> t a -> m (Maybe a)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr a -> m (Maybe a) -> m (Maybe a)
go (Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)
where
go :: a -> m (Maybe a) -> m (Maybe a)
go :: a -> m (Maybe a) -> m (Maybe a)
go a
x m (Maybe a)
acc = do
Bool
b <- a -> m Bool
p a
x
if Bool
b then Maybe a -> m (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just a
x) else m (Maybe a)
acc
inquotes :: T.Text -> T.Text
inquotes :: Text -> Text
inquotes Text
txt = Char -> Text -> Text
T.cons Char
'\"' (Text -> Char -> Text
T.snoc Text
txt Char
'\"')
tshow :: Show a => a -> T.Text
tshow :: forall a. Show a => a -> Text
tshow = FilePath -> Text
T.pack (FilePath -> Text) -> (a -> FilePath) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Show a => a -> FilePath
show
elemText :: Char -> T.Text -> Bool
elemText :: Char -> Text -> Bool
elemText Char
c = (Char -> Bool) -> Text -> Bool
T.any (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
c)
notElemText :: Char -> T.Text -> Bool
notElemText :: Char -> Text -> Bool
notElemText Char
c = (Char -> Bool) -> Text -> Bool
T.all (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
c)
stripTrailingNewlines :: T.Text -> T.Text
stripTrailingNewlines :: Text -> Text
stripTrailingNewlines = (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n')
isWS :: Char -> Bool
isWS :: Char -> Bool
isWS Char
' ' = Bool
True
isWS Char
'\r' = Bool
True
isWS Char
'\n' = Bool
True
isWS Char
'\t' = Bool
True
isWS Char
_ = Bool
False
trim :: T.Text -> T.Text
trim :: Text -> Text
trim = (Char -> Bool) -> Text -> Text
T.dropAround Char -> Bool
isWS
triml :: T.Text -> T.Text
triml :: Text -> Text
triml = (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isWS
trimr :: T.Text -> T.Text
trimr :: Text -> Text
trimr = (Char -> Bool) -> Text -> Text
T.dropWhileEnd Char -> Bool
isWS
trimMath :: T.Text -> T.Text
trimMath :: Text -> Text
trimMath = Text -> Text
triml (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.reverse (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
stripBeginSpace (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.reverse
where
stripBeginSpace :: Text -> Text
stripBeginSpace Text
t
| Text -> Bool
T.null Text
pref = Text
t
| Just (Char
'\\', Text
_) <- Text -> Maybe (Char, Text)
T.uncons Text
suff = Char -> Text -> Text
T.cons (Text -> Char
T.last Text
pref) Text
suff
| Bool
otherwise = Text
suff
where
(Text
pref, Text
suff) = (Char -> Bool) -> Text -> (Text, Text)
T.span Char -> Bool
isWS Text
t
stripFirstAndLast :: T.Text -> T.Text
stripFirstAndLast :: Text -> Text
stripFirstAndLast Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just (Char
_, Text
t') -> case Text -> Maybe (Text, Char)
T.unsnoc Text
t' of
Just (Text
t'', Char
_) -> Text
t''
Maybe (Text, Char)
_ -> Text
t'
Maybe (Char, Text)
_ -> Text
""
camelCaseToHyphenated :: T.Text -> T.Text
camelCaseToHyphenated :: Text -> Text
camelCaseToHyphenated = FilePath -> Text
T.pack (FilePath -> Text) -> (Text -> FilePath) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
camelCaseStrToHyphenated (FilePath -> FilePath) -> (Text -> FilePath) -> Text -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
camelCaseStrToHyphenated :: String -> String
camelCaseStrToHyphenated :: FilePath -> FilePath
camelCaseStrToHyphenated [] = FilePath
""
camelCaseStrToHyphenated (Char
a:Char
b:FilePath
rest)
| Char -> Bool
isLower Char
a
, Char -> Bool
isUpper Char
b = Char
aChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:Char
'-'Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:Char -> Char
toLower Char
bChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath -> FilePath
camelCaseStrToHyphenated FilePath
rest
camelCaseStrToHyphenated (Char
a:Char
b:Char
c:FilePath
rest)
| Char -> Bool
isUpper Char
a
, Char -> Bool
isUpper Char
b
, Char -> Bool
isLower Char
c = Char -> Char
toLower Char
aChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:Char
'-'Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:Char -> Char
toLower Char
bChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath -> FilePath
camelCaseStrToHyphenated (Char
cChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath
rest)
camelCaseStrToHyphenated (Char
a:FilePath
rest) = Char -> Char
toLower Char
aChar -> FilePath -> FilePath
forall a. a -> [a] -> [a]
:FilePath -> FilePath
camelCaseStrToHyphenated FilePath
rest
toRomanNumeral :: Int -> T.Text
toRomanNumeral :: Int -> Text
toRomanNumeral Int
x
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
4000 Bool -> Bool -> Bool
|| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = Text
"?"
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1000 = Text
"M" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1000)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
900 = Text
"CM" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
900)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
500 = Text
"D" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
500)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
400 = Text
"CD" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
400)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
100 = Text
"C" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
100)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
90 = Text
"XC" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
90)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
50 = Text
"L" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
50)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
40 = Text
"XL" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
40)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
10 = Text
"X" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
10)
| Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
9 = Text
"IX"
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
5 = Text
"V" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
5)
| Int
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
4 = Text
"IV"
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
1 = Text
"I" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
toRomanNumeral (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
| Bool
otherwise = Text
""
escapeURI :: T.Text -> T.Text
escapeURI :: Text -> Text
escapeURI = FilePath -> Text
T.pack (FilePath -> Text) -> (Text -> FilePath) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> FilePath -> FilePath
escapeURIString (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
needsEscaping) (FilePath -> FilePath) -> (Text -> FilePath) -> Text -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
where needsEscaping :: Char -> Bool
needsEscaping Char
c = Char -> Bool
isSpace Char
c Bool -> Bool -> Bool
|| Char
c Char -> Text -> Bool
`elemText` Text
"<>|\"{}[]^`"
tabFilter :: Int
-> T.Text
-> T.Text
tabFilter :: Int -> Text -> Text
tabFilter Int
0 = Text -> Text
forall a. a -> a
id
tabFilter Int
tabStop = [Text] -> Text
T.unlines ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
go ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.lines
where go :: Text -> Text
go Text
s =
let (Text
s1, Text
s2) = (Char -> Bool) -> Text -> (Text, Text)
T.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\t') Text
s
in if Text -> Bool
T.null Text
s2
then Text
s1
else Text
s1 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
T.replicate
(Int
tabStop Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Text -> Int
T.length Text
s1 Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
tabStop)) (FilePath -> Text
T.pack FilePath
" ")
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
go (Int -> Text -> Text
T.drop Int
1 Text
s2)
{-# DEPRECATED crFilter "readers filter crs automatically" #-}
crFilter :: T.Text -> T.Text
crFilter :: Text -> Text
crFilter = (Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\r')
normalizeDate :: T.Text -> Maybe T.Text
normalizeDate :: Text -> Maybe Text
normalizeDate = (FilePath -> Text) -> Maybe FilePath -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Text
T.pack (Maybe FilePath -> Maybe Text)
-> (Text -> Maybe FilePath) -> Text -> Maybe Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Maybe FilePath
normalizeDate' (FilePath -> Maybe FilePath)
-> (Text -> FilePath) -> Text -> Maybe FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
normalizeDate' :: String -> Maybe String
normalizeDate' :: FilePath -> Maybe FilePath
normalizeDate' FilePath
s = (Day -> FilePath) -> Maybe Day -> Maybe FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TimeLocale -> FilePath -> Day -> FilePath
forall t. FormatTime t => TimeLocale -> FilePath -> t -> FilePath
formatTime TimeLocale
defaultTimeLocale FilePath
"%F")
([Maybe Day] -> Maybe Day
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum ([Maybe Day] -> Maybe Day) -> [Maybe Day] -> Maybe Day
forall a b. (a -> b) -> a -> b
$ (FilePath -> Maybe Day) -> [FilePath] -> [Maybe Day]
forall a b. (a -> b) -> [a] -> [b]
map (\FilePath
fs -> FilePath -> FilePath -> Maybe Day
parsetimeWith FilePath
fs FilePath
s Maybe Day -> (Day -> Maybe Day) -> Maybe Day
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Day -> Maybe Day
rejectBadYear) [FilePath]
formats :: Maybe Day)
where rejectBadYear :: Day -> Maybe Day
rejectBadYear Day
day = case Day -> (Integer, Int, Int)
toGregorian Day
day of
(Integer
y, Int
_, Int
_) | Integer
y Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= Integer
1601 Bool -> Bool -> Bool
&& Integer
y Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
9999 -> Day -> Maybe Day
forall a. a -> Maybe a
Just Day
day
(Integer, Int, Int)
_ -> Maybe Day
forall a. Maybe a
Nothing
parsetimeWith :: FilePath -> FilePath -> Maybe Day
parsetimeWith = Bool -> TimeLocale -> FilePath -> FilePath -> Maybe Day
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> FilePath -> FilePath -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale
formats :: [FilePath]
formats = [FilePath
"%x",FilePath
"%m/%d/%Y", FilePath
"%D",FilePath
"%F", FilePath
"%d %b %Y",
FilePath
"%e %B %Y", FilePath
"%b. %e, %Y", FilePath
"%B %e, %Y",
FilePath
"%Y%m%d", FilePath
"%Y%m", FilePath
"%Y"]
orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [T.Text]
orderedListMarkers :: (Int, ListNumberStyle, ListNumberDelim) -> [Text]
orderedListMarkers (Int
start, ListNumberStyle
numstyle, ListNumberDelim
numdelim) =
let nums :: [Text]
nums = case ListNumberStyle
numstyle of
ListNumberStyle
DefaultStyle -> (Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Text
forall a. Show a => a -> Text
tshow [Int
start..]
ListNumberStyle
Example -> (Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Text
forall a. Show a => a -> Text
tshow [Int
start..]
ListNumberStyle
Decimal -> (Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Text
forall a. Show a => a -> Text
tshow [Int
start..]
ListNumberStyle
UpperAlpha -> Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
drop (Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
forall a. [a] -> [a]
cycle ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(Char -> Text) -> FilePath -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Text
T.singleton [Char
'A'..Char
'Z']
ListNumberStyle
LowerAlpha -> Int -> [Text] -> [Text]
forall a. Int -> [a] -> [a]
drop (Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ [Text] -> [Text]
forall a. [a] -> [a]
cycle ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$
(Char -> Text) -> FilePath -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Char -> Text
T.singleton [Char
'a'..Char
'z']
ListNumberStyle
UpperRoman -> (Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Text
toRomanNumeral [Int
start..]
ListNumberStyle
LowerRoman -> (Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> Text
T.toLower (Text -> Text) -> (Int -> Text) -> Int -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
toRomanNumeral) [Int
start..]
inDelim :: a -> a
inDelim a
str = case ListNumberDelim
numdelim of
ListNumberDelim
DefaultDelim -> a
str a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"."
ListNumberDelim
Period -> a
str a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
"."
ListNumberDelim
OneParen -> a
str a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
")"
ListNumberDelim
TwoParens -> a
"(" a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
str a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
")"
in (Text -> Text) -> [Text] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Text
forall {a}. (Semigroup a, IsString a) => a -> a
inDelim [Text]
nums
extractSpaces :: (Inlines -> Inlines) -> Inlines -> Inlines
Inlines -> Inlines
f Inlines
is =
let contents :: Seq Inline
contents = Inlines -> Seq Inline
forall a. Many a -> Seq a
B.unMany Inlines
is
left :: Inlines
left = case Seq Inline -> ViewL Inline
forall a. Seq a -> ViewL a
viewl Seq Inline
contents of
(Inline
Space :< Seq Inline
_) -> Inlines
B.space
(Inline
SoftBreak :< Seq Inline
_) -> Inlines
B.softbreak
ViewL Inline
_ -> Inlines
forall a. Monoid a => a
mempty
right :: Inlines
right = case Seq Inline -> ViewR Inline
forall a. Seq a -> ViewR a
viewr Seq Inline
contents of
(Seq Inline
_ :> Inline
Space) -> Inlines
B.space
(Seq Inline
_ :> Inline
SoftBreak) -> Inlines
B.softbreak
ViewR Inline
_ -> Inlines
forall a. Monoid a => a
mempty in
(Inlines
left Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
f (Inlines -> Inlines
B.trimInlines (Inlines -> Inlines)
-> (Seq Inline -> Inlines) -> Seq Inline -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Seq Inline -> Inlines
forall a. Seq a -> Many a
B.Many (Seq Inline -> Inlines) -> Seq Inline -> Inlines
forall a b. (a -> b) -> a -> b
$ Seq Inline
contents) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
right)
removeFormatting :: Walkable Inline a => a -> [Inline]
removeFormatting :: forall a. Walkable Inline a => a -> [Inline]
removeFormatting = (Inline -> [Inline]) -> a -> [Inline]
forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Inline -> [Inline]
go (a -> [Inline]) -> (a -> a) -> a -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Inline) -> a -> a
forall a b. Walkable a b => (a -> a) -> b -> b
walk (Inline -> Inline
deNote (Inline -> Inline) -> (Inline -> Inline) -> Inline -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inline -> Inline
deQuote)
where go :: Inline -> [Inline]
go :: Inline -> [Inline]
go (Str Text
xs) = [Text -> Inline
Str Text
xs]
go Inline
Space = [Inline
Space]
go Inline
SoftBreak = [Inline
SoftBreak]
go (Code Attr
_ Text
x) = [Text -> Inline
Str Text
x]
go (Math MathType
_ Text
x) = [Text -> Inline
Str Text
x]
go Inline
LineBreak = [Inline
Space]
go Inline
_ = []
deNote :: Inline -> Inline
deNote :: Inline -> Inline
deNote (Note [Block]
_) = Text -> Inline
Str Text
""
deNote Inline
x = Inline
x
deLink :: Inline -> Inline
deLink :: Inline -> Inline
deLink (Link Attr
_ [Inline]
ils (Text, Text)
_) = Attr -> [Inline] -> Inline
Span Attr
nullAttr [Inline]
ils
deLink Inline
x = Inline
x
deQuote :: Inline -> Inline
deQuote :: Inline -> Inline
deQuote (Quoted QuoteType
SingleQuote [Inline]
xs) =
Attr -> [Inline] -> Inline
Span (Text
"",[],[]) (Text -> Inline
Str Text
"\8216" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
xs [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str Text
"\8217"])
deQuote (Quoted QuoteType
DoubleQuote [Inline]
xs) =
Attr -> [Inline] -> Inline
Span (Text
"",[],[]) (Text -> Inline
Str Text
"\8220" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
xs [Inline] -> [Inline] -> [Inline]
forall a. [a] -> [a] -> [a]
++ [Text -> Inline
Str Text
"\8221"])
deQuote Inline
x = Inline
x
stringify :: Walkable Inline a => a -> T.Text
stringify :: forall a. Walkable Inline a => a -> Text
stringify = (Inline -> Text) -> a -> Text
forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Inline -> Text
go (a -> Text) -> (a -> a) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Inline) -> a -> a
forall a b. Walkable a b => (a -> a) -> b -> b
walk (Inline -> Inline
deNote (Inline -> Inline) -> (Inline -> Inline) -> Inline -> Inline
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inline -> Inline
deQuote)
where go :: Inline -> T.Text
go :: Inline -> Text
go Inline
Space = Text
" "
go Inline
SoftBreak = Text
" "
go (Str Text
x) = Text
x
go (Code Attr
_ Text
x) = Text
x
go (Math MathType
_ Text
x) = Text
x
go (RawInline (Format Text
"html") (Text -> FilePath
T.unpack -> (Char
'<':Char
'b':Char
'r':FilePath
_)))
= Text
" "
go Inline
LineBreak = Text
" "
go Inline
_ = Text
""
capitalize :: Walkable Inline a => a -> a
capitalize :: forall a. Walkable Inline a => a -> a
capitalize = (Inline -> Inline) -> a -> a
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
go
where go :: Inline -> Inline
go :: Inline -> Inline
go (Str Text
s) = Text -> Inline
Str (Text -> Inline) -> Text -> Inline
forall a b. (a -> b) -> a -> b
$ Text -> Text
T.toUpper Text
s
go Inline
x = Inline
x
compactify :: [Blocks]
-> [Blocks]
compactify :: [Blocks] -> [Blocks]
compactify [] = []
compactify [Blocks]
items =
let ([Blocks]
others, Blocks
final) = ([Blocks] -> [Blocks]
forall a. [a] -> [a]
init [Blocks]
items, [Blocks] -> Blocks
forall a. [a] -> a
last [Blocks]
items)
in case [Block] -> [Block]
forall a. [a] -> [a]
reverse (Blocks -> [Block]
forall a. Many a -> [a]
B.toList Blocks
final) of
(Para [Inline]
a:[Block]
xs)
| [Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Inline] -> Block
Para [Inline]
x | Para [Inline]
x <- [Block]
xs [Block] -> [Block] -> [Block]
forall a. [a] -> [a] -> [a]
++ (Blocks -> [Block]) -> [Blocks] -> [Block]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Blocks -> [Block]
forall a. Many a -> [a]
B.toList [Blocks]
others]
-> [Blocks]
others [Blocks] -> [Blocks] -> [Blocks]
forall a. [a] -> [a] -> [a]
++ [[Block] -> Blocks
forall a. [a] -> Many a
B.fromList ([Block] -> [Block]
forall a. [a] -> [a]
reverse ([Inline] -> Block
Plain [Inline]
a Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
xs))]
[Block]
_ | [Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Inline] -> Block
Para [Inline]
x | Para [Inline]
x <- (Blocks -> [Block]) -> [Blocks] -> [Block]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Blocks -> [Block]
forall a. Many a -> [a]
B.toList [Blocks]
items]
-> [Blocks]
items
[Block]
_ -> (Blocks -> Blocks) -> [Blocks] -> [Blocks]
forall a b. (a -> b) -> [a] -> [b]
map ((Block -> Block) -> Blocks -> Blocks
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Block -> Block
plainToPara) [Blocks]
items
plainToPara :: Block -> Block
plainToPara :: Block -> Block
plainToPara (Plain [Inline]
ils) = [Inline] -> Block
Para [Inline]
ils
plainToPara Block
x = Block
x
compactifyDL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
compactifyDL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
compactifyDL [(Inlines, [Blocks])]
items =
case [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
forall a. [a] -> [a]
reverse [(Inlines, [Blocks])]
items of
((Inlines
t,[Blocks]
ds):[(Inlines, [Blocks])]
ys) ->
case [[Block]] -> [[Block]]
forall a. [a] -> [a]
reverse ((Blocks -> [Block]) -> [Blocks] -> [[Block]]
forall a b. (a -> b) -> [a] -> [b]
map ([Block] -> [Block]
forall a. [a] -> [a]
reverse ([Block] -> [Block]) -> (Blocks -> [Block]) -> Blocks -> [Block]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocks -> [Block]
forall a. Many a -> [a]
B.toList) [Blocks]
ds) of
((Para [Inline]
x:[Block]
xs) : [[Block]]
zs) | Bool -> Bool
not ((Block -> Bool) -> [Block] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Block -> Bool
isPara [Block]
xs) ->
[(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
forall a. [a] -> [a]
reverse [(Inlines, [Blocks])]
ys [(Inlines, [Blocks])]
-> [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
forall a. [a] -> [a] -> [a]
++
[(Inlines
t, [Blocks] -> [Blocks]
forall a. [a] -> [a]
reverse (([Block] -> Blocks) -> [[Block]] -> [Blocks]
forall a b. (a -> b) -> [a] -> [b]
map [Block] -> Blocks
forall a. [a] -> Many a
B.fromList [[Block]]
zs) [Blocks] -> [Blocks] -> [Blocks]
forall a. [a] -> [a] -> [a]
++
[[Block] -> Blocks
forall a. [a] -> Many a
B.fromList ([Block] -> [Block]
forall a. [a] -> [a]
reverse ([Inline] -> Block
Plain [Inline]
xBlock -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:[Block]
xs))])]
[[Block]]
_ -> [(Inlines, [Blocks])]
items
[(Inlines, [Blocks])]
_ -> [(Inlines, [Blocks])]
items
combineLines :: [[Inline]] -> [Inline]
combineLines :: [[Inline]] -> [Inline]
combineLines = [Inline] -> [[Inline]] -> [Inline]
forall a. [a] -> [[a]] -> [a]
intercalate [Inline
LineBreak]
linesToPara :: [[Inline]] -> Block
linesToPara :: [[Inline]] -> Block
linesToPara = [Inline] -> Block
Para ([Inline] -> Block)
-> ([[Inline]] -> [Inline]) -> [[Inline]] -> Block
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Inline]] -> [Inline]
combineLines
isPara :: Block -> Bool
isPara :: Block -> Bool
isPara (Para [Inline]
_) = Bool
True
isPara Block
_ = Bool
False
inlineListToIdentifier :: Extensions -> [Inline] -> T.Text
inlineListToIdentifier :: Extensions -> [Inline] -> Text
inlineListToIdentifier Extensions
exts =
Text -> Text
dropNonLetter (Text -> Text) -> ([Inline] -> Text) -> [Inline] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
filterAscii (Text -> Text) -> ([Inline] -> Text) -> [Inline] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
toIdent (Text -> Text) -> ([Inline] -> Text) -> [Inline] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inline] -> Text
forall a. Walkable Inline a => a -> Text
stringify ([Inline] -> Text) -> ([Inline] -> [Inline]) -> [Inline] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Inline] -> [Inline]) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk [Inline] -> [Inline]
unEmojify
where
unEmojify :: [Inline] -> [Inline]
unEmojify :: [Inline] -> [Inline]
unEmojify
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_gfm_auto_identifiers Extensions
exts Bool -> Bool -> Bool
||
Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_ascii_identifiers Extensions
exts = (Inline -> Inline) -> [Inline] -> [Inline]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
unEmoji
| Bool
otherwise = [Inline] -> [Inline]
forall a. a -> a
id
unEmoji :: Inline -> Inline
unEmoji (Span (Text
"",[Text
"emoji"],[(Text
"data-emoji",Text
ename)]) [Inline]
_) = Text -> Inline
Str Text
ename
unEmoji Inline
x = Inline
x
dropNonLetter :: Text -> Text
dropNonLetter
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_gfm_auto_identifiers Extensions
exts = Text -> Text
forall a. a -> a
id
| Bool
otherwise = (Char -> Bool) -> Text -> Text
T.dropWhile (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isAlpha)
filterAscii :: Text -> Text
filterAscii
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_ascii_identifiers Extensions
exts
= Text -> Text
toAsciiText
| Bool
otherwise = Text -> Text
forall a. a -> a
id
toIdent :: Text -> Text
toIdent
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_gfm_auto_identifiers Extensions
exts =
Text -> Text
filterPunct (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
spaceToDash (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower
| Bool
otherwise = Text -> [Text] -> Text
T.intercalate Text
"-" ([Text] -> Text) -> (Text -> [Text]) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.words (Text -> [Text]) -> (Text -> Text) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
filterPunct (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower
filterPunct :: Text -> Text
filterPunct = (Char -> Bool) -> Text -> Text
T.filter (\Char
c -> Char -> Bool
isSpace Char
c Bool -> Bool -> Bool
|| Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char -> Bool
isAllowedPunct Char
c)
isAllowedPunct :: Char -> Bool
isAllowedPunct Char
c
| Extension -> Extensions -> Bool
extensionEnabled Extension
Ext_gfm_auto_identifiers Extensions
exts
= Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
||
Char -> GeneralCategory
generalCategory Char
c GeneralCategory -> [GeneralCategory] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [GeneralCategory
NonSpacingMark, GeneralCategory
SpacingCombiningMark,
GeneralCategory
EnclosingMark, GeneralCategory
ConnectorPunctuation]
| Bool
otherwise = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'.'
spaceToDash :: Text -> Text
spaceToDash = (Char -> Char) -> Text -> Text
T.map (\Char
c -> if Char -> Bool
isSpace Char
c then Char
'-' else Char
c)
makeSections :: Bool -> Maybe Int -> [Block] -> [Block]
makeSections :: Bool -> Maybe Int -> [Block] -> [Block]
makeSections Bool
numbering Maybe Int
mbBaseLevel [Block]
bs =
State (Maybe Int, [Int]) [Block] -> (Maybe Int, [Int]) -> [Block]
forall s a. State s a -> s -> a
S.evalState ([Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
bs) (Maybe Int
mbBaseLevel, [])
where
go :: [Block] -> S.State (Maybe Int, [Int]) [Block]
go :: [Block] -> State (Maybe Int, [Int]) [Block]
go (Header Int
level (Text
ident,[Text]
classes,[(Text, Text)]
kvs) [Inline]
title':[Block]
xs) = do
(Maybe Int
mbLevel, [Int]
lastnum) <- StateT (Maybe Int, [Int]) Identity (Maybe Int, [Int])
forall s (m :: * -> *). MonadState s m => m s
S.get
let level' :: Int
level' = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
level Maybe Int
mbLevel
let lastnum' :: [Int]
lastnum' = Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
level' [Int]
lastnum
let newnum :: [Int]
newnum =
if Int
level' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then case [Int] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
lastnum' of
Int
x | Text
"unnumbered" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text]
classes -> []
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
level' -> [Int] -> [Int]
forall a. [a] -> [a]
init [Int]
lastnum' [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [[Int] -> Int
forall a. [a] -> a
last [Int]
lastnum' Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1]
| Bool
otherwise -> [Int]
lastnum [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++
Int -> Int -> [Int]
forall a. Int -> a -> [a]
replicate (Int
level' Int -> Int -> Int
forall a. Num a => a -> a -> a
- [Int] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
lastnum Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int
0 [Int] -> [Int] -> [Int]
forall a. [a] -> [a] -> [a]
++ [Int
1]
else []
Bool
-> StateT (Maybe Int, [Int]) Identity ()
-> StateT (Maybe Int, [Int]) Identity ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Int] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
newnum) (StateT (Maybe Int, [Int]) Identity ()
-> StateT (Maybe Int, [Int]) Identity ())
-> StateT (Maybe Int, [Int]) Identity ()
-> StateT (Maybe Int, [Int]) Identity ()
forall a b. (a -> b) -> a -> b
$ ((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
S.modify (((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ())
-> ((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall a b. (a -> b) -> a -> b
$ \(Maybe Int
mbl, [Int]
_) -> (Maybe Int
mbl, [Int]
newnum)
let ([Block]
sectionContents, [Block]
rest) = (Block -> Bool) -> [Block] -> ([Block], [Block])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Int -> Block -> Bool
headerLtEq Int
level) [Block]
xs
((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
S.modify (((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ())
-> ((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall a b. (a -> b) -> a -> b
$ \(Maybe Int
_, [Int]
ln) -> ((Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Maybe Int
mbLevel, [Int]
ln)
[Block]
sectionContents' <- [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
sectionContents
((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
S.modify (((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ())
-> ((Maybe Int, [Int]) -> (Maybe Int, [Int]))
-> StateT (Maybe Int, [Int]) Identity ()
forall a b. (a -> b) -> a -> b
$ \(Maybe Int
_, [Int]
ln) -> (Maybe Int
mbLevel, [Int]
ln)
[Block]
rest' <- [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
rest
let kvs' :: [(Text, Text)]
kvs' =
case Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"number" [(Text, Text)]
kvs of
Maybe Text
Nothing | Bool
numbering
, Text
"unnumbered" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
classes ->
(Text
"number", Text -> [Text] -> Text
T.intercalate Text
"." ((Int -> Text) -> [Int] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Text
forall a. Show a => a -> Text
tshow [Int]
newnum)) (Text, Text) -> [(Text, Text)] -> [(Text, Text)]
forall a. a -> [a] -> [a]
: [(Text, Text)]
kvs
Maybe Text
_ -> [(Text, Text)]
kvs
let divattr :: Attr
divattr = (Text
ident, Text
"section"Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
classes, [(Text, Text)]
kvs')
let attr :: Attr
attr = (Text
"",[Text]
classes,[(Text, Text)]
kvs')
[Block] -> State (Maybe Int, [Int]) [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Block] -> State (Maybe Int, [Int]) [Block])
-> [Block] -> State (Maybe Int, [Int]) [Block]
forall a b. (a -> b) -> a -> b
$
Attr -> [Block] -> Block
Div Attr
divattr (Int -> Attr -> [Inline] -> Block
Header Int
level' Attr
attr [Inline]
title' Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
sectionContents') Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
rest'
go (Div divattr :: Attr
divattr@(Text
dident,[Text]
dclasses,[(Text, Text)]
_) (Header Int
level Attr
hattr [Inline]
title':[Block]
ys) : [Block]
xs)
| (Block -> Bool) -> [Block] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\case
Header Int
level' Attr
_ [Inline]
_ -> Int
level' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
level
Block
_ -> Bool
True) [Block]
ys
, Text
"column" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
dclasses
, Text
"columns" Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
dclasses = do
[Block]
inner <- [Block] -> State (Maybe Int, [Int]) [Block]
go (Int -> Attr -> [Inline] -> Block
Header Int
level Attr
hattr [Inline]
title'Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:[Block]
ys)
[Block]
rest <- [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
xs
[Block] -> State (Maybe Int, [Int]) [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Block] -> State (Maybe Int, [Int]) [Block])
-> [Block] -> State (Maybe Int, [Int]) [Block]
forall a b. (a -> b) -> a -> b
$
case [Block]
inner of
[Div divattr' :: Attr
divattr'@(Text
dident',[Text]
_,[(Text, Text)]
_) [Block]
zs]
| Text -> Bool
T.null Text
dident Bool -> Bool -> Bool
|| Text -> Bool
T.null Text
dident' Bool -> Bool -> Bool
|| Text
dident Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
dident'
-> Attr -> [Block] -> Block
Div (Attr -> Attr -> Attr
combineAttr Attr
divattr' Attr
divattr) [Block]
zs Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
rest
[Block]
_ -> Attr -> [Block] -> Block
Div Attr
divattr [Block]
inner Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
rest
go (Div Attr
attr [Block]
xs : [Block]
rest) = do
[Block]
xs' <- [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
xs
[Block]
rest' <- [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
rest
[Block] -> State (Maybe Int, [Int]) [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Block] -> State (Maybe Int, [Int]) [Block])
-> [Block] -> State (Maybe Int, [Int]) [Block]
forall a b. (a -> b) -> a -> b
$ Attr -> [Block] -> Block
Div Attr
attr [Block]
xs' Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
rest'
go (Block
x:[Block]
xs) = (Block
x Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
:) ([Block] -> [Block])
-> State (Maybe Int, [Int]) [Block]
-> State (Maybe Int, [Int]) [Block]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Block] -> State (Maybe Int, [Int]) [Block]
go [Block]
xs
go [] = [Block] -> State (Maybe Int, [Int]) [Block]
forall (m :: * -> *) a. Monad m => a -> m a
return []
combineAttr :: Attr -> Attr -> Attr
combineAttr :: Attr -> Attr -> Attr
combineAttr (Text
id1, [Text]
classes1, [(Text, Text)]
kvs1) (Text
id2, [Text]
classes2, [(Text, Text)]
kvs2) =
(if Text -> Bool
T.null Text
id1 then Text
id2 else Text
id1,
[Text] -> [Text]
forall a. Ord a => [a] -> [a]
ordNub ([Text]
classes1 [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [Text]
classes2),
((Text, Text) -> [(Text, Text)] -> [(Text, Text)])
-> [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(Text
k,Text
v) [(Text, Text)]
kvs -> case Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
k [(Text, Text)]
kvs of
Maybe Text
Nothing -> (Text
k,Text
v)(Text, Text) -> [(Text, Text)] -> [(Text, Text)]
forall a. a -> [a] -> [a]
:[(Text, Text)]
kvs
Just Text
_ -> [(Text, Text)]
kvs) [(Text, Text)]
forall a. Monoid a => a
mempty ([(Text, Text)]
kvs1 [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. [a] -> [a] -> [a]
++ [(Text, Text)]
kvs2))
headerLtEq :: Int -> Block -> Bool
Int
level (Header Int
l Attr
_ [Inline]
_) = Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
level
headerLtEq Int
level (Div Attr
_ (Block
b:[Block]
_)) = Int -> Block -> Bool
headerLtEq Int
level Block
b
headerLtEq Int
_ Block
_ = Bool
False
uniqueIdent :: Extensions -> [Inline] -> Set.Set T.Text -> T.Text
uniqueIdent :: Extensions -> [Inline] -> Set Text -> Text
uniqueIdent Extensions
exts [Inline]
title' Set Text
usedIdents =
if Text
baseIdent Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
usedIdents
then Text -> (Int -> Text) -> Maybe Int -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
baseIdent Int -> Text
forall a. Show a => a -> Text
numIdent
(Maybe Int -> Text) -> Maybe Int -> Text
forall a b. (a -> b) -> a -> b
$ (Int -> Bool) -> [Int] -> Maybe Int
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (\Int
x -> Int -> Text
forall a. Show a => a -> Text
numIdent Int
x Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.notMember` Set Text
usedIdents) ([Int
1..Int
60000] :: [Int])
else Text
baseIdent
where
baseIdent :: Text
baseIdent = case Extensions -> [Inline] -> Text
inlineListToIdentifier Extensions
exts [Inline]
title' of
Text
"" -> Text
"section"
Text
x -> Text
x
numIdent :: a -> Text
numIdent a
n = Text
baseIdent Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> a -> Text
forall a. Show a => a -> Text
tshow a
n
isHeaderBlock :: Block -> Bool
Header{} = Bool
True
isHeaderBlock Block
_ = Bool
False
headerShift :: Int -> Pandoc -> Pandoc
Int
n (Pandoc Meta
meta (Header Int
m Attr
_ [Inline]
ils : [Block]
bs))
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
, Int
m Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Int -> Pandoc -> Pandoc
headerShift Int
n (Pandoc -> Pandoc) -> Pandoc -> Pandoc
forall a b. (a -> b) -> a -> b
$
Inlines -> Pandoc -> Pandoc
B.setTitle ([Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
ils) (Pandoc -> Pandoc) -> Pandoc -> Pandoc
forall a b. (a -> b) -> a -> b
$ Meta -> [Block] -> Pandoc
Pandoc Meta
meta [Block]
bs
headerShift Int
n (Pandoc Meta
meta [Block]
bs) = Meta -> [Block] -> Pandoc
Pandoc Meta
meta ((Block -> Block) -> [Block] -> [Block]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Block -> Block
shift [Block]
bs)
where
shift :: Block -> Block
shift :: Block -> Block
shift (Header Int
level Attr
attr [Inline]
inner)
| Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 = Int -> Attr -> [Inline] -> Block
Header (Int
level Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
n) Attr
attr [Inline]
inner
| Bool
otherwise = [Inline] -> Block
Para [Inline]
inner
shift Block
x = Block
x
stripEmptyParagraphs :: Pandoc -> Pandoc
stripEmptyParagraphs :: Pandoc -> Pandoc
stripEmptyParagraphs = ([Block] -> [Block]) -> Pandoc -> Pandoc
forall a b. Walkable a b => (a -> a) -> b -> b
walk [Block] -> [Block]
go
where go :: [Block] -> [Block]
go :: [Block] -> [Block]
go = (Block -> Bool) -> [Block] -> [Block]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Block -> Bool) -> Block -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Block -> Bool
isEmptyParagraph)
isEmptyParagraph :: Block -> Bool
isEmptyParagraph (Para []) = Bool
True
isEmptyParagraph Block
_ = Bool
False
onlySimpleTableCells :: [[[Block]]] -> Bool
onlySimpleTableCells :: [[[Block]]] -> Bool
onlySimpleTableCells = ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all [Block] -> Bool
isSimpleCell ([[Block]] -> Bool)
-> ([[[Block]]] -> [[Block]]) -> [[[Block]]] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[[Block]]] -> [[Block]]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
where
isSimpleCell :: [Block] -> Bool
isSimpleCell [Plain [Inline]
ils] = Bool -> Bool
not ([Inline] -> Bool
hasLineBreak [Inline]
ils)
isSimpleCell [Para [Inline]
ils ] = Bool -> Bool
not ([Inline] -> Bool
hasLineBreak [Inline]
ils)
isSimpleCell [] = Bool
True
isSimpleCell [Block]
_ = Bool
False
hasLineBreak :: [Inline] -> Bool
hasLineBreak = Any -> Bool
getAny (Any -> Bool) -> ([Inline] -> Any) -> [Inline] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Inline -> Any) -> [Inline] -> Any
forall a b c. (Walkable a b, Monoid c) => (a -> c) -> b -> c
query Inline -> Any
isLineBreak
isLineBreak :: Inline -> Any
isLineBreak Inline
LineBreak = Bool -> Any
Any Bool
True
isLineBreak Inline
_ = Bool -> Any
Any Bool
False
isTightList :: [[Block]] -> Bool
isTightList :: [[Block]] -> Bool
isTightList = ([Block] -> Bool) -> [[Block]] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\[Block]
item -> [Block] -> Bool
firstIsPlain [Block]
item Bool -> Bool -> Bool
|| [Block] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Block]
item)
where firstIsPlain :: [Block] -> Bool
firstIsPlain (Plain [Inline]
_ : [Block]
_) = Bool
True
firstIsPlain [Block]
_ = Bool
False
taskListItemFromAscii :: Extensions -> [Block] -> [Block]
taskListItemFromAscii :: Extensions -> [Block] -> [Block]
taskListItemFromAscii = ([Inline] -> [Inline]) -> Extensions -> [Block] -> [Block]
handleTaskListItem [Inline] -> [Inline]
fromMd
where
fromMd :: [Inline] -> [Inline]
fromMd (Str Text
"[" : Inline
Space : Str Text
"]" : Inline
Space : [Inline]
is) = Text -> Inline
Str Text
"☐" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is
fromMd (Str Text
"[x]" : Inline
Space : [Inline]
is) = Text -> Inline
Str Text
"☒" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is
fromMd (Str Text
"[X]" : Inline
Space : [Inline]
is) = Text -> Inline
Str Text
"☒" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is
fromMd [Inline]
is = [Inline]
is
taskListItemToAscii :: Extensions -> [Block] -> [Block]
taskListItemToAscii :: Extensions -> [Block] -> [Block]
taskListItemToAscii = ([Inline] -> [Inline]) -> Extensions -> [Block] -> [Block]
handleTaskListItem [Inline] -> [Inline]
toMd
where
toMd :: [Inline] -> [Inline]
toMd (Str Text
"☐" : Inline
Space : [Inline]
is) = Text -> Inline
rawMd Text
"[ ]" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is
toMd (Str Text
"☒" : Inline
Space : [Inline]
is) = Text -> Inline
rawMd Text
"[x]" Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: Inline
Space Inline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
: [Inline]
is
toMd [Inline]
is = [Inline]
is
rawMd :: Text -> Inline
rawMd = Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"markdown")
handleTaskListItem :: ([Inline] -> [Inline]) -> Extensions -> [Block] -> [Block]
handleTaskListItem :: ([Inline] -> [Inline]) -> Extensions -> [Block] -> [Block]
handleTaskListItem [Inline] -> [Inline]
handleInlines Extensions
exts [Block]
bls =
if Extension
Ext_task_lists Extension -> Extensions -> Bool
`extensionEnabled` Extensions
exts
then [Block] -> [Block]
handleItem [Block]
bls
else [Block]
bls
where
handleItem :: [Block] -> [Block]
handleItem (Plain [Inline]
is : [Block]
bs) = [Inline] -> Block
Plain ([Inline] -> [Inline]
handleInlines [Inline]
is) Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
bs
handleItem (Para [Inline]
is : [Block]
bs) = [Inline] -> Block
Para ([Inline] -> [Inline]
handleInlines [Inline]
is) Block -> [Block] -> [Block]
forall a. a -> [a] -> [a]
: [Block]
bs
handleItem [Block]
bs = [Block]
bs
addMetaField :: ToMetaValue a
=> T.Text
-> a
-> Meta
-> Meta
addMetaField :: forall a. ToMetaValue a => Text -> a -> Meta -> Meta
addMetaField Text
key a
val (Meta Map Text MetaValue
meta) =
Map Text MetaValue -> Meta
Meta (Map Text MetaValue -> Meta) -> Map Text MetaValue -> Meta
forall a b. (a -> b) -> a -> b
$ (MetaValue -> MetaValue -> MetaValue)
-> Text -> MetaValue -> Map Text MetaValue -> Map Text MetaValue
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
M.insertWith MetaValue -> MetaValue -> MetaValue
combine Text
key (a -> MetaValue
forall a. ToMetaValue a => a -> MetaValue
toMetaValue a
val) Map Text MetaValue
meta
where combine :: MetaValue -> MetaValue -> MetaValue
combine MetaValue
newval (MetaList [MetaValue]
xs) = [MetaValue] -> MetaValue
MetaList ([MetaValue]
xs [MetaValue] -> [MetaValue] -> [MetaValue]
forall a. [a] -> [a] -> [a]
++ MetaValue -> [MetaValue]
tolist MetaValue
newval)
combine MetaValue
newval MetaValue
x = [MetaValue] -> MetaValue
MetaList [MetaValue
x, MetaValue
newval]
tolist :: MetaValue -> [MetaValue]
tolist (MetaList [MetaValue]
ys) = [MetaValue]
ys
tolist MetaValue
y = [MetaValue
y]
makeMeta :: [Inline] -> [[Inline]] -> [Inline] -> Meta
makeMeta :: [Inline] -> [[Inline]] -> [Inline] -> Meta
makeMeta [Inline]
title [[Inline]]
authors [Inline]
date =
Text -> Inlines -> Meta -> Meta
forall a. ToMetaValue a => Text -> a -> Meta -> Meta
addMetaField Text
"title" ([Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
title)
(Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ Text -> [Inlines] -> Meta -> Meta
forall a. ToMetaValue a => Text -> a -> Meta -> Meta
addMetaField Text
"author" (([Inline] -> Inlines) -> [[Inline]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [[Inline]]
authors)
(Meta -> Meta) -> Meta -> Meta
forall a b. (a -> b) -> a -> b
$ Text -> Inlines -> Meta -> Meta
forall a. ToMetaValue a => Text -> a -> Meta -> Meta
addMetaField Text
"date" ([Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
date) Meta
nullMeta
eastAsianLineBreakFilter :: Pandoc -> Pandoc
eastAsianLineBreakFilter :: Pandoc -> Pandoc
eastAsianLineBreakFilter = ([Inline] -> [Inline]) -> Pandoc -> Pandoc
forall a b. (Data a, Data b) => (a -> a) -> b -> b
bottomUp [Inline] -> [Inline]
go
where go :: [Inline] -> [Inline]
go (Inline
x:Inline
SoftBreak:Inline
y:[Inline]
zs)
| Just (Text
_, Char
b) <- Text -> Maybe (Text, Char)
T.unsnoc (Text -> Maybe (Text, Char)) -> Text -> Maybe (Text, Char)
forall a b. (a -> b) -> a -> b
$ Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify Inline
x
, Just (Char
c, Text
_) <- Text -> Maybe (Char, Text)
T.uncons (Text -> Maybe (Char, Text)) -> Text -> Maybe (Char, Text)
forall a b. (a -> b) -> a -> b
$ Inline -> Text
forall a. Walkable Inline a => a -> Text
stringify Inline
y
, Char -> Int
charWidth Char
b Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2
, Char -> Int
charWidth Char
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
2
= Inline
xInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:Inline
yInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
zs
| Bool
otherwise
= Inline
xInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:Inline
SoftBreakInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:Inline
yInline -> [Inline] -> [Inline]
forall a. a -> [a] -> [a]
:[Inline]
zs
go [Inline]
xs
= [Inline]
xs
htmlSpanLikeElements :: Set.Set T.Text
htmlSpanLikeElements :: Set Text
htmlSpanLikeElements = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList [Text
"kbd", Text
"mark", Text
"dfn"]
filterIpynbOutput :: Maybe Format -> Pandoc -> Pandoc
filterIpynbOutput :: Maybe Format -> Pandoc -> Pandoc
filterIpynbOutput Maybe Format
mode = (Block -> Block) -> Pandoc -> Pandoc
forall a b. Walkable a b => (a -> a) -> b -> b
walk Block -> Block
go
where go :: Block -> Block
go (Div (Text
ident, Text
"output":[Text]
os, [(Text, Text)]
kvs) [Block]
bs) =
case Maybe Format
mode of
Maybe Format
Nothing -> Attr -> [Block] -> Block
Div (Text
ident, Text
"output"Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
os, [(Text, Text)]
kvs) []
Just Format
fmt
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"ipynb"
-> Attr -> [Block] -> Block
Div (Text
ident, Text
"output"Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
os, [(Text, Text)]
kvs) [Block]
bs
| Bool
otherwise -> Attr -> [Block] -> Block
Div (Text
ident, Text
"output"Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:[Text]
os, [(Text, Text)]
kvs) ([Block] -> Block) -> [Block] -> Block
forall a b. (a -> b) -> a -> b
$
(Block -> Block) -> [Block] -> [Block]
forall a b. Walkable a b => (a -> a) -> b -> b
walk Block -> Block
removeANSI ([Block] -> [Block]) -> [Block] -> [Block]
forall a b. (a -> b) -> a -> b
$
Int -> [Block] -> [Block]
forall a. Int -> [a] -> [a]
take Int
1 ([Block] -> [Block]) -> [Block] -> [Block]
forall a b. (a -> b) -> a -> b
$ (Block -> Int) -> [Block] -> [Block]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn Block -> Int
rank [Block]
bs
where
rank :: Block -> Int
rank (RawBlock (Format Text
"html") Text
_)
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"html" = Int
1 :: Int
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"markdown" = Int
3
| Bool
otherwise = Int
4
rank (RawBlock (Format Text
"latex") Text
_)
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"latex" = Int
1
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Format
Format Text
"markdown" = Int
3
| Bool
otherwise = Int
4
rank (RawBlock Format
f Text
_)
| Format
fmt Format -> Format -> Bool
forall a. Eq a => a -> a -> Bool
== Format
f = Int
1
| Bool
otherwise = Int
4
rank (Para [Image{}]) = Int
2
rank Block
_ = Int
3
removeANSI :: Block -> Block
removeANSI (CodeBlock Attr
attr Text
code) =
Attr -> Text -> Block
CodeBlock Attr
attr (Text -> Text
removeANSIEscapes Text
code)
removeANSI Block
x = Block
x
removeANSIEscapes :: Text -> Text
removeANSIEscapes Text
t
| Just Text
cs <- Text -> Text -> Maybe Text
T.stripPrefix Text
"\x1b[" Text
t =
Text -> Text
removeANSIEscapes (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Int -> Text -> Text
T.drop Int
1 (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'm') Text
cs
| Just (Char
c, Text
cs) <- Text -> Maybe (Char, Text)
T.uncons Text
t = Char -> Text -> Text
T.cons Char
c (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Text -> Text
removeANSIEscapes Text
cs
| Bool
otherwise = Text
""
go Block
x = Block
x
renderTags' :: [Tag T.Text] -> T.Text
renderTags' :: [Tag Text] -> Text
renderTags' = RenderOptions Text -> [Tag Text] -> Text
forall str. StringLike str => RenderOptions str -> [Tag str] -> str
renderTagsOptions
RenderOptions Text
forall str. StringLike str => RenderOptions str
renderOptions{ optMinimize :: Text -> Bool
optMinimize = [Text] -> Text -> Bool
forall {t :: * -> *}. Foldable t => t Text -> Text -> Bool
matchTags [Text
"hr", Text
"br", Text
"img",
Text
"meta", Text
"link", Text
"col"]
, optRawTag :: Text -> Bool
optRawTag = [Text] -> Text -> Bool
forall {t :: * -> *}. Foldable t => t Text -> Text -> Bool
matchTags [Text
"script", Text
"style"] }
where matchTags :: t Text -> Text -> Bool
matchTags t Text
tags = (Text -> t Text -> Bool) -> t Text -> Text -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> t Text -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem t Text
tags (Text -> Bool) -> (Text -> Text) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower
inDirectory :: FilePath -> IO a -> IO a
inDirectory :: forall a. FilePath -> IO a -> IO a
inDirectory FilePath
path IO a
action = IO FilePath -> (FilePath -> IO ()) -> (FilePath -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracket
IO FilePath
getCurrentDirectory
FilePath -> IO ()
setCurrentDirectory
(IO a -> FilePath -> IO a
forall a b. a -> b -> a
const (IO a -> FilePath -> IO a) -> IO a -> FilePath -> IO a
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
setCurrentDirectory FilePath
path IO () -> IO a -> IO a
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO a
action)
mapLeft :: (a -> b) -> Either a c -> Either b c
mapLeft :: forall a b c. (a -> b) -> Either a c -> Either b c
mapLeft = (a -> b) -> Either a c -> Either b c
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
Bifunctor.first
collapseFilePath :: FilePath -> FilePath
collapseFilePath :: FilePath -> FilePath
collapseFilePath = [FilePath] -> FilePath
Posix.joinPath ([FilePath] -> FilePath)
-> (FilePath -> [FilePath]) -> FilePath -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FilePath] -> [FilePath]
forall a. [a] -> [a]
reverse ([FilePath] -> [FilePath])
-> (FilePath -> [FilePath]) -> FilePath -> [FilePath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([FilePath] -> FilePath -> [FilePath])
-> [FilePath] -> [FilePath] -> [FilePath]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' [FilePath] -> FilePath -> [FilePath]
go [] ([FilePath] -> [FilePath])
-> (FilePath -> [FilePath]) -> FilePath -> [FilePath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> [FilePath]
splitDirectories
where
go :: [FilePath] -> FilePath -> [FilePath]
go [FilePath]
rs FilePath
"." = [FilePath]
rs
go r :: [FilePath]
r@(FilePath
p:[FilePath]
rs) FilePath
".." = case FilePath
p of
FilePath
".." -> FilePath
".."FilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
:[FilePath]
r
(FilePath -> Maybe Bool
checkPathSeperator -> Just Bool
True) -> FilePath
".."FilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
:[FilePath]
r
FilePath
_ -> [FilePath]
rs
go [FilePath]
_ (FilePath -> Maybe Bool
checkPathSeperator -> Just Bool
True) = [[Char
Posix.pathSeparator]]
go [FilePath]
rs FilePath
x = FilePath
xFilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
:[FilePath]
rs
isSingleton :: [a] -> Maybe a
isSingleton [] = Maybe a
forall a. Maybe a
Nothing
isSingleton [a
x] = a -> Maybe a
forall a. a -> Maybe a
Just a
x
isSingleton [a]
_ = Maybe a
forall a. Maybe a
Nothing
checkPathSeperator :: FilePath -> Maybe Bool
checkPathSeperator = (Char -> Bool) -> Maybe Char -> Maybe Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Char -> Bool
isPathSeparator (Maybe Char -> Maybe Bool)
-> (FilePath -> Maybe Char) -> FilePath -> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Maybe Char
forall {a}. [a] -> Maybe a
isSingleton
uriPathToPath :: T.Text -> FilePath
uriPathToPath :: Text -> FilePath
uriPathToPath (Text -> FilePath
T.unpack -> FilePath
path) =
#ifdef _WINDOWS
case path of
'/':ps -> ps
ps -> ps
#else
FilePath
path
#endif
filteredFilesFromArchive :: Archive -> (FilePath -> Bool) -> [(FilePath, BL.ByteString)]
filteredFilesFromArchive :: Archive -> (FilePath -> Bool) -> [(FilePath, ByteString)]
filteredFilesFromArchive Archive
zf FilePath -> Bool
f =
(FilePath -> Maybe (FilePath, ByteString))
-> [FilePath] -> [(FilePath, ByteString)]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Archive -> FilePath -> Maybe (FilePath, ByteString)
fileAndBinary Archive
zf) ((FilePath -> Bool) -> [FilePath] -> [FilePath]
forall a. (a -> Bool) -> [a] -> [a]
filter FilePath -> Bool
f (Archive -> [FilePath]
filesInArchive Archive
zf))
where
fileAndBinary :: Archive -> FilePath -> Maybe (FilePath, BL.ByteString)
fileAndBinary :: Archive -> FilePath -> Maybe (FilePath, ByteString)
fileAndBinary Archive
a FilePath
fp = FilePath -> Archive -> Maybe Entry
findEntryByPath FilePath
fp Archive
a Maybe Entry
-> (Entry -> Maybe (FilePath, ByteString))
-> Maybe (FilePath, ByteString)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Entry
e -> (FilePath, ByteString) -> Maybe (FilePath, ByteString)
forall a. a -> Maybe a
Just (FilePath
fp, Entry -> ByteString
fromEntry Entry
e)
schemes :: Set.Set T.Text
schemes :: Set Text
schemes = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
Set.fromList
[ Text
"aaa", Text
"aaas", Text
"about", Text
"acap", Text
"acct", Text
"acr", Text
"adiumxtra", Text
"afp", Text
"afs"
, Text
"aim", Text
"appdata", Text
"apt", Text
"attachment", Text
"aw", Text
"barion", Text
"beshare", Text
"bitcoin"
, Text
"blob", Text
"bolo", Text
"browserext", Text
"callto", Text
"cap", Text
"chrome", Text
"chrome-extension"
, Text
"cid", Text
"coap", Text
"coaps", Text
"com-eventbrite-attendee", Text
"content", Text
"crid", Text
"cvs"
, Text
"data", Text
"dav", Text
"dict", Text
"dis", Text
"dlna-playcontainer", Text
"dlna-playsingle"
, Text
"dns", Text
"dntp", Text
"dtn", Text
"dvb", Text
"ed2k", Text
"example", Text
"facetime", Text
"fax", Text
"feed"
, Text
"feedready", Text
"file", Text
"filesystem", Text
"finger", Text
"fish", Text
"ftp", Text
"geo", Text
"gg"
, Text
"git", Text
"gizmoproject", Text
"go", Text
"gopher", Text
"graph", Text
"gtalk", Text
"h323", Text
"ham"
, Text
"hcp", Text
"http", Text
"https", Text
"hxxp", Text
"hxxps", Text
"hydrazone", Text
"iax", Text
"icap", Text
"icon"
, Text
"im", Text
"imap", Text
"info", Text
"iotdisco", Text
"ipn", Text
"ipp", Text
"ipps", Text
"irc", Text
"irc6"
, Text
"ircs", Text
"iris", Text
"iris.beep", Text
"iris.lwz", Text
"iris.xpc", Text
"iris.xpcs"
, Text
"isostore", Text
"itms", Text
"jabber", Text
"jar", Text
"jms", Text
"keyparc", Text
"lastfm", Text
"ldap"
, Text
"ldaps", Text
"lvlt", Text
"magnet", Text
"mailserver", Text
"mailto", Text
"maps", Text
"market"
, Text
"message", Text
"mid", Text
"mms", Text
"modem", Text
"mongodb", Text
"moz", Text
"ms-access"
, Text
"ms-browser-extension", Text
"ms-drive-to", Text
"ms-enrollment", Text
"ms-excel"
, Text
"ms-gamebarservices", Text
"ms-getoffice", Text
"ms-help", Text
"ms-infopath"
, Text
"ms-media-stream-id", Text
"ms-officeapp", Text
"ms-project", Text
"ms-powerpoint"
, Text
"ms-publisher", Text
"ms-search-repair", Text
"ms-secondary-screen-controller"
, Text
"ms-secondary-screen-setup", Text
"ms-settings", Text
"ms-settings-airplanemode"
, Text
"ms-settings-bluetooth", Text
"ms-settings-camera", Text
"ms-settings-cellular"
, Text
"ms-settings-cloudstorage", Text
"ms-settings-connectabledevices"
, Text
"ms-settings-displays-topology", Text
"ms-settings-emailandaccounts"
, Text
"ms-settings-language", Text
"ms-settings-location", Text
"ms-settings-lock"
, Text
"ms-settings-nfctransactions", Text
"ms-settings-notifications"
, Text
"ms-settings-power", Text
"ms-settings-privacy", Text
"ms-settings-proximity"
, Text
"ms-settings-screenrotation", Text
"ms-settings-wifi", Text
"ms-settings-workplace"
, Text
"ms-spd", Text
"ms-sttoverlay", Text
"ms-transit-to", Text
"ms-virtualtouchpad"
, Text
"ms-visio", Text
"ms-walk-to", Text
"ms-whiteboard", Text
"ms-whiteboard-cmd", Text
"ms-word"
, Text
"msnim", Text
"msrp", Text
"msrps", Text
"mtqp", Text
"mumble", Text
"mupdate", Text
"mvn", Text
"news", Text
"nfs"
, Text
"ni", Text
"nih", Text
"nntp", Text
"notes", Text
"ocf", Text
"oid", Text
"onenote", Text
"onenote-cmd"
, Text
"opaquelocktoken", Text
"pack", Text
"palm", Text
"paparazzi", Text
"pkcs11", Text
"platform", Text
"pop"
, Text
"pres", Text
"prospero", Text
"proxy", Text
"pwid", Text
"psyc", Text
"qb", Text
"query", Text
"redis"
, Text
"rediss", Text
"reload", Text
"res", Text
"resource", Text
"rmi", Text
"rsync", Text
"rtmfp", Text
"rtmp"
, Text
"rtsp", Text
"rtsps", Text
"rtspu", Text
"secondlife", Text
"service", Text
"session", Text
"sftp", Text
"sgn"
, Text
"shttp", Text
"sieve", Text
"sip", Text
"sips", Text
"skype", Text
"smb", Text
"sms", Text
"smtp", Text
"snews"
, Text
"snmp", Text
"soap.beep", Text
"soap.beeps", Text
"soldat", Text
"spotify", Text
"ssh", Text
"steam"
, Text
"stun", Text
"stuns", Text
"submit", Text
"svn", Text
"tag", Text
"teamspeak", Text
"tel", Text
"teliaeid"
, Text
"telnet", Text
"tftp", Text
"things", Text
"thismessage", Text
"tip", Text
"tn3270", Text
"tool", Text
"turn"
, Text
"turns", Text
"tv", Text
"udp", Text
"unreal", Text
"urn", Text
"ut2004", Text
"v-event", Text
"vemmi"
, Text
"ventrilo", Text
"videotex", Text
"vnc", Text
"view-source", Text
"wais", Text
"webcal", Text
"wpid"
, Text
"ws", Text
"wss", Text
"wtai", Text
"wyciwyg", Text
"xcon", Text
"xcon-userid", Text
"xfire"
, Text
"xmlrpc.beep", Text
"xmlrpc.beeps", Text
"xmpp", Text
"xri", Text
"ymsgr", Text
"z39.50", Text
"z39.50r"
, Text
"z39.50s"
, Text
"doi", Text
"isbn", Text
"javascript", Text
"pmid"
]
isURI :: T.Text -> Bool
isURI :: Text -> Bool
isURI = Bool -> (URI -> Bool) -> Maybe URI -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False URI -> Bool
hasKnownScheme (Maybe URI -> Bool) -> (Text -> Maybe URI) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Maybe URI
parseURI (FilePath -> Maybe URI) -> (Text -> FilePath) -> Text -> Maybe URI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
where
hasKnownScheme :: URI -> Bool
hasKnownScheme = (Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Text
schemes) (Text -> Bool) -> (URI -> Text) -> URI -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
T.toLower (Text -> Text) -> (URI -> Text) -> URI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(Char -> Bool) -> Text -> Text
T.filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
':') (Text -> Text) -> (URI -> Text) -> URI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack (FilePath -> Text) -> (URI -> FilePath) -> URI -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. URI -> FilePath
uriScheme
blockToInlines :: Block -> Inlines
blockToInlines :: Block -> Inlines
blockToInlines (Plain [Inline]
ils) = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
ils
blockToInlines (Para [Inline]
ils) = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
ils
blockToInlines (LineBlock [[Inline]]
lns) = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList ([Inline] -> Inlines) -> [Inline] -> Inlines
forall a b. (a -> b) -> a -> b
$ [[Inline]] -> [Inline]
combineLines [[Inline]]
lns
blockToInlines (CodeBlock Attr
attr Text
str) = Attr -> Text -> Inlines
B.codeWith Attr
attr Text
str
blockToInlines (RawBlock (Format Text
fmt) Text
str) = Text -> Text -> Inlines
B.rawInline Text
fmt Text
str
blockToInlines (BlockQuote [Block]
blks) = [Block] -> Inlines
blocksToInlines' [Block]
blks
blockToInlines (OrderedList (Int, ListNumberStyle, ListNumberDelim)
_ [[Block]]
blkslst) =
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ ([Block] -> Inlines) -> [[Block]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Block] -> Inlines
blocksToInlines' [[Block]]
blkslst
blockToInlines (BulletList [[Block]]
blkslst) =
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ ([Block] -> Inlines) -> [[Block]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Block] -> Inlines
blocksToInlines' [[Block]]
blkslst
blockToInlines (DefinitionList [([Inline], [[Block]])]
pairslst) =
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ (([Inline], [[Block]]) -> Inlines)
-> [([Inline], [[Block]])] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map ([Inline], [[Block]]) -> Inlines
f [([Inline], [[Block]])]
pairslst
where
f :: ([Inline], [[Block]]) -> Inlines
f ([Inline]
ils, [[Block]]
blkslst) = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
ils Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
B.str Text
":" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat (([Block] -> Inlines) -> [[Block]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Block] -> Inlines
blocksToInlines' [[Block]]
blkslst)
blockToInlines (Header Int
_ Attr
_ [Inline]
ils) = [Inline] -> Inlines
forall a. [a] -> Many a
B.fromList [Inline]
ils
blockToInlines Block
HorizontalRule = Inlines
forall a. Monoid a => a
mempty
blockToInlines (Table Attr
_ Caption
_ [ColSpec]
_ (TableHead Attr
_ [Row]
hbd) [TableBody]
bodies (TableFoot Attr
_ [Row]
fbd)) =
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines) -> [Inlines] -> Inlines
forall a b. (a -> b) -> a -> b
$ Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
B.linebreak ([Inlines] -> [Inlines]) -> [Inlines] -> [Inlines]
forall a b. (a -> b) -> a -> b
$
([[Block]] -> Inlines) -> [[[Block]]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([[Block]] -> [Inlines]) -> [[Block]] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Block] -> Inlines) -> [[Block]] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map [Block] -> Inlines
blocksToInlines') (Row -> [[Block]]
plainRowBody (Row -> [[Block]]) -> [Row] -> [[[Block]]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Row]
hbd [Row] -> [Row] -> [Row]
forall a. Semigroup a => a -> a -> a
<> [TableBody] -> [Row]
unTableBodies [TableBody]
bodies [Row] -> [Row] -> [Row]
forall a. Semigroup a => a -> a -> a
<> [Row]
fbd)
where
plainRowBody :: Row -> [[Block]]
plainRowBody (Row Attr
_ [Cell]
body) = Cell -> [Block]
cellBody (Cell -> [Block]) -> [Cell] -> [[Block]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Cell]
body
cellBody :: Cell -> [Block]
cellBody (Cell Attr
_ Alignment
_ RowSpan
_ ColSpan
_ [Block]
body) = [Block]
body
unTableBody :: TableBody -> [Row]
unTableBody (TableBody Attr
_ RowHeadColumns
_ [Row]
hd [Row]
bd) = [Row]
hd [Row] -> [Row] -> [Row]
forall a. Semigroup a => a -> a -> a
<> [Row]
bd
unTableBodies :: [TableBody] -> [Row]
unTableBodies = (TableBody -> [Row]) -> [TableBody] -> [Row]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TableBody -> [Row]
unTableBody
blockToInlines (Div Attr
_ [Block]
blks) = [Block] -> Inlines
blocksToInlines' [Block]
blks
blockToInlines Block
Null = Inlines
forall a. Monoid a => a
mempty
blocksToInlinesWithSep :: Inlines -> [Block] -> Inlines
blocksToInlinesWithSep :: Inlines -> [Block] -> Inlines
blocksToInlinesWithSep Inlines
sep =
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Block] -> [Inlines]) -> [Block] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse Inlines
sep ([Inlines] -> [Inlines])
-> ([Block] -> [Inlines]) -> [Block] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Block -> Inlines) -> [Block] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Block -> Inlines
blockToInlines
blocksToInlines' :: [Block] -> Inlines
blocksToInlines' :: [Block] -> Inlines
blocksToInlines' = Inlines -> [Block] -> Inlines
blocksToInlinesWithSep Inlines
defaultBlocksSeparator
blocksToInlines :: [Block] -> [Inline]
blocksToInlines :: [Block] -> [Inline]
blocksToInlines = Inlines -> [Inline]
forall a. Many a -> [a]
B.toList (Inlines -> [Inline])
-> ([Block] -> Inlines) -> [Block] -> [Inline]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Block] -> Inlines
blocksToInlines'
defaultBlocksSeparator :: Inlines
defaultBlocksSeparator :: Inlines
defaultBlocksSeparator =
Inlines
B.space Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
B.str Text
"¶" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
B.space
safeRead :: (MonadPlus m, Read a) => T.Text -> m a
safeRead :: forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead = FilePath -> m a
forall (m :: * -> *) a. (MonadPlus m, Read a) => FilePath -> m a
safeStrRead (FilePath -> m a) -> (Text -> FilePath) -> Text -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack
safeStrRead :: (MonadPlus m, Read a) => String -> m a
safeStrRead :: forall (m :: * -> *) a. (MonadPlus m, Read a) => FilePath -> m a
safeStrRead FilePath
s = case ReadS a
forall a. Read a => ReadS a
reads FilePath
s of
(a
d,FilePath
x):[(a, FilePath)]
_
| (Char -> Bool) -> FilePath -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace FilePath
x -> a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
d
[(a, FilePath)]
_ -> m a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
defaultUserDataDir :: IO FilePath
defaultUserDataDir :: IO FilePath
defaultUserDataDir = do
FilePath
xdgDir <- IO FilePath -> (SomeException -> IO FilePath) -> IO FilePath
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
E.catch (XdgDirectory -> FilePath -> IO FilePath
getXdgDirectory XdgDirectory
XdgData FilePath
"pandoc")
(\(SomeException
_ :: E.SomeException) -> FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
forall a. Monoid a => a
mempty)
FilePath
legacyDir <- FilePath -> IO FilePath
getAppUserDataDirectory FilePath
"pandoc"
Bool
xdgExists <- FilePath -> IO Bool
doesDirectoryExist FilePath
xdgDir
Bool
legacyDirExists <- FilePath -> IO Bool
doesDirectoryExist FilePath
legacyDir
if Bool -> Bool
not Bool
xdgExists Bool -> Bool -> Bool
&& Bool
legacyDirExists
then FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
legacyDir
else FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
xdgDir