diff options
Diffstat (limited to 'src/MdBlocks/Address.hs')
| -rw-r--r-- | src/MdBlocks/Address.hs | 28 |
1 files changed, 27 insertions, 1 deletions
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 |
