From 24606a92040f707d3ccdb1b14bd4870144d0a5c1 Mon Sep 17 00:00:00 2001 From: Pagwin Date: Mon, 6 Apr 2026 13:41:12 -0400 Subject: [PATCH] preliminary djot changes to IR made --- src/IR.hs | 118 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 102 insertions(+), 16 deletions(-) diff --git a/src/IR.hs b/src/IR.hs index 4f2ad2e..e9dbe63 100644 --- a/src/IR.hs +++ b/src/IR.hs @@ -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