166 lines
3.6 KiB
Haskell
166 lines
3.6 KiB
Haskell
module IR where
|
|
|
|
import Data.Text
|
|
|
|
newtype Document = Doc [Element]
|
|
deriving (Show)
|
|
|
|
data Element
|
|
= Heading Heading Attrs
|
|
| Code Code
|
|
| BlockQuote BlockQuote
|
|
| List List Attrs
|
|
| -- Markdown only, DJOT will produce a RawBlock with an html type
|
|
HTML HTML
|
|
| Paragraph Paragraph Attrs
|
|
| -- to avoid breaking generation when swapping InlineText to Element in Markdown parser
|
|
Transparent [InlineText]
|
|
| HorizontalRule
|
|
| Table Table Attrs
|
|
| -- Djot :::
|
|
Container [Element] Attrs
|
|
| Footnote Footnote Attrs
|
|
| DescriptionList DescriptionList Attrs
|
|
| RawBlock RawBlock Attrs
|
|
| TaskList TaskList Attrs
|
|
deriving (Show)
|
|
|
|
-- Removed: BlankLine
|
|
|
|
data Heading = H
|
|
{ level :: Int,
|
|
text :: [InlineText]
|
|
}
|
|
deriving (Show)
|
|
|
|
data Code = C
|
|
{ language :: Maybe Text,
|
|
code :: Text
|
|
}
|
|
deriving (Show)
|
|
|
|
newtype BlockQuote = Q [Element] deriving (Show)
|
|
|
|
newtype ListItem = LI
|
|
-- children are just more elements
|
|
{ content :: [Element] -- Flatten continuations into here
|
|
}
|
|
deriving (Show)
|
|
|
|
data ListType = Ordered {start_number :: Maybe Int, style :: Maybe Text} | Unordered {style :: Maybe Text} deriving (Show)
|
|
|
|
data List = L
|
|
{ list_type :: ListType,
|
|
items :: [ListItem]
|
|
}
|
|
deriving (Show)
|
|
|
|
newtype HTML
|
|
= HTMLTag
|
|
{ html_content :: Text
|
|
}
|
|
deriving (Show)
|
|
|
|
newtype Paragraph = P [InlineText] deriving (Show)
|
|
|
|
data InlineText
|
|
= Text Text -- Combined Normal and Escaped
|
|
| Bold [InlineText] Attrs
|
|
| Italic [InlineText] Attrs
|
|
| Crossed [InlineText] Attrs
|
|
| Underlined [InlineText]
|
|
| InlineCode Text Attrs
|
|
| Link
|
|
{ linkText :: [InlineText],
|
|
url :: Text,
|
|
title :: Maybe Text,
|
|
misc_attrs :: Attrs
|
|
}
|
|
| Image
|
|
{ altText :: Text,
|
|
url :: Text,
|
|
title :: Maybe Text,
|
|
misc_attrs :: Attrs
|
|
}
|
|
| -- Markdown only DJOT uses RawInline
|
|
HTMLInline {inline_html_content :: Text}
|
|
| Superscript [InlineText] Attrs
|
|
| Subscript [InlineText] Attrs
|
|
| Highlighted [InlineText] Attrs
|
|
| -- different HTML element than Underlined
|
|
Insert [InlineText] Attrs
|
|
| Math Math Attrs
|
|
| FootnoteReference {label :: Text, attrs :: Attrs}
|
|
| Symbol Text
|
|
| RawInline RawInline Attrs
|
|
| Span [InlineText] Attrs
|
|
| LineBreak
|
|
deriving (Show)
|
|
|
|
data Attrs = Attrs
|
|
{ attrId :: Maybe Text,
|
|
attrClasses :: [Text],
|
|
attrKV :: [(Text, Text)]
|
|
}
|
|
deriving (Show)
|
|
|
|
emptyAttrs :: Attrs
|
|
emptyAttrs = Attrs {attrId = Nothing, attrClasses = [], attrKV = []}
|
|
|
|
data Math
|
|
= InlineLaTeX Text
|
|
| BlockLaTeX Text
|
|
deriving (Show)
|
|
|
|
data Alignment = AlignLeft | AlignRight | AlignCenter | AlignDefault
|
|
deriving (Show)
|
|
|
|
data TableCell = TC
|
|
{ cellContent :: [InlineText],
|
|
cellAlign :: Alignment
|
|
}
|
|
deriving (Show)
|
|
|
|
newtype TableRow = TR [TableCell] deriving (Show)
|
|
|
|
data Table = T
|
|
{ tableCaption :: Maybe [InlineText],
|
|
tableHead :: Maybe TableRow,
|
|
tableBody :: [TableRow]
|
|
}
|
|
deriving (Show)
|
|
|
|
newtype DescriptionList = DL {items :: [DefinitionItem]} deriving (Show)
|
|
|
|
data DefinitionItem = Def
|
|
{ defTitle :: [InlineText],
|
|
defContent :: [Element]
|
|
}
|
|
deriving (Show)
|
|
|
|
data Footnote = F {label :: Text, content :: [Element]} deriving (Show)
|
|
|
|
newtype TaskList = TL {items :: [Task]} deriving (Show)
|
|
|
|
data Task = Ta
|
|
{ checked :: Bool,
|
|
content :: [Element]
|
|
}
|
|
deriving (Show)
|
|
|
|
data RawInline = RI
|
|
{
|
|
}
|
|
deriving (Show)
|
|
|
|
data RawBlock = RB
|
|
{
|
|
}
|
|
deriving (Show)
|
|
|
|
-- for processing math
|
|
-- https://hackage.haskell.org/package/typst-0.6.1/docs/Typst-Parse.html#v:parseTypst
|
|
-- and
|
|
-- https://hackage.haskell.org/package/typst-symbols-0.1.7/docs/Typst-Symbols.html
|
|
-- are going to be used for handling typst and
|
|
-- texmath for latex handling
|