Skip to content

Commit

Permalink
Identify mailto: links as URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed May 31, 2024
1 parent 1208a02 commit bb785f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed warnings when renaming a note using dry-run.
- Fixed handling check boxes with characters that have a special meaning in regular expressions (e.g. "?").
- `Client:create_note()` will always ensure the parent directory exists, even when not writing the note itself to disk, to avoid downstream issues (see #600).
- Identify `mailto:` links as URLs.

## [v3.7.12](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.12) - 2024-05-02

Expand Down
2 changes: 2 additions & 0 deletions lua/obsidian/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ M.RefTypes = {
Markdown = "Markdown",
NakedUrl = "NakedUrl",
FileUrl = "FileUrl",
MailtoUrl = "MailtoUrl",
Tag = "Tag",
BlockID = "BlockID",
Highlight = "Highlight",
Expand All @@ -42,6 +43,7 @@ M.Patterns = {
Markdown = "%[[^][]+%]%([^%)]+%)", -- [yyy](xxx)
NakedUrl = "https?://[a-zA-Z0-9._-]+[a-zA-Z0-9._#/=&?:+%%-]+[a-zA-Z0-9/]", -- https://xyz.com
FileUrl = "file:/[/{2}]?.*", -- file:///
MailtoUrl = "mailto:.*", -- mailto:emailaddress
BlockID = util.BLOCK_PATTERN .. "$", -- ^hello-world
}

Expand Down
1 change: 1 addition & 0 deletions lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ util.is_url = function(s)
if
string.match(util.strip_whitespace(s), "^" .. search.Patterns[search.RefTypes.NakedUrl] .. "$")
or string.match(util.strip_whitespace(s), "^" .. search.Patterns[search.RefTypes.FileUrl] .. "$")
or string.match(util.strip_whitespace(s), "^" .. search.Patterns[search.RefTypes.MailtoUrl] .. "$")
then
return true
else
Expand Down
4 changes: 4 additions & 0 deletions test/obsidian/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ describe("util.is_url()", function()
it("should identify semantic scholar API URLS", function()
assert.is_true(util.is_url "https://api.semanticscholar.org/CorpusID:235829052")
end)

it("should identify 'mailto' URLS", function()
assert.is_true(util.is_url "mailto:mail@domain.com")
end)
end)

describe("util.strip_anchor_links()", function()
Expand Down

0 comments on commit bb785f7

Please sign in to comment.