Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Restore gist extraction
  • Loading branch information
Heimdell committed Nov 9, 2021
commit 034bef52d70a80635337764280d0ba0cf711cd66
5 changes: 4 additions & 1 deletion src/Xrefcheck/Scanners/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Control.Lens hiding ((^?))
import Control.Monad.Except (MonadError, throwError)
import Data.Aeson.TH (deriveFromJSON)
import Data.ByteString.Lazy qualified as BSL
import Data.Char (isAlpha)
import Data.DList qualified as DList
import Data.Default (def)
import Data.List (isSubsequenceOf)
Expand Down Expand Up @@ -206,7 +207,9 @@ nodeExtractInfo input@(Node _ _ nSubs) = do

urlIsASubsequence :: CopyPaste -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: AFAICS, here we check if link text is a subsequence of link URL, so if name is a URL subsequence, not URL is a subsequence of name

urlIsASubsequence paste =
T.unpack (cpAnchorText paste) `isSubsequenceOf` T.unpack (cpPlainText paste)
gist (cpAnchorText paste) `isSubsequenceOf` gist (cpPlainText paste)
where
gist = T.unpack . T.toLower . T.filter isAlpha

merge :: (Monad m, Monoid b) => [a -> m b] -> a -> m b
merge fs a = mconcat <$> traverse ($ a) fs
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Xrefcheck/CopyPasteInListsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec = do
for_ allFlavors $ \fl -> do
it ("is detected (" <> show fl <> ")") $ do
fi <- getFI fl "tests/markdowns/without-annotations/copy-paste_in_lists.md"
getPasta fi `shouldBe`[("a", "c")]
getPasta fi `shouldBe`[("foo-bar","Foo Kek")]
where
getPasta :: FileInfo -> [(Text, Text)]
getPasta fi = map (cpAnchorText &&& cpPlainText) $ fi ^. fiCopyPastes
12 changes: 6 additions & 6 deletions tests/markdowns/without-annotations/copy-paste_in_lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

A list with bad copy-paste:

- [a](a) e
- [b](b) e
- [c](a) e
- [Foo Bar](foo-bar) e
- [Foo Qux](foo-qux) e
- [Foo Kek](foo-bar) e

A list that is completely fine:

- [a](a) d
- [b](b) d
- [c](c) d
- [Foo Bar](foo-bar) e
- [Foo Qux](foo-qux) e
- [Foo Kek](foo-kek) e