parent
480b33b710
commit
c47bd8404f
2 changed files with 20 additions and 6 deletions
|
@ -459,6 +459,7 @@ inline = choice inlineParsers <?> "inline"
|
|||
, strikeout
|
||||
, underline
|
||||
, code
|
||||
, math
|
||||
, verbatim
|
||||
, subscript
|
||||
, superscript
|
||||
|
@ -530,10 +531,13 @@ underline = B.strong <$> inlinesEnclosedBy '_'
|
|||
code :: OrgParser Inlines
|
||||
code = B.code <$> rawEnclosedBy '='
|
||||
|
||||
verbatim :: OrgParser Inlines
|
||||
math :: OrgParser Inlines
|
||||
math = B.math <$> rawEnclosedBy '$'
|
||||
|
||||
verbatim :: OrgParser Inlines
|
||||
verbatim = B.rawInline "" <$> rawEnclosedBy '~'
|
||||
|
||||
subscript :: OrgParser Inlines
|
||||
subscript :: OrgParser Inlines
|
||||
subscript = B.subscript <$> (try $ char '_' *> maybeGroupedByBraces)
|
||||
|
||||
superscript :: OrgParser Inlines
|
||||
|
@ -580,18 +584,24 @@ rawEnclosedBy c = enclosedRaw (atStart $ char c) (atEnd $ char c)
|
|||
-- succeeds only if we're not right after a str (ie. in middle of word)
|
||||
atStart :: OrgParser a -> OrgParser a
|
||||
atStart p = do
|
||||
pos <- getPosition
|
||||
st <- getState
|
||||
guard $ orgLastStrPos st /= Just pos
|
||||
guard =<< not <$> isRightAfterString
|
||||
p
|
||||
|
||||
-- | succeeds only if we're at the end of a word
|
||||
atEnd :: OrgParser a -> OrgParser a
|
||||
atEnd p = try $ do
|
||||
p <* lookingAtEndOfWord
|
||||
p <* lookingAtEndOfWord
|
||||
where lookingAtEndOfWord =
|
||||
eof <|> const (return ()) =<< lookAhead . oneOf =<< postWordChars
|
||||
|
||||
isRightAfterString :: OrgParser Bool
|
||||
isRightAfterString = do
|
||||
pos <- getPosition
|
||||
st <- getState
|
||||
-- the position `Nothing` isn't after a String, either, hence the double
|
||||
-- negation
|
||||
return $ not $ orgLastStrPos st /= Just pos
|
||||
|
||||
postWordChars :: OrgParser [Char]
|
||||
postWordChars = do
|
||||
st <- getState
|
||||
|
|
|
@ -54,6 +54,10 @@ tests =
|
|||
"=Robot.rock()=" =?>
|
||||
para (code "Robot.rock()")
|
||||
|
||||
, "Math" =:
|
||||
"$E=mc^2$" =?>
|
||||
para (math "E=mc^2")
|
||||
|
||||
, "Verbatim" =:
|
||||
"~word for word~" =?>
|
||||
para (rawInline "" "word for word")
|
||||
|
|
Loading…
Add table
Reference in a new issue