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
|
-- Parse bold text
|
||||||
parseBold :: ReadP MdToken
|
parseBold :: ReadP MdToken
|
||||||
parseBold = do
|
parseBold = parseBoldWith "**" <|> parseBoldWith "__"
|
||||||
text <-
|
where
|
||||||
choice
|
parseBoldWith delim = do
|
||||||
[ between (string "__") (string "__") (many1 (lookaheadParse (/= "__"))),
|
string delim
|
||||||
between (string "**") (string "**") (many1 (lookaheadParse (/= "**")))
|
inside <- greedyParse1 parseLineToken
|
||||||
]
|
string delim
|
||||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
return (Bold (Line inside))
|
||||||
return (Bold parsedText)
|
|
||||||
|
|
||||||
-- Parse italic text
|
-- Parse italic text
|
||||||
parseItalic :: ReadP MdToken
|
parseItalic :: ReadP MdToken
|
||||||
parseItalic = do
|
parseItalic = parseBoldWith "*" <|> parseBoldWith "_"
|
||||||
text <-
|
where
|
||||||
choice
|
parseBoldWith delim = do
|
||||||
[ between (string "_") (string "_") (munch1 (/= '_')),
|
string delim
|
||||||
between (string "*") (string "*") (munch1 (/= '*'))
|
inside <- greedyParse1 parseLineToken
|
||||||
]
|
string delim
|
||||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
return (Italic (Line inside))
|
||||||
return (Italic parsedText)
|
|
||||||
|
|
||||||
-- Parse strikethrough text
|
-- Parse strikethrough text
|
||||||
parseStrikethrough :: ReadP MdToken
|
parseStrikethrough :: ReadP MdToken
|
||||||
parseStrikethrough = do
|
parseStrikethrough = do
|
||||||
text <- between (string "~~") (string "~~") (many1 (lookaheadParse (/= "~~")))
|
string "~~"
|
||||||
let parsedText = fst $ leftmostLongestParse parseLine text
|
inside <- many1 parseLineToken
|
||||||
return (Strikethrough parsedText)
|
string "~~"
|
||||||
|
return (Strikethrough (Line inside))
|
||||||
|
|
||||||
-- Parse a link
|
-- Parse a link
|
||||||
parseLink :: ReadP MdToken
|
parseLink :: ReadP MdToken
|
||||||
|
Reference in New Issue
Block a user