fix: add handling for windows share links

This commit is contained in:
Michael Große
2018-01-30 15:00:55 +01:00
parent 16354267cf
commit 92a5ea435b
6 changed files with 103 additions and 0 deletions

View 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."
}
]
}
]
}

View File

@ -0,0 +1 @@
Windows Shares like [[\\server\share|this]] are recognized, too.

View File

@ -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,

View 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 . ']]';
}
}

View File

@ -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'));

View File

@ -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',