Parse bold, italic and strikethrough in-order, instead of trying to find
the end, then parsing everything in the middle. The current approach parses the opening bold (or italic), some text, then the closing bold (or italic), instead of parsing the opening, closing, then everything in between.
This commit is contained in:
@@ -166,32 +166,31 @@ parseHeader = do
|
||||
|
||||
-- Parse bold text
|
||||
parseBold :: ReadP MdToken
|
||||
parseBold = do
|
||||
text <-
|
||||
choice
|
||||
[ between (string "__") (string "__") (many1 (lookaheadParse (/= "__"))),
|
||||
between (string "**") (string "**") (many1 (lookaheadParse (/= "**")))
|
||||
]
|
||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
||||
return (Bold parsedText)
|
||||
parseBold = parseBoldWith "**" <|> parseBoldWith "__"
|
||||
where
|
||||
parseBoldWith delim = do
|
||||
string delim
|
||||
inside <- greedyParse1 parseLineToken
|
||||
string delim
|
||||
return (Bold (Line inside))
|
||||
|
||||
-- Parse italic text
|
||||
parseItalic :: ReadP MdToken
|
||||
parseItalic = do
|
||||
text <-
|
||||
choice
|
||||
[ between (string "_") (string "_") (munch1 (/= '_')),
|
||||
between (string "*") (string "*") (munch1 (/= '*'))
|
||||
]
|
||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
||||
return (Italic parsedText)
|
||||
parseItalic = parseBoldWith "*" <|> parseBoldWith "_"
|
||||
where
|
||||
parseBoldWith delim = do
|
||||
string delim
|
||||
inside <- greedyParse1 parseLineToken
|
||||
string delim
|
||||
return (Italic (Line inside))
|
||||
|
||||
-- Parse strikethrough text
|
||||
parseStrikethrough :: ReadP MdToken
|
||||
parseStrikethrough = do
|
||||
text <- between (string "~~") (string "~~") (many1 (lookaheadParse (/= "~~")))
|
||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
||||
return (Strikethrough parsedText)
|
||||
string "~~"
|
||||
inside <- many1 parseLineToken
|
||||
string "~~"
|
||||
return (Strikethrough (Line inside))
|
||||
|
||||
-- Parse a link
|
||||
parseLink :: ReadP MdToken
|
||||
|
Reference in New Issue
Block a user