Remove extra markdown paragraph padding from balloons

This commit is contained in:
Micah Hahn 2023-04-04 11:56:40 -05:00
parent 73ea410205
commit a8d65c58a2
3 changed files with 29 additions and 11 deletions

View File

@ -6,6 +6,8 @@ import Css
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css)
import Markdown
import Markdown.Block
import Markdown.Inline
{-| Provide a plain-text string.
@ -51,6 +53,22 @@ markdownContent content =
|> List.map fromUnstyled
{-| Provide a string that will be rendered as markdown and placed in a paragraph tag, with the default margin removed.
-}
markdownParagraph : String -> List (Html msg)
markdownParagraph content =
case Markdown.Block.parse Nothing content of
[ Markdown.Block.Paragraph _ inlines ] ->
-- The library always parses into a paragraph and never into `PlainInline`
List.map (Markdown.Inline.toHtml >> fromUnstyled) inlines
|> p [ css [ Css.margin Css.zero ] ]
|> List.singleton
_ ->
Markdown.toHtml Nothing content
|> List.map fromUnstyled
{-| Provide a list of custom HTML.
-}
html :

View File

@ -376,7 +376,7 @@ markdown content =
Attribute <|
\config ->
{ config
| content = Content.markdownContent content
| content = Content.markdownParagraph content
, css = MarkdownStyles.anchorAndButton ++ config.css
}

View File

@ -262,16 +262,6 @@ view_ tagStyle viewSegment highlightables =
segments
stripMarkdownSyntax : String -> String
stripMarkdownSyntax markdown =
case Markdown.Block.parse Nothing markdown of
[ Markdown.Block.Paragraph _ inlines ] ->
Markdown.Inline.extractText inlines
_ ->
markdown
viewMarkedByBalloon :
{ config
| backgroundColor : Color
@ -598,3 +588,13 @@ viewBalloonSpacer config =
]
[ Html.text "()" ]
]
stripMarkdownSyntax : String -> String
stripMarkdownSyntax markdown =
case Markdown.Block.parse Nothing markdown of
[ Markdown.Block.Paragraph _ inlines ] ->
Markdown.Inline.extractText inlines
_ ->
markdown