Skip to content

Commit

Permalink
Correctly deal with multiple links on one line (#30)
Browse files Browse the repository at this point in the history
* 🐞 Fix greedy matching of [[]] links.

* 🐞 Fix greedy matching of []() links.
  • Loading branch information
BasilPH authored Jul 12, 2020
1 parent dc0283c commit dc6888b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vizel"
version = "0.2.0"
version = "0.2.1"
description = "Vizualise a Zettelkasten"
authors = ["Basil Philipp <basil@interdimensional-television.com>"]
license = "GPL-3.0-only"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ nocite: |
---
---

Here we have to links on one line to test the regex. [A first link](202002251025_This_is_the_first_test_zettel.md) and a [second line](202003211727_This_is_the_second_test_zettel.md).


### **References:**
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# 202002251025 This is the first test Zettel
tags: #artificialintelligence #zettelkasten

This Zettel references this other Zettel here[[202002241029]].

It points to the second Zettel [[202003211727]].
This Zettel references this other Zettel here[[202002241029]]. It points to the second Zettel [[202003211727]].


## It also has subtitles, fancy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ nocite: |
---
---

Here we have to links on one line to test the regex. [A first link](202002251025_This_is_the_first_test_zettel.txt) and a [second line](202003211727_This_is_the_second_test_zettel.txt).

### **References:**
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# 202002251025 This is the first test Zettel
tags: #artificialintelligence #zettelkasten

This Zettel references this other Zettel here[[202002241029]].

It points to the second Zettel [[202003211727]].
This Zettel references this other Zettel here[[202002241029]]. It points to the second Zettel [[202003211727]].


## It also has subtitles, fancy
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vizel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def test_stats(zettelkasten_directory, stderr_expected):
assert result.exit_code == 0
stdout_output = (
'7 Zettel\n'
'4 references between Zettel\n'
'6 references between Zettel\n'
'2 Zettel with no references\n'
'4 connected components\n'
'3 connected components\n'
)
assert result.stdout == stdout_output

Expand Down
8 changes: 5 additions & 3 deletions vizel/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def _load_references(zettel_path, zettel_directory_path):
zettel_filenames = sorted(
[os.path.basename(f) for f in glob.glob(os.path.join(zettel_directory_path, '*[.md|.txt]'))])

# Extract references for the [[]] link format
references += _extract_valid_references('\[\[(.+)\]\]', zettel_path, zettel_filenames)
# Extract references for the [[ID]] link format
# Look for [[, and then match anything that isn't ]]. End with ]].
references += _extract_valid_references('\[\[([^\]\]]+)\]\]', zettel_path, zettel_filenames)

# Extract references for the markdown link format
references += _extract_valid_references('\[.*\]\((.+)\)', zettel_path, zettel_filenames)
# Look for [, and then match anything that isn't ]. Then look for ( and match anything that isn't ). End with ).
references += _extract_valid_references('\[[^\]]+\]\(([^\)]+)\)', zettel_path, zettel_filenames)

return references

Expand Down

0 comments on commit dc6888b

Please sign in to comment.