Compare commits
No commits in common. "4893b40cc981f3ec0db1ee9ef2276743477b1935" and "57126ef6be2a951c803ed6d93403b751ec300b0c" have entirely different histories.
4893b40cc9
...
57126ef6be
2 changed files with 20 additions and 66 deletions
70
app/IR.hs
70
app/IR.hs
|
|
@ -4,73 +4,33 @@ import Data.Text
|
||||||
|
|
||||||
newtype Document = Doc [Element]
|
newtype Document = Doc [Element]
|
||||||
|
|
||||||
data Element
|
data Element = Heading Heading | Code Code | BlockQuote BlockQuote | List List | Table Table | HTML HTML | Paragraph Paragraph | BlankLine BlankLine
|
||||||
= Heading Heading
|
|
||||||
| Code Code
|
|
||||||
| BlockQuote BlockQuote
|
|
||||||
| List List
|
|
||||||
| HTML HTML
|
|
||||||
| Paragraph Paragraph
|
|
||||||
| HorizontalRule
|
|
||||||
|
|
||||||
-- Removed: BlankLine
|
data Heading = H {level :: Int, text :: Text}
|
||||||
|
|
||||||
data Heading = H
|
data Code = C {language :: Text, code :: Text}
|
||||||
{ level :: Int,
|
|
||||||
text :: [InlineText]
|
|
||||||
}
|
|
||||||
|
|
||||||
data Code = C
|
newtype BlockQuote = Q Text
|
||||||
{ language :: Maybe Text,
|
|
||||||
code :: Text
|
|
||||||
}
|
|
||||||
|
|
||||||
data BlockQuote = Q [InlineText]
|
|
||||||
|
|
||||||
data ListItem = LI
|
|
||||||
{ content :: [InlineText], -- Flatten continuations into here
|
|
||||||
children :: [List]
|
|
||||||
}
|
|
||||||
|
|
||||||
data ListType = Ordered | Unordered
|
data ListType = Ordered | Unordered
|
||||||
|
|
||||||
data List = L
|
data ListItem = LI {content :: Text, children :: [List]}
|
||||||
{ list_type :: ListType,
|
|
||||||
items :: [ListItem]
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Table: keep as-is or simplify based on your needs
|
data List = L {list_type :: ListType, items :: [ListItem]}
|
||||||
|
|
||||||
data HTML
|
data Table = T {header :: TableHeader, rows :: [TableRow]}
|
||||||
= HTMLTag
|
|
||||||
{ tagName :: Text,
|
|
||||||
attributes :: [(Text, Maybe Text)],
|
|
||||||
html_content :: Text
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Optionally skip: HTMLComment, HTMLDeclaration
|
newtype TableHeader = TH [Text]
|
||||||
|
|
||||||
|
newtype TableRow = TR Text
|
||||||
|
|
||||||
|
newtype HTML = Raw Text
|
||||||
|
|
||||||
newtype Paragraph = P [InlineText]
|
newtype Paragraph = P [InlineText]
|
||||||
|
|
||||||
data InlineText
|
data InlineText = Normal Text | Escaped Char | Bold InlineText | Italic InlineText | CodeLine Text | Link {nest :: InlineText, href :: Text} | HTMLIn Text
|
||||||
= Text Text -- Combined Normal and Escaped
|
|
||||||
| Bold [InlineText]
|
data BlankLine = BL
|
||||||
| Italic [InlineText]
|
|
||||||
| InlineCode Text
|
|
||||||
| Link
|
|
||||||
{ linkText :: [InlineText],
|
|
||||||
url :: Text,
|
|
||||||
title :: Maybe Text
|
|
||||||
}
|
|
||||||
| Image
|
|
||||||
{ altText :: [InlineText],
|
|
||||||
url :: Text,
|
|
||||||
title :: Maybe Text
|
|
||||||
}
|
|
||||||
| HTMLInline
|
|
||||||
{ inlineTagName :: Text,
|
|
||||||
inlineAttributes :: [(Text, Maybe Text)]
|
|
||||||
}
|
|
||||||
|
|
||||||
-- for processing math
|
-- for processing math
|
||||||
-- https://hackage.haskell.org/package/typst-0.6.1/docs/Typst-Parse.html#v:parseTypst
|
-- https://hackage.haskell.org/package/typst-0.6.1/docs/Typst-Parse.html#v:parseTypst
|
||||||
|
|
|
||||||
|
|
@ -66,23 +66,17 @@ htmlInline = do
|
||||||
remaining <- htmlInlineRemainder
|
remaining <- htmlInlineRemainder
|
||||||
whiteSpace
|
whiteSpace
|
||||||
char '>'
|
char '>'
|
||||||
let remainingTagText = foldl' (\ongoing current -> ongoing ++ ' ' : current) "" remaining
|
let remainingTagText = foldl' (\ongoing current -> ongoing ++ ' ' : current) "" remaining
|
||||||
|
|
||||||
pure $ HTMLIn $ pack $ '<' : name ++ remaining
|
pure $ HTMLIn $ pack $ '<' : name ++ remaining
|
||||||
where
|
where
|
||||||
htmlInlineRemainder = many $ whiteSpace *> attribute
|
htmlInlineRemainder = many $ whiteSpace *> attribute
|
||||||
name = many $ choice [alphaNum, char '-', char ':']
|
name = many $ choice [alphaNum, char '-', char ':']
|
||||||
value = do
|
|
||||||
char '"'
|
|
||||||
l <- letter
|
|
||||||
rem <- many $ choice [alphaNum, char '-', char ':']
|
|
||||||
char '"'
|
|
||||||
pure '"' : l : rem ++ "\""
|
|
||||||
attribute = do
|
attribute = do
|
||||||
attrName <- name
|
attrName <- name
|
||||||
char '='
|
char '='
|
||||||
attrValue <- value
|
attrValue <- value
|
||||||
pure attrName ++ ('=' : attrValue)
|
pure attrName ++ '=' :
|
||||||
|
|
||||||
whiteSpace :: Parser Text
|
whiteSpace :: Parser Text
|
||||||
whiteSpace = pack <$> many space
|
whiteSpace = pack <$> many space
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue