Render open-location syntax as link
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled

This commit is contained in:
2026-01-07 11:42:40 +01:00
parent 6a396ce511
commit c5f4bcc1c5
7 changed files with 156 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ use dokuwiki\Extension\SyntaxPlugin;
/**
* luxtools Plugin: Open local path syntax.
*
* Renders an inline button. Clicking it triggers client-side JS that attempts
* Renders an inline link. Clicking it triggers client-side JS that attempts
* to open the configured path in the default file manager (best-effort).
*/
class syntax_plugin_luxtools_open extends SyntaxPlugin
@@ -74,14 +74,36 @@ class syntax_plugin_luxtools_open extends SyntaxPlugin
}
$serviceUrl = trim((string)$this->getConf('open_service_url'));
$serviceToken = trim((string)$this->getConf('open_service_token'));
$attrs = ' type="button" class="luxtools-open"'
. ' data-path="' . hsc($path) . '"';
if ($serviceUrl !== '') {
$attrs .= ' data-service-url="' . hsc($serviceUrl) . '"';
if (!($renderer instanceof \Doku_Renderer_xhtml)) {
$renderer->cdata($caption);
return true;
}
$renderer->doc .= '<button' . $attrs . '>' . hsc($caption) . '</button>';
global $conf;
/** @var \Doku_Renderer_xhtml $renderer */
// Render like a normal DokuWiki link with an icon in front.
// Use the same folder icon class as directory listings.
$link = [
'target' => $conf['target']['extern'],
'style' => '',
'pre' => '',
'suf' => '',
'name' => $caption,
'url' => '#',
'title' => $renderer->_xmlEntities($path),
'more' => '',
'class' => 'luxtools-open media mediafile mf_folder',
];
$link['more'] .= ' data-path="' . hsc($path) . '"';
if (!empty($conf['relnofollow'])) $link['more'] .= ' rel="nofollow"';
if ($serviceUrl !== '') $link['more'] .= ' data-service-url="' . hsc($serviceUrl) . '"';
if ($serviceToken !== '') $link['more'] .= ' data-service-token="' . hsc($serviceToken) . '"';
$renderer->doc .= $renderer->_formatLink($link);
return true;
}
}