mirror of
https://github.com/aelve/guide.git
synced 2024-12-22 20:31:31 +03:00
Don't use unsafe T.head (and don't fail on empty links)
This commit is contained in:
parent
83905bc08d
commit
d6010dfcd5
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,4 +35,5 @@ tags
|
|||||||
|
|
||||||
# JavaScript
|
# JavaScript
|
||||||
guidejs/node_modules/
|
guidejs/node_modules/
|
||||||
|
front/node_modules/
|
||||||
static/js/
|
static/js/
|
||||||
|
@ -62,10 +62,10 @@ consolidate s@("-":_) =
|
|||||||
consolidate (".":".":".":xs) = "..." : consolidate xs
|
consolidate (".":".":".":xs) = "..." : consolidate xs
|
||||||
-- links
|
-- links
|
||||||
consolidate s@("http":":":"/":"/":_) =
|
consolidate s@("http":":":"/":"/":_) =
|
||||||
let (l, r) = span (\x -> x /= ")" && not (isSpace (T.head x))) s
|
let (l, r) = span (\x -> x /= ")" && not (startsWithSpace x)) s
|
||||||
in T.concat l : consolidate r
|
in T.concat l : consolidate r
|
||||||
consolidate s@("https":":":"/":"/":_) =
|
consolidate s@("https":":":"/":"/":_) =
|
||||||
let (l, r) = span (\x -> x /= ")" && not (isSpace (T.head x))) s
|
let (l, r) = span (\x -> x /= ")" && not (startsWithSpace x)) s
|
||||||
in T.concat l : consolidate r
|
in T.concat l : consolidate r
|
||||||
consolidate ("(":"@":"hk":")":xs) = "(" : "@hk" : ")" : consolidate xs
|
consolidate ("(":"@":"hk":")":xs) = "(" : "@hk" : ")" : consolidate xs
|
||||||
|
|
||||||
@ -88,3 +88,8 @@ op = over _1 mconcat . span (isOpToken . T.unpack)
|
|||||||
where
|
where
|
||||||
isOpToken [c] = c `elem` (":!#$%&*+./<=>?@\\^|-~" :: String)
|
isOpToken [c] = c `elem` (":!#$%&*+./<=>?@\\^|-~" :: String)
|
||||||
isOpToken _ = False
|
isOpToken _ = False
|
||||||
|
|
||||||
|
startsWithSpace :: Text -> Bool
|
||||||
|
startsWithSpace s = case T.uncons s of
|
||||||
|
Nothing -> False
|
||||||
|
Just (c, _) -> isSpace c
|
||||||
|
@ -189,7 +189,7 @@ extractInlines = concatMap go
|
|||||||
CODE_BLOCK _ xs -> [MD.Node Nothing (CODE xs) []]
|
CODE_BLOCK _ xs -> [MD.Node Nothing (CODE xs) []]
|
||||||
|
|
||||||
shortcutLinks :: MD.Node -> MD.Node
|
shortcutLinks :: MD.Node -> MD.Node
|
||||||
shortcutLinks node@(MD.Node pos (LINK url title) ns) | '@' <- T.head url =
|
shortcutLinks node@(MD.Node pos (LINK url title) ns) | "@" <- T.take 1 url =
|
||||||
-- %20s are possibly introduced by cmark (Pandoc definitely adds them,
|
-- %20s are possibly introduced by cmark (Pandoc definitely adds them,
|
||||||
-- no idea about cmark but better safe than sorry) and so they need to
|
-- no idea about cmark but better safe than sorry) and so they need to
|
||||||
-- be converted back to spaces
|
-- be converted back to spaces
|
||||||
|
Loading…
Reference in New Issue
Block a user