@@ -217,9 +217,15 @@ pBulletList = try $ do
217217 -- note: if they have an <ol> or <ul> not in scope of a <li>,
218218 -- treat it as a list item, though it's not valid xhtml...
219219 skipMany nonItem
220− items <- manyTill (pInTags "li" block <* skipMany nonItem) (pCloses "ul")
220+ items <- manyTill (pListItem nonItem) (pCloses "ul")
221221 return $ B.bulletList $ map (fixPlains True) items
222222
223+pListItem :: TagParser a -> TagParser Blocks
224+pListItem nonItem = do
225+ TagOpen _ attr <- lookAhead $ pSatisfy (~== TagOpen "li" [])
226+ let liDiv = maybe mempty (\x -> B.divWith (x, [], []) mempty) (lookup "id" attr)
227+ (liDiv <>) <$> pInTags "li" block <* skipMany nonItem
228+
223229pOrderedList :: TagParser Blocks
224230pOrderedList = try $ do
225231 TagOpen _ attribs <- pSatisfy (~== TagOpen "ol" [])
@@ -245,7 +251,7 @@ pOrderedList = try $ do
245251 -- note: if they have an <ol> or <ul> not in scope of a <li>,
246252 -- treat it as a list item, though it's not valid xhtml...
247253 skipMany nonItem
248− items <- manyTill (pInTags "li" block <* skipMany nonItem) (pCloses "ol")
254+ items <- manyTill (pListItem nonItem) (pCloses "ol")
249255 return $ B.orderedListWith (start, style, DefaultDelim) $ map (fixPlains True) items
250256
251257pDefinitionList :: TagParser Blocks
@@ -518,12 +524,24 @@ pLineBreak = do
518524 return B.linebreak
519525
520526pLink :: TagParser Inlines
521−pLink = try $ do
527+pLink = pRelLink <|> pAnchor
528+
529+pAnchor :: TagParser Inlines
530+pAnchor = try $ do
531+ tag <- pSatisfy (tagOpenLit "a" (isJust . lookup "id"))
532+ return $ B.spanWith (fromAttrib "id" tag , [], []) mempty
533+
534+pRelLink :: TagParser Inlines
535+pRelLink = try $ do
522536 tag <- pSatisfy (tagOpenLit "a" (isJust . lookup "href"))
523537 let url = fromAttrib "href" tag
524538 let title = fromAttrib "title" tag
539+ let uid = fromAttrib "id" tag
540+ let spanC = case uid of
541+ [] -> id
542+ s -> B.spanWith (s, [], [])
525543 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
526− return $ B.link (escapeURI url) title lab
544+ return $ spanC $ B.link (escapeURI url) title lab
527545
528546pImage :: TagParser Inlines
529547pImage = do