mirror of
https://github.com/cosmocode/dokuwiki-plugin-prosemirror.git
synced 2025-07-29 21:06:13 +00:00
fix: add handling for windows share links
This commit is contained in:
32
_test/json/windowssharelink.json
Normal file
32
_test/json/windowssharelink.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"type": "doc",
|
||||
"content": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "Windows Shares like "
|
||||
},
|
||||
{
|
||||
"type": "windowssharelink",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "this"
|
||||
}
|
||||
],
|
||||
"attrs": {
|
||||
"href": "file:\/\/\/\/\/server\/share",
|
||||
"class": "windows",
|
||||
"title": "\\\\server\\share"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": " are recognized, too."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1
_test/json/windowssharelink.txt
Normal file
1
_test/json/windowssharelink.txt
Normal file
@ -0,0 +1 @@
|
||||
Windows Shares like [[\\server\share|this]] are recognized, too.
|
@ -15,6 +15,7 @@ abstract class Node {
|
||||
'externallink' => ExternalLinkNode::class,
|
||||
'emaillink' => EmailLinkNode::class,
|
||||
'locallink' => LocalLinkNode::class,
|
||||
'windowssharelink' => WindowsShareLinkNode::class,
|
||||
'preformatted' => PreformattedNode::class,
|
||||
'code_block' => CodeBlockNode::class,
|
||||
'quote' => QuoteNode::class,
|
||||
|
33
parser/WindowsShareLinkNode.php
Normal file
33
parser/WindowsShareLinkNode.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\prosemirror\parser;
|
||||
|
||||
|
||||
class WindowsShareLinkNode extends Node
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data, $parent)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function toSyntax()
|
||||
{
|
||||
$url = $this->data['attrs']['href'];
|
||||
$url = substr($url, strlen('file:///'));
|
||||
$url = str_replace('/', '\\', $url);
|
||||
$title = '';
|
||||
|
||||
if ($this->data['content'][0]['type'] === 'image') {
|
||||
$imageNode = new ImageNode($this->data['content'][0], $this);
|
||||
$title = '|' . $imageNode->toSyntax();
|
||||
} else {
|
||||
if ($url !== $this->data['content'][0]['text']) {
|
||||
$title = '|' . $this->data['content'][0]['text'];
|
||||
}
|
||||
}
|
||||
|
||||
return '[[' . $url . $title . ']]';
|
||||
}
|
||||
}
|
22
renderer.php
22
renderer.php
@ -452,6 +452,28 @@ class renderer_plugin_prosemirror extends Doku_Renderer {
|
||||
$this->nodestack->drop('emaillink');
|
||||
}
|
||||
|
||||
public function windowssharelink($link, $title = null)
|
||||
{
|
||||
if (null === $title) {
|
||||
$title = $link;
|
||||
}
|
||||
$isImage = is_array($title);
|
||||
if ($isImage) {
|
||||
$class = 'media';
|
||||
} else {
|
||||
$class = 'windows';
|
||||
}
|
||||
$url = str_replace('\\', '/', $link);
|
||||
$url = 'file:///'.$url;
|
||||
$wShareLinkNode = new Node('windowssharelink');
|
||||
$wShareLinkNode->attr('href', $url);
|
||||
$wShareLinkNode->attr('class', $class);
|
||||
$wShareLinkNode->attr('title', hsc($link));
|
||||
$this->nodestack->addTop($wShareLinkNode);
|
||||
$this->cdata($title);
|
||||
$this->nodestack->drop('windowssharelink');
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
function linebreak() {
|
||||
$this->nodestack->add(new Node('hard_break'));
|
||||
|
@ -156,6 +156,20 @@ nodes = nodes.addToEnd('emaillink', {
|
||||
},
|
||||
});
|
||||
|
||||
nodes = nodes.addToEnd('windowssharelink', {
|
||||
content: 'text|image',
|
||||
group: 'inline', // fixme should later be changed to substition? or add substitution?
|
||||
inline: true,
|
||||
attrs: {
|
||||
class: {},
|
||||
href: {},
|
||||
title: {},
|
||||
},
|
||||
toDOM(node) {
|
||||
return ['a', node.attrs, 0];
|
||||
},
|
||||
});
|
||||
|
||||
nodes = nodes.addToEnd('footnote', {
|
||||
content: 'inline',
|
||||
group: 'inline',
|
||||
|
Reference in New Issue
Block a user