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/Address.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/MdBlocks/Address.hs') diff --git a/src/MdBlocks/Address.hs b/src/MdBlocks/Address.hs index c3dc5a4..8a32e0f 100644 --- a/src/MdBlocks/Address.hs +++ b/src/MdBlocks/Address.hs @@ -1,12 +1,38 @@ {-# LANGUAGE OverloadedStrings #-} -module MdBlocks.Address where +module MdBlocks.Address + ( Address(..) + , parseAddress + , addressOf + ) +where import Data.Text (Text) import qualified Data.Text as T import MdBlocks.Types +data Address + = GlobalId Text + | FileAddress FilePath Text + deriving (Show, Eq) + +parseAddress :: String -> Either String Address +parseAddress input = + case T.breakOn "#" (T.pack input) of + (file, ident) + | T.null file -> + Left "address must contain a file path" + + | T.null ident -> + Left "address must contain a block id after '#'" + + | otherwise -> + Right + (FileAddress + (T.unpack file) + (T.drop 1 ident)) + addressOf :: Block -> Text addressOf b = case mdId (blockMeta b) of -- cgit v1.3.1