diff options
| author | tv <tv@krebsco.de> | 2026-09-30 04:54:07 +0200 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-09-30 04:54:07 +0200 |
| commit | 80efc38f395b9ee70545d586ef02c68cf952be8d (patch) | |
| tree | b737cdc13ea541d614c53d1528051db781f2b6e0 /src/MdBlocks/Resolver.hs | |
| parent | 359ce0a3104d6407372e0dd3ba86bca71617b9a5 (diff) | |
implement --extract
Diffstat (limited to 'src/MdBlocks/Resolver.hs')
| -rw-r--r-- | src/MdBlocks/Resolver.hs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/MdBlocks/Resolver.hs b/src/MdBlocks/Resolver.hs new file mode 100644 index 0000000..c6e94d1 --- /dev/null +++ b/src/MdBlocks/Resolver.hs @@ -0,0 +1,55 @@ +{-# LANGUAGE OverloadedStrings #-} + +module MdBlocks.Resolver + ( resolveBlock + ) +where + +import Data.Text (Text) + +import MdBlocks.Address +import MdBlocks.Types + +resolveBlock + :: Address + -> [Block] + -> Maybe Block + +resolveBlock (GlobalId ident) blocks = + findById ident blocks + +resolveBlock (FileAddress fp ident) blocks = + findByFileAndId fp ident blocks + +findById :: Text -> [Block] -> Maybe Block +findById ident = + go + where + go [] = + Nothing + + go (b:bs) + | mdId (blockMeta b) == Just ident = + Just b + + | otherwise = + go bs + +findByFileAndId + :: FilePath + -> Text + -> [Block] + -> Maybe Block +findByFileAndId fp ident = + go + where + go [] = + Nothing + + go (b:bs) + | blockFile b == fp + , mdId (blockMeta b) == Just ident = + Just b + + | otherwise = + go bs |
