aboutsummaryrefslogtreecommitdiff
path: root/src/HaddockLex.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/HaddockLex.hs')
-rw-r--r--src/HaddockLex.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/HaddockLex.hs b/src/HaddockLex.hs
index f766222d..f1646453 100644
--- a/src/HaddockLex.hs
+++ b/src/HaddockLex.hs
@@ -11,7 +11,7 @@ module HaddockLex (
import Char
-special = '`' : '\'' : '\"' : '@' : '/' : []
+special = '`' : '\'' : '\"' : '@' : []
data Token
= TokPara
@@ -19,6 +19,7 @@ data Token
| TokBullet
| TokSpecial Char
| TokString String
+ | TokEmph String
| TokURL String
| TokBirdTrack
deriving Show
@@ -33,6 +34,7 @@ tokenise "" = []
tokenise str = case str of
'<':cs -> tokenise_url cs
'\n':cs -> tokenise_newline tokenise cs
+ '/':cs -> tokenise_emph tokenise cs
c:cs | c `elem` special -> TokSpecial c : tokenise cs
_other -> tokenise_string "" str
@@ -42,6 +44,12 @@ tokenise_newline next cs =
'>':cs -> TokBirdTrack : next cs -- bird track
_other -> tokenise_string "" cs
+tokenise_emph next cs =
+ case break newlineSlash cs of
+ (bef, aft@('\n':cs)) -> TokString ('/':bef) : next aft -- paragraph break
+ (bef, '/':cs) -> TokEmph bef : next cs
+ _other -> tokenise_string "" cs
+
tokenise_para cs =
case dropWhile nonNewlineSpace cs of
-- bullet: '*'
@@ -60,6 +68,8 @@ tokenise_para cs =
nonNewlineSpace c = isSpace c && c /= '\n'
+newlineSlash c = c == '\n' || c == '/'
+
-- ----------------------------------------------------------------------------
-- Within a paragraph, we don't throw away any whitespace (except before a
-- birdtrack, and before a paragraph break).
@@ -69,6 +79,7 @@ tokenise1 "" = []
tokenise1 str = case str of
'<':cs -> tokenise_url cs
'\n':cs -> tokenise_newline1 cs
+ '/':cs -> tokenise_emph tokenise1 cs
c:cs | c `elem` special -> TokSpecial c : tokenise1 cs
_other -> tokenise_string "" str
@@ -93,6 +104,7 @@ tokenise_string str cs =
'\\':c:cs -> tokenise_string (c:str) cs
'\n':cs -> tokenise_string_newline str cs
'<':cs -> TokString (reverse str) : tokenise_url cs
+ '/':cs -> TokString (reverse str) : tokenise_emph (tokenise_string "") cs
c:cs | c `elem` special -> TokString (reverse str) : tokenise1 (c:cs)
| otherwise -> tokenise_string (c:str) cs