From 80efc38f395b9ee70545d586ef02c68cf952be8d Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 30 Sep 2026 04:54:07 +0200 Subject: implement --extract --- src/MdBlocks/Resolver.hs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/MdBlocks/Resolver.hs (limited to 'src/MdBlocks/Resolver.hs') 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 -- cgit v1.3.1