-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add support for wiki links in SVG diagrams #61
Comments
Prototype for the JavaScript rendering of the links in svgembed (disclaimer: created with the help of ChatGPT):
Possible problems
Possible enhancement
Edit: 29.11.2023One thing to consider with the links inside a SVGs is that all links should be rendered relative to the namespace of the SVG itself. Otherwise the links would lead to different pages if the the SVG is included in multiple pages. Also, if the links are not rendered relative to the namespace of the SVG, page moves could lead to broken links. How should the link be changed on a page move if the SVG is used on two different pages? The only thing we can certainly know on a page move is the namespace of the SVG itself. Edit: 30.11.2023If the SVG is viewed without a wiki page (in a new tab when opened from a link / from the media manager) the script is not loaded and the links are not rendered. Another possibility is to modify the SVG when the 'MEDIA_SENDFILE' event triggers. This is also beneficial for rendering the link state (existence of the linked page/media file). But I'll first have to look into caching for modified media files because otherwise the parsing of the SVG would happen on each request. Another edit for the edit: The svgimg2 plugin does a conversion for SVG files and then stores the output in a custom cache file: https://codesearch.dokuwiki.org/xref/plugin/svgimg2/action.php#49 |
About moving pages with the "move" pluginAn example for how pages are moved can be found in the rename function of the move plugin: Here affected PAGES are searched through the meta key "relation_references" (these are pages that reference our currently moved page): It then saves information for the move in the meta data entry "plugin_move" for each of the affected pages: After the meta data has been saved and the page is renamed it then redirects to the new location of the page. On the next "IO_WIKIPAGE_READ" event the plugin tries to modify the page content: Then it initializes a new parser with the handlers that have been registered by the move compatible plugins: This means that for each syntax plugin the lexer entry is matched against the content of the page and if it matches, the registered plugin handler for the modification of the match according to the move is called. What this means for SVGsNormally the "relation_references" meta data is only created for pages. As far as I understand, meta data can also be saved for media files. Pitfalls (=how many plugins are affected)
Edit: 29.11.2023It seems like the indexer of dokuwiki (which the move plugin uses to find all affected pages with the "relation_references" meta entry) does not index the meta data of media files.
|
…reliminary implementation for lejmr/dokuwiki-plugin-drawio#61
Technical difficulties with the orphanswanted pluginThe orphanswanted plugin correctly receives the pages (including our SVG media files that have been added to the index with the code shown in my last comment): But then it checks if the page exists before receiving the "relation_references" meta data for the SVG. Since the SVG ist not a page, the check fails and the references are never added to the index: If I remove this check from the orphanswanted plugin, the links from the SVGs are correctly shown in the overviews created with the plugin. But when clicking on the backlinks of a page, the backlink page of dokuwik (builtin functionality) does not show the SVG that linked the page. This is due to another "page_exists": Possible workaroundIn all cases an additional check for "media_exists" could be added where "page_exists" is run for IDs returned from the indexer for "relation_references" meta data. This would allow for media files to also reference pages. |
Current progress: rendering of wiki linksI now implemented the rendering of wiki links to pages and media files inside SVGs in svgembed with PHP. I use a caching object that stores the modified SVG and check if the original SVG has a newer timestamp for expiring the cache. So far this works. The code is not ready yet because I have to do more testing. One thing I noticed is that the current mechanism of loading SVGs that have been edited with drawio are directly loaded from the editor to the current view of the page. This way the rendering of wiki links does not happen. Also the page format is broken if the old page used svgembed to display the SVG. Edit 01.12.2023In the JavaScript code of the drawio plugin I now added a test to detect whether the SVG is rendered with the svgembed plugin and then load the SVG via the media fetch executor of dokuwiki on save. This ensures that the SVG goes through the renderer that I implemented in svgembed. I'm now working on setting the styles of the links for existing/non-existing wiki pages (style classes "wikilink1" and "wikilink2"). But since the svgembed plugin loads the SVG inside an object-element (which is considered good practice), the style classes are not available in the SVG element. I currently see two possibilities for fixing this:
|
…luded in a SVGs and the rendering of wiki links through cache files. The references of wiki links are stored both in the meta file of the SVG and the indexer. This is a preparation step for implement the rewrite of wiki links inside the SVG when pages are moved with the move plugin. Also a render function is implemented that renders wiki links inside the SVG and stores the rendered SVG in the cache. This is a preliminary version - the meta data is updated on each fetch of the status of the SVG (very inefficent). This commit is part of lejmr/dokuwiki-plugin-drawio#61
The current versions of the plugins can be found in:
What does work
What does NOT work
|
Introduction
The drawio plugin for dokuwiki greatly enhances the experience for users by increasing the speed in which documentations can be created without leaving the wiki. I instructed our users to crate SVG diagrams by default. I'm also using #53, which shows an edit button and enables the proper use of links inside the diagrams.
I think the last showstopper for creating the perfect diagrams inside dokuwiki is the feature to implement wiki links
[[namespace:page|Link Name]]
inside the diagrams. Right now links to wiki pages have to be set with the complete URLwiki.my-domain.com/namespace/page#section
. But using static URLs quickly leads to broken links if pages are moved.Technical prerequisites
If SVGs are enabled for drawio in dokuwiki, drawio saves the diagram with embedded drawio diagram data (https://www.drawio.com/doc/faq/save-file-formats). The data of links inside the diagram elements is represented with the following string
href="[[namespace:page|Text]]"
. This can be read and altered from php. The SVG elements are represented as normal HTML links<a href="[[namespace:page|Text]]">Original link text</a>
Concept
As it is hard to constantly modify the original drawio file for rendering the links, it might be a good idea to move the rendering of these links to JavaScript. But links could be broken if pages are moved. Also plugins like "OrphansWanted" (https://www.dokuwiki.org/plugin:orphanswanted) should be able to index the links.
this way the OrphansWanted plugin (and other plugins) know about our diagram including a link to another page
Possible problems
-> maybe use the link text from the original object in drawio and do not use the link text from the wiki link
-> might need more complex move handling
Edit 27.11.2023
Another requirement that was not mentioned clearly in the original text is that we probably should use the svgembed plugin for this feature (an implementation can be seen in https://github.com/gkrid/dokuwiki-plugin-drawio/tree/feature-svgembed-integration - I also use this feature with some slight modifications in my setup). This would make it easier to implement the JavaScript rendering of links. But there also occurs a problem: we only render the svgembed syntax. I think this would break some event handlers that are needed for move events and all meta data registration that happens in svgembed that need to be implemented for the compatibility with the plugins move and orphanswanted.
The text was updated successfully, but these errors were encountered: