Fix links with section anchors (#51)

pull/49/head
Mickaël Menu 3 years ago committed by GitHub
parent 45f4d85169
commit 274234e608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,12 @@
All notable changes to this project will be documented in this file.
<!--## Unreleased-->
## Unreleased
### Fixed
* [#16](https://github.com/mickael-menu/zk/issues/16) Links with section anchors, e.g. `[[filename#section]]`.
## 0.5.0

@ -290,6 +290,10 @@ func (d *NoteDAO) findIdsByPathPrefixes(paths []string) ([]core.NoteID, error) {
}
func (d *NoteDAO) findIdByPathPrefix(path string) (core.NoteID, error) {
// Remove any anchor at the end of the HREF, since it's most likely
// matching a sub-section in the note.
path = strings.SplitN(path, "#", 2)[0]
row, err := d.findIdByPathPrefixStmt.QueryRow(path)
if err != nil {
return 0, err

@ -154,7 +154,7 @@ func TestNoteDAOAddWithLinks(t *testing.T) {
},
{
Title: "Second is added",
Href: "f39c8",
Href: "f39c8#anchor",
Rels: core.LinkRels("second"),
},
{
@ -194,7 +194,7 @@ func TestNoteDAOAddWithLinks(t *testing.T) {
SourceId: id,
TargetId: idPointer(4),
Title: "Second is added",
Href: "f39c8",
Href: "f39c8#anchor",
Rels: "\x01second\x01",
},
{

@ -175,6 +175,10 @@ func (n *Notebook) FindMinimalNotes(opts NoteFindOpts) ([]MinimalNote, error) {
// FindByHref retrieves the first note matching the given link href.
func (n *Notebook) FindByHref(href string) (*MinimalNote, error) {
// Remove any anchor at the end of the HREF, since it's most likely
// matching a sub-section in the note.
href = strings.SplitN(href, "#", 2)[0]
notes, err := n.FindMinimalNotes(NoteFindOpts{
IncludePaths: []string{href},
Limit: 1,

Loading…
Cancel
Save