diff --git a/src/HTML.hs b/src/HTML.hs index de53ff6..ec65f45 100644 --- a/src/HTML.hs +++ b/src/HTML.hs @@ -43,6 +43,9 @@ compileToHTML (Doc elements) = T.concat $ map elementToHTML elements elementsToHTML :: [Element] -> T.Text elementsToHTML = T.concat . map elementToHTML +spaceSep :: [T.Text] -> T.Text +spaceSep = T.intercalate " " + elementToHTML :: Element -> T.Text elementToHTML (Heading header attrs) = T.concat ["", serializeInlineToHTML header.text, ""] -- @@ -50,10 +53,10 @@ elementToHTML (Code code_block) = T.concat ["
", elementsToHTML elems, ""]
-elementToHTML (List (L {list_type = Ordered {start_number, style}, items}) attrs) = T.concat ["", generateLiElems items, ""]
-elementToHTML (List (L {list_type = Unordered {style}, items}) attrs) = T.concat ["", generateLiElems items, ""]
+elementToHTML (List (L {list_type = Ordered {start_number, style}, items}) attrs) = spaceSep ["", generateLiElems items, ""]
+elementToHTML (List (L {list_type = Unordered {style}, items}) attrs) = spaceSep ["", generateLiElems items, ""]
 elementToHTML (HTML (HTMLTag {html_content})) = html_content
-elementToHTML (Paragraph (P snippets) attrs) = T.concat ["", serializeInlineToHTML snippets, "

"] +elementToHTML (Paragraph (P snippets) attrs) = spaceSep ["", serializeInlineToHTML snippets, "

"] elementToHTML (Transparent snippets) = serializeInlineToHTML snippets elementToHTML HorizontalRule = "
" elementToHTML (Table _ _) = error "TODO" @@ -71,7 +74,7 @@ handleStart start = T.concat ["start=\"", T.show start, "\""] handleAttrs :: Attrs -> T.Text handleAttrs Attrs {attrId, attrClasses, attrKV} = - T.concat + spaceSep [ maybe "" (\id -> "id=\"" <> id <> "\"") attrId, "class=\"" <> T.intercalate " " attrClasses <> "\"", T.intercalate " " $ map (\(key, val) -> key <> "=\"" <> val <> "\"") attrKV @@ -79,7 +82,7 @@ handleAttrs Attrs {attrId, attrClasses, attrKV} = headerAttrs :: Heading -> Attrs -> T.Text headerAttrs header Attrs {attrId, attrClasses, attrKV} = - T.concat + spaceSep -- id is overcomplicated due to header having id logic written I don't wanna bother with [ maybe (genHeaderId header) (\id -> "id=\"" <> id <> "\"") attrId, "class=\"" <> T.intercalate " " attrClasses <> "\"", @@ -99,12 +102,12 @@ generateLiElems (element : remainder) = serializeInlineToHTML :: [InlineText] -> T.Text serializeInlineToHTML [] = "" serializeInlineToHTML (Text t : remaining) = escapeText t <> serializeInlineToHTML remaining -serializeInlineToHTML ((Bold elems attrs) : remaining) = T.concat ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] -serializeInlineToHTML ((Italic elems attrs) : remaining) = T.concat ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] -serializeInlineToHTML ((Crossed elems attrs) : remaining) = T.concat ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] -serializeInlineToHTML ((InlineCode code attrs) : remaining) = T.concat ["", escapeText code, "", serializeInlineToHTML remaining] -serializeInlineToHTML (Link {linkText, url, title, misc_attrs} : remaining) = T.concat [" T.concat ["title=\"", escapeText t, "\""]) title, ">", serializeInlineToHTML linkText, "", serializeInlineToHTML remaining] -serializeInlineToHTML (Image {altText, url, title, misc_attrs} : remaining) = T.concat ["\"", T.concat ["title=\"", escapeText t, "\""]) title, handleAttrs misc_attrs, ">", serializeInlineToHTML remaining] +serializeInlineToHTML ((Bold elems attrs) : remaining) = spaceSep ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] +serializeInlineToHTML ((Italic elems attrs) : remaining) = spaceSep ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] +serializeInlineToHTML ((Crossed elems attrs) : remaining) = spaceSep ["", serializeInlineToHTML elems, "", serializeInlineToHTML remaining] +serializeInlineToHTML ((InlineCode code attrs) : remaining) = spaceSep ["", escapeText code, "", serializeInlineToHTML remaining] +serializeInlineToHTML (Link {linkText, url, title, misc_attrs} : remaining) = T.concat [" T.concat [" title=\"", escapeText t, "\""]) title, ">", serializeInlineToHTML linkText, "", serializeInlineToHTML remaining] +serializeInlineToHTML (Image {altText, url, title, misc_attrs} : remaining) = T.concat ["\"", T.concat ["title=\"", escapeText t, "\" "]) title, handleAttrs misc_attrs, ">", serializeInlineToHTML remaining] serializeInlineToHTML (HTMLInline {inline_html_content} : remaining) = inline_html_content <> serializeInlineToHTML remaining serializeInlineToHTML ((Superscript _ _) : remaining) = error "TODO" serializeInlineToHTML ((Subscript _ _) : remaining) = error "TODO" diff --git a/src/IR.hs b/src/IR.hs index 3fcec17..55d4152 100644 --- a/src/IR.hs +++ b/src/IR.hs @@ -90,8 +90,7 @@ data InlineText | -- different HTML element than Underlined Insert [InlineText] Attrs | Math Math Attrs - | -- TODO - FootnoteReference {label :: Text, attrs :: Attrs} + | FootnoteReference {label :: Text, attrs :: Attrs} | Symbol Text | RawInline RawInline Attrs | Span [InlineText] Attrs diff --git a/src/Markdown.hs b/src/Markdown.hs index 1aff2b3..1fd1977 100644 --- a/src/Markdown.hs +++ b/src/Markdown.hs @@ -174,8 +174,10 @@ listBlock list_type prefix child_parser_factory nest_level = do optional ((notFollowedBy blockEnding) *> lineEnding) child <- optional $ child_parser_factory $ nest_level + 1 - error "TODO, child list handling works different now, child needs to be combined into content" - pure $ LI {content = [Transparent content]} + + case child of + Just c -> pure $ LI {content = [Transparent content, List c emptyAttrs]} + Nothing -> pure $ LI {content = [Transparent content]} unorderedListBlock :: (Logger m, Characters s) => Int -> Parser s m Element unorderedListBlock = listBlock Unordered {style = Nothing} unordered_prefix (\level -> unwrap <$> ((try $ unorderedListBlock level) <|> orderedListBlock level))