mirror of
https://github.com/cosmocode/dokuwiki-plugin-prosemirror.git
synced 2025-07-29 21:06:13 +00:00
feat: add handling for emaillinks
This commit is contained in:
50
_test/json/emaillink.json
Normal file
50
_test/json/emaillink.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"type": "doc",
|
||||
"content": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "Email addresses like this one: "
|
||||
},
|
||||
{
|
||||
"type": "emaillink",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "andi@splitbrain.org"
|
||||
}
|
||||
],
|
||||
"attrs": {
|
||||
"href": "mailto:andi@splitbrain.org",
|
||||
"class": "mail",
|
||||
"title": "andi@splitbrain.org"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": " or "
|
||||
},
|
||||
{
|
||||
"type": "emaillink",
|
||||
"content": [
|
||||
{
|
||||
"type": "text",
|
||||
"text": "write me!"
|
||||
}
|
||||
],
|
||||
"attrs": {
|
||||
"href": "mailto:andi@splitbrain.org",
|
||||
"class": "mail",
|
||||
"title": "andi@splitbrain.org"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"text": " are recognized, too."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1
_test/json/emaillink.txt
Normal file
1
_test/json/emaillink.txt
Normal file
@ -0,0 +1 @@
|
||||
Email addresses like this one: [[andi@splitbrain.org]] or [[andi@splitbrain.org|write me!]] are recognized, too.
|
32
parser/EmailLinkNode.php
Normal file
32
parser/EmailLinkNode.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\prosemirror\parser;
|
||||
|
||||
|
||||
class EmailLinkNode extends Node
|
||||
{
|
||||
|
||||
protected $data;
|
||||
|
||||
public function __construct($data, $parent)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function toSyntax()
|
||||
{
|
||||
list(, $address) = explode(':', $this->data['attrs']['href'], 2);
|
||||
$title = '';
|
||||
|
||||
if ($this->data['content'][0]['type'] === 'image') {
|
||||
$imageNode = new ImageNode($this->data['content'][0], $this);
|
||||
$title = '|' . $imageNode->toSyntax();
|
||||
} else {
|
||||
if ($address !== $this->data['content'][0]['text']) {
|
||||
$title = '|' . $this->data['content'][0]['text'];
|
||||
}
|
||||
}
|
||||
|
||||
return '[[' . $address . $title . ']]';
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ abstract class Node {
|
||||
'interwikilink' => InterwikiLinkNode::class,
|
||||
'internallink' => InternalLinkNode::class,
|
||||
'externallink' => ExternalLinkNode::class,
|
||||
'emaillink' => EmailLinkNode::class,
|
||||
'locallink' => LocalLinkNode::class,
|
||||
'preformatted' => PreformattedNode::class,
|
||||
'code_block' => CodeBlockNode::class,
|
||||
|
20
renderer.php
20
renderer.php
@ -393,6 +393,26 @@ class renderer_plugin_prosemirror extends Doku_Renderer {
|
||||
$this->nodestack->drop('interwikilink');
|
||||
}
|
||||
|
||||
public function emaillink($address, $name = null)
|
||||
{
|
||||
if (null === $name) {
|
||||
$name = $address;
|
||||
}
|
||||
$isImage = is_array($name);
|
||||
if ($isImage) {
|
||||
$class = 'media';
|
||||
} else {
|
||||
$class = 'mail';
|
||||
}
|
||||
$emailLink = new Node('emaillink');
|
||||
$emailLink->attr('href', 'mailto:' . $address);
|
||||
$emailLink->attr('class', $class);
|
||||
$emailLink->attr('title', $address);
|
||||
$this->nodestack->addTop($emailLink);
|
||||
$this->cdata($name ?: $address);
|
||||
$this->nodestack->drop('emaillink');
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
function linebreak() {
|
||||
$this->nodestack->add(new Node('hard_break'));
|
||||
|
@ -132,6 +132,21 @@ nodes = nodes.addToEnd('locallink', {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
nodes = nodes.addToEnd('emaillink', {
|
||||
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