preliminary djot changes to IR made

This commit is contained in:
Pagwin 2026-04-06 13:41:12 -04:00
parent c90d2e45b8
commit 24606a9204
No known key found for this signature in database
GPG key ID: 81137023740CA260

118
src/IR.hs
View file

@ -6,13 +6,23 @@ newtype Document = Doc [Element]
deriving (Show)
data Element
= Heading Heading
= Heading Heading Attrs
| Code Code
| BlockQuote BlockQuote
| List List
| HTML HTML
| Paragraph Paragraph
| List List Attrs
| -- Markdown only, DJOT will produce a RawBlock with an html type
HTML HTML
| Paragraph Paragraph Attrs
| HorizontalRule
| -- TODO
Table Table Attrs
| -- Djot :::
Container [Element] Attrs
| -- TODO
Footnote Footnote Attrs
| DescriptionList DescriptionList Attrs
| RawBlock RawBlock Attrs
| TaskList TaskList Attrs
deriving (Show)
-- Removed: BlankLine
@ -29,15 +39,15 @@ data Code = C
}
deriving (Show)
data BlockQuote = Q [InlineText] deriving (Show)
data BlockQuote = Q [Element] deriving (Show)
data ListItem = LI
{ content :: [InlineText], -- Flatten continuations into here
{ content :: [Element], -- Flatten continuations into here
child :: Maybe List
}
deriving (Show)
data ListType = Ordered | Unordered deriving (Show)
data ListType = Ordered {start_number :: Text, style :: Text} | Unordered {style :: Text} deriving (Show)
data List = L
{ list_type :: ListType,
@ -45,7 +55,7 @@ data List = L
}
deriving (Show)
data HTML
newtype HTML
= HTMLTag
{ html_content :: Text
}
@ -54,23 +64,99 @@ data HTML
newtype Paragraph = P [InlineText] deriving (Show)
data InlineText
= Text Text -- Combined Normal and Escaped
| Bold [InlineText]
| Italic [InlineText]
| Crossed [InlineText]
= Text Text Attrs -- Combined Normal and Escaped
| Bold [InlineText] Attrs
| Italic [InlineText] Attrs
| Crossed [InlineText] Attrs
| Underlined [InlineText]
| InlineCode Text
| InlineCode Text Attrs
| Link
{ linkText :: [InlineText],
url :: Text,
title :: Maybe Text
title :: Maybe Text,
misc_attrs :: Attrs
}
| Image
{ altText :: Text,
url :: Text,
title :: Maybe Text
title :: Maybe Text,
misc_attrs :: Attrs
}
| HTMLInline {inline_html_content :: Text}
| -- 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
| -- TODO
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