Skip to content

Commit

Permalink
fixup! fixup! [#93] Add support for basic html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Sereja313 committed Dec 28, 2022
1 parent d863dcf commit 15caf4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/Xrefcheck/Scanners/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ removeIgnored = withIgnoreMode . cataNodeWithParentNodeInfo remove

findAttributes :: [Text] -> [Attribute Text] -> Maybe Text
findAttributes (map T.toLower -> attrs) =
fmap snd . find (\(attr, _) -> T.toLower attr `elem` attrs)
fmap snd . find ((`elem` attrs) . T.toLower . fst)

isLink :: Text -> Bool
isLink (parseTags -> tags) = case safeHead tags of
Expand All @@ -282,7 +282,6 @@ isLink (parseTags -> tags) = case safeHead tags of
|| T.toLower tag == "img" && isJust (findAttributes ["src"] attrs)
_ -> False


-- | Custom `foldMap` for source tree.
foldNode :: (Monoid a, Monad m) => (Node -> m a) -> Node -> m a
foldNode action node@(Node _ _ subs) = do
Expand Down Expand Up @@ -353,8 +352,7 @@ nodeExtractInfo input@(Node _ _ nSubs) = do
attributes <- case tag of
TagOpen a attrs | T.toLower a == "a" -> Just attrs
_ -> Nothing
(_, name) <- find (\(field, _) -> T.toLower field `elem` ["name", "id"]) attributes
pure name
findAttributes ["name", "id"] attributes

case mName of
Just aName -> do
Expand Down Expand Up @@ -402,7 +400,6 @@ nodeExtractInfo input@(Node _ _ nSubs) = do
_ -> pure mempty
_ -> pure mempty


-- | Check if there is `ignore all` at the beginning of the file,
-- ignoring preceding comments if there are any.
checkIgnoreAllFile :: [Node] -> Bool
Expand Down
6 changes: 6 additions & 0 deletions tests/golden/check-html/check-html.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ text <a href=#seven>Seven</a> text

<!-- xrefcheck: ignore link -->
text <a href=https://serokell.io/404>serokell404</a> text

<!-- xrefcheck: ignore link -->
<img src=https://serokell.io/404>

<!-- xrefcheck: ignore link -->
text <img src=https://serokell.io/404> text

0 comments on commit 15caf4b

Please sign in to comment.