Compare commits
No commits in common. "4a5d5e541a2bb517645029d961a1de2044be8a31" and "07218a32a6e639fff8b96c12dd33cc1974869f4e" have entirely different histories.
4a5d5e541a
...
07218a32a6
5 changed files with 83 additions and 37 deletions
|
@ -1,5 +1,9 @@
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
module Markdown
|
||||||
|
( module Markdown.Parser,
|
||||||
|
module Markdown.Data,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
module Markdown () where
|
import Markdown.Data
|
||||||
|
import Markdown.Parser
|
||||||
|
|
||||||
import CMark
|
|
||||||
|
|
30
app/Markdown/Data.hs
Normal file
30
app/Markdown/Data.hs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{-# LANGUAGE RankNTypes, FlexibleContexts #-}
|
||||||
|
|
||||||
|
module Markdown.Data
|
||||||
|
( MarkDownElement,
|
||||||
|
MListItem,
|
||||||
|
Parser,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Data.Text
|
||||||
|
import Text.Parsec
|
||||||
|
|
||||||
|
-- modified version of https://github.com/tusharad/markdown-parser
|
||||||
|
data MarkDownElement
|
||||||
|
= MHeading Int MarkDownElement
|
||||||
|
| MParagraph MarkDownElement
|
||||||
|
| MBold MarkDownElement
|
||||||
|
| MItalic MarkDownElement
|
||||||
|
| MBoldItalic MarkDownElement
|
||||||
|
| MLink MarkDownElement Text
|
||||||
|
| MLine [MarkDownElement]
|
||||||
|
| MUnorderedList [MListItem]
|
||||||
|
| MOrderedList [MListItem]
|
||||||
|
| Only Text -- Bottom of all types
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
data MListItem = MListItem MarkDownElement [MarkDownElement]
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
type Parser v = forall s u m. (Monad m, Stream s m Char) => ParsecT s u m v
|
44
app/Markdown/Parser.hs
Normal file
44
app/Markdown/Parser.hs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
|
||||||
|
module Markdown.Parser
|
||||||
|
( Markdown.Parser.lines,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Data.Functor (void)
|
||||||
|
import Data.Text (Text, pack)
|
||||||
|
import Text.Parsec
|
||||||
|
|
||||||
|
-- https://spec.commonmark.org/0.31.2/
|
||||||
|
-- https://hackage.haskell.org/package/parsec
|
||||||
|
|
||||||
|
linebreak ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m ()
|
||||||
|
-- 2 newlines due to mark
|
||||||
|
linebreak = void (newline *> newline)
|
||||||
|
|
||||||
|
emptyParse ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m String
|
||||||
|
emptyParse = "" <$ notFollowedBy anyChar
|
||||||
|
|
||||||
|
line ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m Text
|
||||||
|
line = fmap pack $ many $ notFollowedBy linebreak *> anyChar
|
||||||
|
|
||||||
|
lines ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m [Text]
|
||||||
|
lines = line `sepBy` linebreak
|
||||||
|
|
||||||
|
heading ::
|
||||||
|
(Monad m, Stream s m Char) =>
|
||||||
|
ParsecT s u m (Int, Text)
|
||||||
|
heading = do
|
||||||
|
level <- fmap length $ many1 $ char '#'
|
||||||
|
text <- line
|
||||||
|
pure (level, text)
|
||||||
|
|
||||||
|
-- TODO: blockquote, single backticks, triple backticks, links, arb HTML
|
|
@ -2,34 +2,3 @@ module Restruct where
|
||||||
|
|
||||||
-- https://docutils.sourceforge.io/rst.html
|
-- https://docutils.sourceforge.io/rst.html
|
||||||
-- https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
|
-- https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
|
||||||
|
|
||||||
-- https://hackage.haskell.org/package/parsec-3.1.18.0/docs/doc-index-All.html
|
|
||||||
|
|
||||||
import Data.Text (Text)
|
|
||||||
import Data.Void (Void)
|
|
||||||
import Text.Parsec as P
|
|
||||||
|
|
||||||
data RestElement
|
|
||||||
= RBody RestBody
|
|
||||||
| RTransition
|
|
||||||
| -- list of integers is the location in the section heirachy it is, Text is the title
|
|
||||||
-- NOTE: future me don't bother with proper restext convention do header depth via #n prefix to the title
|
|
||||||
RSection [Int] Text RestBody
|
|
||||||
|
|
||||||
data RestBody
|
|
||||||
= RParagraph [RInlineText]
|
|
||||||
| RBulletList Void
|
|
||||||
| REnumList Void
|
|
||||||
| RDefinitionList Void
|
|
||||||
| RFieldList Void
|
|
||||||
| ROptionList Void
|
|
||||||
| RLiteralBlock Void
|
|
||||||
| RLineBlock Void
|
|
||||||
| RBlockQuote Void
|
|
||||||
| -- skipping doctest blocks because no I'll just use a literal block thanks
|
|
||||||
RTable Void
|
|
||||||
| RExplicit Void
|
|
||||||
|
|
||||||
data MarkupModifier = Underline | Bold | Italic
|
|
||||||
|
|
||||||
data RInlineText = RInLineText {text :: Text, modifiers :: [MarkupModifier]}
|
|
||||||
|
|
|
@ -29,14 +29,13 @@ executable psb
|
||||||
-- .hs or .lhs file containing the Main module.
|
-- .hs or .lhs file containing the Main module.
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
||||||
other-modules: Config Utilities Templates Types IR Markdown Restruct
|
other-modules: Config Utilities Templates Types IR Markdown Markdown.Data Markdown.Parser Restruct
|
||||||
|
|
||||||
default-extensions: ApplicativeDo DataKinds NamedFieldPuns DerivingVia LambdaCase TypeApplications DeriveGeneric
|
default-extensions: ApplicativeDo DataKinds NamedFieldPuns DerivingVia LambdaCase TypeApplications DeriveGeneric
|
||||||
|
|
||||||
-- Other library packages from which modules are imported.
|
-- Other library packages from which modules are imported.
|
||||||
-- https://hackage.haskell.org/package/texmath
|
-- https://hackage.haskell.org/package/texmath
|
||||||
-- cmark is pinned because I don't want to touch it unless I rewrite to my own code
|
build-depends: base >=4.17.2.1, mustache >=2.4.2, pandoc >=3.2.1, shake >= 0.19.8, deriving-aeson >= 0.2.9, aeson, text, time, unordered-containers, yaml, parsec >= 3.1.18.0, typst >= 0.6.1, typst-symbols >= 0.1.7
|
||||||
build-depends: base >=4.17.2.1, mustache >=2.4.2, pandoc >=3.2.1, shake >= 0.19.8, deriving-aeson >= 0.2.9, aeson, text, time, unordered-containers, yaml, parsec >= 3.1.18.0, typst >= 0.6.1, typst-symbols >= 0.1.7, cmark == 0.6.1
|
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
|
|
Loading…
Reference in a new issue