mirror of
https://github.com/cosmocode/dokuwiki-plugin-prosemirror.git
synced 2025-07-29 21:06:13 +00:00
feat: add support for quotes
This commit is contained in:
79
_test/json/quote.json
Normal file
79
_test/json/quote.json
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
{
|
||||||
|
"type": "doc",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "paragraph",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": "I think we should do it"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": " No we shouldn't"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": " Well, I say we should"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": " Really?"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": " Yes!"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "quote",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"text": " Then lets do it!"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
11
_test/json/quote.txt
Normal file
11
_test/json/quote.txt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
I think we should do it
|
||||||
|
|
||||||
|
> No we shouldn't
|
||||||
|
|
||||||
|
>> Well, I say we should
|
||||||
|
|
||||||
|
> Really?
|
||||||
|
|
||||||
|
>> Yes!
|
||||||
|
|
||||||
|
>>> Then lets do it!
|
@ -17,6 +17,7 @@ abstract class Node {
|
|||||||
'locallink' => LocalLinkNode::class,
|
'locallink' => LocalLinkNode::class,
|
||||||
'preformatted' => PreformattedNode::class,
|
'preformatted' => PreformattedNode::class,
|
||||||
'code_block' => CodeBlockNode::class,
|
'code_block' => CodeBlockNode::class,
|
||||||
|
'quote' => QuoteNode::class,
|
||||||
'image' => ImageNode::class,
|
'image' => ImageNode::class,
|
||||||
'hard_break' => HardBreakNode::class,
|
'hard_break' => HardBreakNode::class,
|
||||||
'horizontal_rule' => HruleNode::class,
|
'horizontal_rule' => HruleNode::class,
|
||||||
|
36
parser/QuoteNode.php
Normal file
36
parser/QuoteNode.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace dokuwiki\plugin\prosemirror\parser;
|
||||||
|
|
||||||
|
|
||||||
|
class QuoteNode extends Node
|
||||||
|
{
|
||||||
|
/** @var Node[] */
|
||||||
|
protected $subnodes = [];
|
||||||
|
|
||||||
|
protected $parent;
|
||||||
|
|
||||||
|
public function __construct($data, $parent) {
|
||||||
|
$this->parent = &$parent;
|
||||||
|
|
||||||
|
$previousNode = false;
|
||||||
|
foreach ($data['content'] as $nodeData) {
|
||||||
|
try {
|
||||||
|
$newNode = new self::$nodeclass[$nodeData['type']]($nodeData, $this, $previousNode);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
error_log("************ Unknown Node type: " . $nodeData['type'] . " ************");
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
$this->subnodes[] = $newNode;
|
||||||
|
$previousNode = $newNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toSyntax() {
|
||||||
|
$doc = '>';
|
||||||
|
foreach ($this->subnodes as $subnode) {
|
||||||
|
$doc .= $subnode->toSyntax();
|
||||||
|
}
|
||||||
|
return $doc;
|
||||||
|
}
|
||||||
|
}
|
12
renderer.php
12
renderer.php
@ -55,6 +55,18 @@ class renderer_plugin_prosemirror extends Doku_Renderer {
|
|||||||
$this->nodestack->drop('paragraph');
|
$this->nodestack->drop('paragraph');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @inheritDoc */
|
||||||
|
function quote_open()
|
||||||
|
{
|
||||||
|
$this->nodestack->addTop(new Node('quote'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @inheritDoc */
|
||||||
|
function quote_close()
|
||||||
|
{
|
||||||
|
$this->nodestack->drop('quote');
|
||||||
|
}
|
||||||
|
|
||||||
#region lists
|
#region lists
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
@ -56,6 +56,15 @@ const codeBlock = nodes.get('code_block');
|
|||||||
codeBlock.toDOM = function toDOM() { return ['pre', { class: 'code' }, 0]; };
|
codeBlock.toDOM = function toDOM() { return ['pre', { class: 'code' }, 0]; };
|
||||||
nodes = nodes.update('code_block', codeBlock);
|
nodes = nodes.update('code_block', codeBlock);
|
||||||
|
|
||||||
|
nodes = nodes.addToEnd('quote', {
|
||||||
|
content: 'block',
|
||||||
|
group: 'block',
|
||||||
|
inline: false,
|
||||||
|
toDOM() {
|
||||||
|
return ['blockquote', {}, ['div', { class: 'no' }, 0]];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
nodes = nodes.addToEnd('interwikilink', {
|
nodes = nodes.addToEnd('interwikilink', {
|
||||||
content: 'text',
|
content: 'text',
|
||||||
marks: '_',
|
marks: '_',
|
||||||
|
Reference in New Issue
Block a user