{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Redundant bracket" #-}
module Converter (hsToMd, mdToHs, lhsToMd, mdToLhs, Config (..), ConfigHsMd (..)) where
import Data.Default (Default)
import Data.List (isPrefixOf, isSuffixOf)
import Data.Yaml (FromJSON (..))
import Data.Yaml.Aeson (withObject, (.:), (.:?))
import GHC.Generics (Generic)
newtype Config = Config {Config -> Maybe ConfigHsMd
configHsMd :: Maybe ConfigHsMd} deriving (forall x. Rep Config x -> Config
forall x. Config -> Rep Config x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Config x -> Config
$cfrom :: forall x. Config -> Rep Config x
Generic, Config
forall a. a -> Default a
def :: Config
$cdef :: Config
Default)
instance FromJSON Config where
parseJSON :: Value -> Parser Config
parseJSON = forall a. [Char] -> (Object -> Parser a) -> Value -> Parser a
withObject [Char]
"Configs" (\Object
v -> Maybe ConfigHsMd -> Config
Config forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"hs-md")
newtype ConfigHsMd = ConfigHs2Md { :: [String]} deriving (forall x. Rep ConfigHsMd x -> ConfigHsMd
forall x. ConfigHsMd -> Rep ConfigHsMd x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfigHsMd x -> ConfigHsMd
$cfrom :: forall x. ConfigHsMd -> Rep ConfigHsMd x
Generic, ConfigHsMd
forall a. a -> Default a
def :: ConfigHsMd
$cdef :: ConfigHsMd
Default)
instance FromJSON ConfigHsMd where
parseJSON :: Value -> Parser ConfigHsMd
parseJSON =
forall a. [Char] -> (Object -> Parser a) -> Value -> Parser a
withObject
[Char]
"CommentsToIgnore"
(\Object
v -> [[Char]] -> ConfigHsMd
ConfigHs2Md forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"special-comments")
backticks :: String
backticks :: [Char]
backticks = [Char]
"```"
haskellSnippet :: String
haskellSnippet :: [Char]
haskellSnippet = [Char]
backticks forall a. [a] -> [a] -> [a]
++ [Char]
"haskell"
consoleSnippet :: String
consoleSnippet :: [Char]
consoleSnippet = [Char]
backticks forall a. [a] -> [a] -> [a]
++ [Char]
"console"
chooseSnippetType :: String -> String
chooseSnippetType :: [Char] -> [Char]
chooseSnippetType [Char]
s
| [Char]
s [Char] -> [Char] -> Bool
`startsWith` [Char]
birdTrack = [Char]
haskellSnippet
| Bool
otherwise = [Char]
consoleSnippet
birdTrack :: String
birdTrack :: [Char]
birdTrack = [Char]
"> "
reverseBirdTrack :: String
reverseBirdTrack :: [Char]
reverseBirdTrack = [Char]
"< "
birdTracks :: [String]
birdTracks :: [[Char]]
birdTracks = [[Char]
birdTrack, [Char]
reverseBirdTrack]
lhsToMd :: String -> String
lhsToMd :: [Char] -> [Char]
lhsToMd = [[Char]] -> [Char]
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]] -> [[Char]]
convert [Char]
"" forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
lines
where
convert :: String -> [String] -> [String]
convert :: [Char] -> [[Char]] -> [[Char]]
convert [Char]
prev []
|
[Char]
prev [Char] -> [[Char]] -> Bool
`startsWithAnyOf` [[Char]]
birdTracks =
[[Char]
backticks]
| Bool
otherwise = []
convert [Char]
prev ([Char]
h : [[Char]]
t)
|
Bool -> Bool
not ([Char]
prev [Char] -> [[Char]] -> Bool
`startsWithAnyOf` [[Char]]
birdTracks)
Bool -> Bool -> Bool
&& ([Char]
h [Char] -> [[Char]] -> Bool
`startsWithAnyOf` [[Char]]
birdTracks) =
([[Char]
"" | [Char]
prev forall a. Eq a => a -> a -> Bool
/= [Char]
""]) forall a. [a] -> [a] -> [a]
++ [[Char] -> [Char]
chooseSnippetType [Char]
h, forall a. Int -> [a] -> [a]
drop Int
2 [Char]
h] forall a. [a] -> [a] -> [a]
++ [[Char]]
rest
|
[Char]
h [Char] -> [[Char]] -> Bool
`startsWithAnyOf` [[Char]]
birdTracks =
forall a. Int -> [a] -> [a]
drop Int
2 [Char]
h forall a. a -> [a] -> [a]
: [[Char]]
rest
|
[Char]
prev [Char] -> [[Char]] -> Bool
`startsWithAnyOf` [[Char]]
birdTracks =
[[Char]
backticks] forall a. [a] -> [a] -> [a]
++ ([[Char]
"" | [Char]
h forall a. Eq a => a -> a -> Bool
/= [Char]
""]) forall a. [a] -> [a] -> [a]
++ [[Char]
h] forall a. [a] -> [a] -> [a]
++ [[Char]]
rest
| [Char]
h [Char] -> [Char] -> Bool
`startsWith` (Char
' ' forall a. a -> [a] -> [a]
: [Char]
birdTrack) =
forall a. Int -> [a] -> [a]
drop Int
1 [Char]
h forall a. a -> [a] -> [a]
: [[Char]]
rest
| Bool
otherwise = [Char] -> [[Char]]
shiftIfHeader [Char]
h forall a. [a] -> [a] -> [a]
++ [[Char]]
rest
where
rest :: [[Char]]
rest = [Char] -> [[Char]] -> [[Char]]
convert [Char]
h [[Char]]
t
mdToLhs :: String -> String
mdToLhs :: [Char] -> [Char]
mdToLhs = [[Char]] -> [Char]
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False [Char]
"" forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
lines
where
convert :: Bool -> Bool -> String -> [String] -> [String]
convert :: Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
inHsCode Bool
inSample [Char]
prev [] = []
convert Bool
inHsCode Bool
inSample [Char]
prev ([Char]
h : [[Char]]
t)
|
[Char]
h forall a. Eq a => a -> a -> Bool
== [Char]
haskellSnippet =
([[Char]
"" | [Char]
prev forall a. Eq a => a -> a -> Bool
/= [Char]
""]) forall a. [a] -> [a] -> [a]
++ Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False [Char]
prev [[Char]]
t
|
Bool
inHsCode Bool -> Bool -> Bool
&& [Char]
h forall a. Eq a => a -> a -> Bool
/= [Char]
backticks =
([Char]
"> " forall a. [a] -> [a] -> [a]
++ [Char]
h) forall a. a -> [a] -> [a]
: Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False [Char]
h [[Char]]
t
|
Bool
inSample Bool -> Bool -> Bool
&& [Char]
h forall a. Eq a => a -> a -> Bool
/= [Char]
backticks =
([Char]
"< " forall a. [a] -> [a] -> [a]
++ [Char]
h) forall a. a -> [a] -> [a]
: Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
False Bool
True [Char]
h [[Char]]
t
|
[Char] -> Bool
isHeading [Char]
h =
(Char
' ' forall a. a -> [a] -> [a]
: [Char]
h) forall a. a -> [a] -> [a]
: [[Char]]
rest
|
(Bool
inHsCode Bool -> Bool -> Bool
|| Bool
inSample)
Bool -> Bool -> Bool
&& [Char]
h forall a. Eq a => a -> a -> Bool
== [Char]
backticks =
([[Char]
"" | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [[Char]]
t Bool -> Bool -> Bool
|| forall a. [a] -> a
head [[Char]]
t forall a. Eq a => a -> a -> Bool
/= [Char]
""])
forall a. [a] -> [a] -> [a]
++ Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False [Char]
prev [[Char]]
t
|
forall a. Int -> [a] -> [a]
take Int
3 [Char]
h forall a. Eq a => a -> a -> Bool
== [Char]
backticks =
([[Char]
"" | [Char]
prev forall a. Eq a => a -> a -> Bool
/= [Char]
""]) forall a. [a] -> [a] -> [a]
++ Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
False Bool
True [Char]
prev [[Char]]
t
|
[Char]
h [Char] -> [Char] -> Bool
`startsWith` [Char]
birdTrack =
([Char]
" >" forall a. [a] -> [a] -> [a]
++ forall a. Int -> [a] -> [a]
drop Int
1 [Char]
h) forall a. a -> [a] -> [a]
: [[Char]]
rest
| Bool
otherwise = [Char]
h forall a. a -> [a] -> [a]
: [[Char]]
rest
where
isHeading :: [Char] -> Bool
isHeading [Char]
h = Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null (forall a. (a -> Bool) -> [a] -> [a]
takeWhile (forall a. Eq a => a -> a -> Bool
== Char
'#') [Char]
h))
rest :: [[Char]]
rest = Bool -> Bool -> [Char] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False [Char]
h [[Char]]
t
startsWith :: String -> String -> Bool
startsWith :: [Char] -> [Char] -> Bool
startsWith = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf
startsWithAnyOf :: String -> [String] -> Bool
startsWithAnyOf :: [Char] -> [[Char]] -> Bool
startsWithAnyOf [Char]
l = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ([Char] -> [Char] -> Bool
startsWith [Char]
l)
shiftIfHeader :: String -> [String]
[Char]
"" = [[Char]
""]
shiftIfHeader (Char
' ' : Char
'#' : [Char]
x) = [Char
'#' forall a. a -> [a] -> [a]
: [Char]
x]
shiftIfHeader [Char]
x = [[Char]
x]
_LIMA_DISABLE :: String
_LIMA_DISABLE :: [Char]
_LIMA_DISABLE = [Char]
"LIMA_DISABLE"
_LIMA_ENABLE :: String
_LIMA_ENABLE :: [Char]
_LIMA_ENABLE = [Char]
"LIMA_ENABLE"
specialCommentsDefault :: [String]
= [[Char]
"FOURMOLU_DISABLE", [Char]
"FOURMOLU_ENABLE"]
endsWith :: String -> String -> Bool
endsWith :: [Char] -> [Char] -> Bool
endsWith = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Eq a => [a] -> [a] -> Bool
isSuffixOf
mcOpen :: String
mcOpen :: [Char]
mcOpen = [Char]
"{-"
mcOpenSpace :: String
mcOpenSpace :: [Char]
mcOpenSpace = [Char]
mcOpen forall a. [a] -> [a] -> [a]
++ [Char]
" "
mcClose :: String
mcClose :: [Char]
mcClose = [Char]
"-}"
mcCloseSpace :: String
mcCloseSpace :: [Char]
mcCloseSpace = [Char]
" -}"
dropEnd :: Int -> String -> String
dropEnd :: Int -> [Char] -> [Char]
dropEnd Int
n [Char]
s = forall a. [a] -> [a]
reverse (forall a. Int -> [a] -> [a]
drop Int
n (forall a. [a] -> [a]
reverse [Char]
s))
backticksHs :: String
backticksHs :: [Char]
backticksHs = [Char]
backticks forall a. [a] -> [a] -> [a]
++ [Char]
"haskell"
dropEmpties :: [String] -> [String]
dropEmpties :: [[Char]] -> [[Char]]
dropEmpties = forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
== [Char]
"")
mdcOpen :: String
mdcOpen :: [Char]
mdcOpen = [Char]
"<!--"
mdcClose :: String
mdcClose :: [Char]
mdcClose = [Char]
"-->"
mdcOpenSpace :: String
mdcOpenSpace :: [Char]
mdcOpenSpace = [Char]
mdcOpen forall a. [a] -> [a] -> [a]
++ [Char]
" "
mdcCloseSpace :: String
mdcCloseSpace :: [Char]
mdcCloseSpace = [Char]
" " forall a. [a] -> [a] -> [a]
++ [Char]
mdcClose
stripMc :: String -> String
stripMc :: [Char] -> [Char]
stripMc [Char]
x = Int -> [Char] -> [Char]
dropEnd (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
mcCloseSpace) (forall a. Int -> [a] -> [a]
drop (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
mcOpenSpace) [Char]
x)
hsToMd :: ConfigHsMd -> String -> String
hsToMd :: ConfigHsMd -> [Char] -> [Char]
hsToMd ConfigHs2Md{[[Char]]
specialComments :: [[Char]]
specialComments :: ConfigHsMd -> [[Char]]
..} = [[Char]] -> [Char]
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
== [Char]
"") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\[[Char]]
x -> Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False Bool
False [[Char]]
x []) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
lines
where
specialComments_ :: [[Char]]
specialComments_ = [[Char]]
specialCommentsDefault forall a. [a] -> [a] -> [a]
++ [[Char]]
specialComments
convert :: Bool -> Bool -> Bool -> [String] -> [String] -> [String]
convert :: Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
inComments Bool
inSnippet ([Char]
h : [[Char]]
hs) [[Char]]
res
| Bool -> Bool
not Bool
inComments =
if
|
[Char]
h [Char] -> [Char] -> Bool
`startsWith` ([Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_DISABLE) ->
(Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
False [[Char]]
hs)
([[Char]
mdcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_DISABLE] forall a. [a] -> [a] -> [a]
++ [[Char]
backticks | Bool
inSnippet] forall a. [a] -> [a] -> [a]
++ [[Char]]
res)
|
[Char]
h [Char] -> [Char] -> Bool
`startsWith` ([Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_ENABLE) ->
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False Bool
inSnippet [[Char]]
hs (([Char]
_LIMA_ENABLE forall a. [a] -> [a] -> [a]
++ [Char]
mdcCloseSpace) forall a. a -> [a] -> [a]
: [[Char]]
res)
|
Bool -> Bool
not Bool
inLimaEnable ->
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
False [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
|
[Char]
h [Char] -> [[Char]] -> Bool
`startsWithAnyOf` (([Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Char]]
specialComments_) ->
(Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
False [[Char]]
hs)
([[Char]
mdcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
stripMc [Char]
h forall a. [a] -> [a] -> [a]
++ [Char]
mdcCloseSpace] forall a. [a] -> [a] -> [a]
++ [[Char]
"" | Bool
inSnippet] forall a. [a] -> [a] -> [a]
++ [[Char]
backticks | Bool
inSnippet] forall a. [a] -> [a] -> [a]
++ [[Char]] -> [[Char]]
dropEmpties [[Char]]
res)
|
([Char]
h [Char] -> [Char] -> Bool
`startsWith` [Char]
mcOpenSpace Bool -> Bool -> Bool
|| [Char]
h forall a. Eq a => a -> a -> Bool
== [Char]
mcOpen) ->
let x' :: [Char]
x' = forall a. Int -> [a] -> [a]
drop Int
3 [Char]
h
pref :: [[Char]]
pref = [Char]
"" forall a. a -> [a] -> [a]
: [[Char]
backticks | Bool
inSnippet]
res' :: [[Char]]
res' = if Bool
inSnippet then [[Char]] -> [[Char]]
dropEmpties [[Char]]
res else [[Char]]
res
in
if [Char]
h [Char] -> [Char] -> Bool
`endsWith` [Char]
mcClose
then Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
False [[Char]]
hs ([Int -> [Char] -> [Char]
dropEnd (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
mcCloseSpace) [Char]
x'] forall a. [a] -> [a] -> [a]
++ [[Char]]
pref forall a. [a] -> [a] -> [a]
++ [[Char]]
res')
else Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
True Bool
False [[Char]]
hs ([[Char]
x' | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
x')] forall a. [a] -> [a] -> [a]
++ [[Char]]
pref forall a. [a] -> [a] -> [a]
++ [[Char]]
res')
|
Bool -> Bool
not Bool
inSnippet ->
if Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
h)
then
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
True [[Char]]
hs ([[Char]
h, [Char]
backticksHs] forall a. [a] -> [a] -> [a]
++ [[Char]] -> [[Char]]
squashEmpties [[Char]]
res)
else
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
False [[Char]]
hs [[Char]]
res
| Bool
inSnippet ->
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
True [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
| Bool
inComments =
if
[Char]
h [Char] -> [Char] -> Bool
`startsWith` [Char]
mcClose
then Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
False Bool
False [[Char]]
hs [[Char]]
res
else
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inLimaEnable Bool
True Bool
False [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
convert Bool
_ Bool
_ Bool
inSnippet [] [[Char]]
res =
[[Char]
backticks | Bool
inSnippet] forall a. [a] -> [a] -> [a]
++ [[Char]] -> [[Char]]
dropEmpties [[Char]]
res
stripMdc :: String -> String
stripMdc :: [Char] -> [Char]
stripMdc [Char]
x = Int -> [Char] -> [Char]
dropEnd (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
mdcCloseSpace) (forall a. Int -> [a] -> [a]
drop (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
mdcOpenSpace) [Char]
x)
squashEmpties :: [String] -> [String]
squashEmpties :: [[Char]] -> [[Char]]
squashEmpties = ([[Char]
""] forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Char]] -> [[Char]]
dropEmpties
mdToHs :: ConfigHsMd -> String -> String
mdToHs :: ConfigHsMd -> [Char] -> [Char]
mdToHs ConfigHs2Md{[[Char]]
specialComments :: [[Char]]
specialComments :: ConfigHsMd -> [[Char]]
..} = [[Char]] -> [Char]
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. (a -> Bool) -> [a] -> [a]
dropWhile (forall a. Eq a => a -> a -> Bool
== [Char]
"") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
reverse forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\[[Char]]
x -> Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
False [[Char]]
x []) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [[Char]]
lines
where
specialComments_ :: [[Char]]
specialComments_ = [[Char]]
specialCommentsDefault forall a. [a] -> [a] -> [a]
++ [[Char]]
specialComments
closeTextIf :: Bool -> [[Char]]
closeTextIf Bool
x = [[Char]
mcClose | Bool
x]
convert :: Bool -> Bool -> Bool -> [String] -> [String] -> [String]
convert :: Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inText Bool
inSnippet Bool
inComments ([Char]
h : [[Char]]
hs) [[Char]]
res
| Bool
inComments =
if
[Char]
h [Char] -> [Char] -> Bool
`startsWith` ([Char]
_LIMA_ENABLE forall a. [a] -> [a] -> [a]
++ [Char]
mdcCloseSpace)
then
(Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inText Bool
inSnippet Bool
False [[Char]]
hs)
([[Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_ENABLE forall a. [a] -> [a] -> [a]
++ [Char]
mcCloseSpace] forall a. [a] -> [a] -> [a]
++ [[Char]
"" | Bool
inText] forall a. [a] -> [a] -> [a]
++ Bool -> [[Char]]
closeTextIf Bool
inText forall a. [a] -> [a] -> [a]
++ [[Char]]
res)
else
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
True [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
| Bool -> Bool
not Bool
inSnippet =
if
|
[Char]
h [Char] -> [Char] -> Bool
`startsWith` ([Char]
mdcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_DISABLE) ->
(Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
True [[Char]]
hs)
([[Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char]
_LIMA_DISABLE forall a. [a] -> [a] -> [a]
++ [Char]
mcCloseSpace] forall a. [a] -> [a] -> [a]
++ [[Char]
"" | Bool
inText] forall a. [a] -> [a] -> [a]
++ Bool -> [[Char]]
closeTextIf Bool
inText forall a. [a] -> [a] -> [a]
++ [[Char]]
res)
|
[Char]
h [Char] -> [[Char]] -> Bool
`startsWithAnyOf` (([Char]
mdcOpenSpace forall a. [a] -> [a] -> [a]
++) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Char]]
specialComments_) ->
(Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
False [[Char]]
hs)
([[Char]
mcOpenSpace forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
stripMdc [Char]
h forall a. [a] -> [a] -> [a]
++ [Char]
mcCloseSpace] forall a. [a] -> [a] -> [a]
++ [[Char]
"" | Bool
inText] forall a. [a] -> [a] -> [a]
++ Bool -> [[Char]]
closeTextIf Bool
inText forall a. [a] -> [a] -> [a]
++ [[Char]]
res)
|
[Char]
h [Char] -> [Char] -> Bool
`startsWith` [Char]
backticksHs ->
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
True Bool
False [[Char]]
hs (Bool -> [[Char]]
closeTextIf Bool
inText forall a. [a] -> [a] -> [a]
++ [[Char]] -> [[Char]]
squashEmpties [[Char]]
res)
| Bool -> Bool
not Bool
inText ->
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
h
then
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
inText Bool
False Bool
False [[Char]]
hs [[Char]]
res
else
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False Bool
False [[Char]]
hs ([[Char]
h, [Char]
mcOpen, [Char]
""] forall a. [a] -> [a] -> [a]
++ [[Char]]
res)
|
Bool
otherwise ->
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
True Bool
False Bool
False [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
| Bool
otherwise =
if [Char]
h forall a. Eq a => a -> a -> Bool
== [Char]
backticks
then
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
False Bool
False [[Char]]
hs [[Char]]
res
else
Bool -> Bool -> Bool -> [[Char]] -> [[Char]] -> [[Char]]
convert Bool
False Bool
True Bool
False [[Char]]
hs ([Char]
h forall a. a -> [a] -> [a]
: [[Char]]
res)
convert Bool
inText Bool
_ Bool
_ [] [[Char]]
res = [[Char]
mcClose | Bool
inText] forall a. [a] -> [a] -> [a]
++ [[Char]]
res