-- FIXME TODO lazy implementation
stripMarkdown :: A.Parser (Either Text Text)
stripMarkdown = do
    -- Either designates whether we keep the result or discard it, later.
    A.choice [h1, h2, hn, link, quote, unorderedList, orderedList]
  where
    h1 = fmap Right $ line <* "\n" <* A.many1 (A.char '=')
    h2 = fmap Right $ line <* "\n" <* A.many1 (A.char '-')
    hn = let hashes = A.string `map` reverse (scanl (flip T.cons) "#" "#####")
         in fmap Right $ A.choice hashes *> A.skipSpace *> line
    link = fmap Right $ "[" *> A.takeWhile1 (/= ']') <* "(" <* A.skipWhile (/= ')') <* ")"
    -- TODO parse lazy, 80col quoteblocks, for all above
    quote = fmap (Left . T.unlines) . A.many1 $ "\n" *> A.skipSpace *> line
    unorderedList = do
        let lp = "\n" *> A.skipSpace *> A.choice (map A.char ('+':"*-")) *> line
        Left . T.unlines <$> A.many1 lp
    -- TODO requires recursion: List has to start with "1." not "N."
    orderedList = do
        let lp = "\n" *> A.skipSpace  *> A.digit *> "." *> A.skipSpace *> line
        Left . T.unlines <$> A.many1 lp


-- FIXME remove use of `fromJust`
-- | Get latest Discourse thread IDs
stripMarkdown :: A.Parser (Either Text Text)
stripMarkdown = do
    -- Either designates whether we keep the result or discard it, later.
    A.choice [h1, h2, hn, link, quote, unorderedList, orderedList]
  where
    h1 = fmap Right $ line <* "\n" <* A.many1 (A.char '=')
    h2 = fmap Right $ line <* "\n" <* A.many1 (A.char '-')
    hn = let hashes = A.string `map` reverse (scanl (flip T.cons) "#" "#####")
         in fmap Right $ A.choice hashes *> A.skipSpace *> line
    link = fmap Right $ "[" *> A.takeWhile1 (/= ']') <* "(" <* A.skipWhile (/= ')') <* ")"
    -- TODO parse lazy, 80col quoteblocks, for all above
    quote = fmap (Left . T.unlines) . A.many1 $ "\n" *> A.skipSpace *> line
    unorderedList = do
        let lp = "\n" *> A.skipSpace *> A.choice (map A.char ('+':"*-")) *> line
        Left . T.unlines <$> A.many1 lp
    -- TODO requires recursion: List has to start with "1." not "N."
    orderedList = do
        let lp = "\n" *> A.skipSpace  *> A.digit *> "." *> A.skipSpace *> line
        Left . T.unlines <$> A.many1 lp


-- FIXME remove use of `fromJust`
-- | Get latest Discourse thread IDs
stripMarkdown = do
    -- Either designates whether we keep the result or discard it, later.
    A.choice [h1, h2, hn, link, quote, unorderedList, orderedList]
  where
    h1 = fmap Right $ line <* "\n" <* A.many1 (A.char '=')
    h2 = fmap Right $ line <* "\n" <* A.many1 (A.char '-')
    hn = let hashes = A.string `map` reverse (scanl (flip T.cons) "#" "#####")
         in fmap Right $ A.choice hashes *> A.skipSpace *> line
    link = fmap Right $ "[" *> A.takeWhile1 (/= ']') <* "(" <* A.skipWhile (/= ')') <* ")"
    -- TODO parse lazy, 80col quoteblocks, for all above
    quote = fmap (Left . T.unlines) . A.many1 $ "\n" *> A.skipSpace *> line
    unorderedList = do
        let lp = "\n" *> A.skipSpace *> A.choice (map A.char ('+':"*-")) *> line
        Left . T.unlines <$> A.many1 lp
    -- TODO requires recursion: List has to start with "1." not "N."
    orderedList = do
        let lp = "\n" *> A.skipSpace  *> A.digit *> "." *> A.skipSpace *> line
        Left . T.unlines <$> A.many1 lp


-- FIXME remove use of `fromJust`
-- | Get latest Discourse thread IDs