Skip to content

Commit

Permalink
Allow dot in Zettel ID; resolves #369
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Sep 14, 2020
1 parent 73ed7fe commit 27e1dea
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Inline tags (#189)
- support for [fancy lists](https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/fancy_lists.md) (#335)
- Fix hard line breaks to actually work (#354)
- Allow dot in Zettel ID (#369)
- CLI
- Faster querying: add `--cached` option to `neuron query`, to run faster using the cache. To keep the cache up to date, make sure that `neuron rib` is running.
- Add `--id` and `--search` options to `open` command to open given zettel ID or search page respectively (#317)
Expand Down
1 change: 1 addition & 0 deletions guide/2011403.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ specify your own as well, as long as it contains only the following characters:
* digits
* hyphen (`-`)
* underscore (`_`)
* dot (`.`)

## Why prefer random IDs?

Expand Down
2 changes: 1 addition & 1 deletion neuron/neuron.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 2.4
name: neuron
-- This version must be in sync with what's in Default.dhall
version: 0.6.9.0
version: 0.6.9.1
license: AGPL-3.0-only
copyright: 2020 Sridhar Ratnakumar
maintainer: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion neuron/src/lib/Neuron/Zettelkasten/ID.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dayParser = do

customIDParser :: Parser Text
customIDParser = do
fmap toText $ M.some $ M.alphaNumChar <|> M.char '_' <|> M.char '-'
fmap toText $ M.some $ M.alphaNumChar <|> M.char '_' <|> M.char '-' <|> M.char '.'

-- | Parse the ZettelID if the given filepath is a zettel.
getZettelID :: ZettelFormat -> FilePath -> Maybe ZettelID
Expand Down
10 changes: 5 additions & 5 deletions neuron/src/lib/Neuron/Zettelkasten/Query/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ queryFromURI defConn uri = do
(URI.unRText -> path) :| [] <- hoistMaybe shortLinkPath
zid <-
hoistMaybe $
-- Allow direct use of ID
rightToMaybe (parseZettelID path)
-- Also, allow raw filename (ending with ".md"). HACK: hardcoding
-- format, but we shouldn't.
<|> getZettelID ZettelFormat_Markdown (toString path)
-- Allow raw filename (ending with ".md"). HACK: hardcoding
-- format, but we shouldn't.
getZettelID ZettelFormat_Markdown (toString path)
-- Before checking for direct use of ID
<|> rightToMaybe (parseZettelID path)
pure $ Some $ ZettelQuery_ZettelByID zid conn
Just (URI.unRText -> proto) -> do
guard $ proto == "z"
Expand Down
6 changes: 5 additions & 1 deletion neuron/test/Neuron/Zettelkasten/IDSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ spec = do
let deceptiveZid = Z.ZettelCustomID "2136537e"
it "parses a custom zettel ID that looks like date ID" $ do
Z.parseZettelID "2136537e" `shouldBe` Right deceptiveZid
it "parses a custom zettel ID with dot" $ do
Z.parseZettelID "foo.bar" `shouldBe` Right (Z.ZettelCustomID "foo.bar")
-- Even if there is a ".md" (not a file extension)
Z.parseZettelID "foo.md" `shouldBe` Right (Z.ZettelCustomID "foo.md")
context "failures" $ do
it "fails to parse ID with disallowed characters" $ do
Z.parseZettelID "/foo" `shouldSatisfy` isLeft
Z.parseZettelID "foo." `shouldSatisfy` isLeft
Z.parseZettelID "foo$" `shouldSatisfy` isLeft
Z.parseZettelID "foo bar" `shouldSatisfy` isLeft
describe "ID converstion" $ do
context "JSON encoding" $ do
Expand Down

0 comments on commit 27e1dea

Please sign in to comment.