-
Notifications
You must be signed in to change notification settings - Fork 36
/
Configurator.php
67 lines (59 loc) · 1.78 KB
/
Configurator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php declare(strict_types=1);
/**
* @package s9e\TextFormatter
* @copyright Copyright (c) 2010-2020 The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\TextFormatter\Plugins\TaskLists;
use s9e\TextFormatter\Configurator\Items\Tag;
use s9e\TextFormatter\Plugins\ConfiguratorBase;
class Configurator extends ConfiguratorBase
{
/**
* {@inheritdoc}
*/
public function asConfig()
{
return;
}
protected function setUp(): void
{
if (!isset($this->configurator->tags['LI']))
{
$this->configurator->Litedown;
}
$this->createTaskTag();
$this->configureListItemTag($this->configurator->tags['LI']);
}
protected function configureListItemTag(Tag $tag): void
{
$tag->filterChain->append(Helper::class . '::filterListItem')
->resetParameters()
->addParameterByName('parser')
->addParameterByName('tag')
->addParameterByName('text')
->setJS(file_get_contents(__DIR__ . '/filterListItem.js'));
$tag->template = preg_replace(
'(<li[^>]*+>(?!<xsl:if test="TASK">)\\K)',
'<xsl:if test="TASK">
<xsl:attribute name="data-task-id">
<xsl:value-of select="TASK/@id"/>
</xsl:attribute>
<xsl:attribute name="data-task-state">
<xsl:value-of select="TASK/@state"/>
</xsl:attribute>
</xsl:if>',
$tag->template
);
}
protected function createTaskTag(): void
{
$tag = $this->configurator->tags->add('TASK');
$tag->attributes->add('id')->filterChain->append('#identifier');
$tag->attributes->add('state')->filterChain->append('#identifier');
$tag->template = '<input data-task-id="{@id}" type="checkbox">
<xsl:if test="@state = \'complete\'"><xsl:attribute name="checked"/></xsl:if>
<xsl:if test="not($TASKLISTS_EDITABLE)"><xsl:attribute name="disabled"/></xsl:if>
</input>';
}
}