New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path.absname, absolute paths for insert date #1847
Conversation
Complements Path.relname and Path.basename. In addition, replaced instances of "':' + link.name" with this new property and changed links created by the "Insert Date and Time" dialog absolute.
This addition could also be useful for implementing a "only use absolute links" option (see #492 (comment)) |
This comment has been minimized.
This comment has been minimized.
This patch builds on the broken Path.absname one (zim-desktop-wiki#1847) and thus isn't recommended for daily consumption. See zim-desktop-wiki#492 for further discussion.
The attribute |
Looking back, my problem was creating
Which part? I tried[0] handling I can't say I've wholly cracked the distinction between |
The class "Path" should be renamed to "PageName" that makes it more clear
what it is exactly. It is an (absolute) page name, no more, no less. It
should not have any logic for handling links.
We do have a "Link" class - the index has an "IndexLink" class to represent
a link between two pages as stored in the index.
The class "HRef" represents a link as it appears in the wiki source, and
contains semantic information about the link type but does not contain an
end point. It was introduced to help with the logic of updating links when
moving pages while preserving the link type (relative, floating or
absolute).
To resolve a link you need to first create a HRef and then call
notebook.pages.resolve_link(). Which will just return the end point as a
Path, not a Link as you might expect.
If you are sure you need an absolute link, you can indeed just call ":" +
path.name, however it may not be robust in some far future where an
alternative syntax is supported.
There is also notebook.pages.create_link() if you want the most concise
link format.
Hope this helps,
Jaap
…On Thu, Jan 6, 2022 at 8:41 AM introt ***@***.***> wrote:
Looking back, my problem was creating Paths from wiki syntax for relative
links, against the instructions in the documentation (Never construct a
path directly from user input).
Probably the most clean way to handle this would be to use a HRef object
rather than a path object ?
Which part? I tried[0] handling InsertDateDialog with a HRef just now,
ended up with HRef(HREF_REL_ABSOLUTE, self.link.name).to_wiki_link()
which seems excessive for prepending a : - self.link being a Path instead
of a HRef is a tad bit confusing.
I can't say I've wholly cracked the distinction between Path and HRef.
Why not have Path represent absolute paths with eg. from_relative_link(source:
Path, target: str) and to_wiki_link(relative_source: Path=None) to serve
the HRef needs? Being half-rhetorical here, probs has something to do
with either maintainability/performance/something I-can't-quite-articulate
regarding relative/floating links or semantics. Though semantically I also
find using rel in the context of "href" for location-relation instead of
resource-relation confusing, but that's likely due to me not grasping the
more abstract concepts and relating the terminology to html - I better stop
here before I start questioning why we don't have a Link class.
1. https://github.com/introt/zim-desktop-wiki/tree/href-date
—
Reply to this email directly, view it on GitHub
<#1847 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJQYHQBEHEG2HYZJSYTPS3UUVBRXANCNFSM5K7M73YA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
* zim.notebook.index.links - comment -> docstring - type annotated IndexLink * zim.notebook.index.pages - type annotated PagesView * zim.notebook.page - type annotated Path, HRef, shortest_unique_names - improved HRef documentation based on zim-desktop-wiki#1847
Thanks, that clears it up a lot!
":" + path.name is already used in a few places. Would the following addition to HRef make sense to you? Pagename shouldn't need another round of validation or resolving, and this allows the future-proof creation of absolute links without importing HREF_REL_ABSOLUTE.
I've opened #1853 for some related documentation improvements. |
* zim.notebook.index.links - comment -> docstring - type annotated IndexLink * zim.notebook.index.pages - type annotated PagesView * zim.notebook.page - type annotated Path, HRef, shortest_unique_names - improved HRef documentation based on zim-desktop-wiki#1847
For now the ":" + page name usage is fine. A convenience method on href is
also ok with me.
Open to PR to rename Path. Probably will keep Path as an alias to avoid
breaking 3rd party code for some time.
Op vr 7 jan. 2022 14:27 schreef introt ***@***.***>:
… Thanks, that clears it up a lot!
PageName is (at least in this context) a lot more descriptive - and is
used in some parameter names already. Are you open to a PR for this?
If you are sure you need an absolute link, you can indeed just call ":" +
path.name, however it may not be robust in some far future where an
alternative syntax is supported.
":" + path.name is already used in a few places. Would the following
addition to HRef make sense to you? Pagename shouldn't need another round
of validation or resolving, and this allows the future-proof creation of
absolute links without importing HREF_REL_ABSOLUTE.
@classmethod
def pagename_to_wiki_link(klass, pagename):
'''Returns href for C{pagename} as text for absolute wiki link.'''
#return ':' + pagename.name
return klass(HREF_REL_ABSOLUTE, pagename.name).to_wiki_link()
I've opened #1853
<#1853> for some
related documentation improvements.
—
Reply to this email directly, view it on GitHub
<#1847 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJQYHR22JVTR2HPQIPHFSLUU3S33ANCNFSM5K7M73YA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
* zim.notebook.index.links - comment -> docstring - type annotated IndexLink * zim.notebook.index.pages - type annotated PagesView * zim.notebook.page - type annotated Path, HRef, shortest_unique_names - improved HRef documentation based on #1847
Complements Path.relname and Path.basename. In addition, replaced
instances of "':' + link.name" with this new property and changed
links created by the "Insert Date and Time" dialog absolute.