dokuwiki-plugin-semantic/syntax.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2015-03-25 23:48:00 +00:00
<?php
/**
* Semantic plugin: Add Schema.org News Article using JSON-LD
*
2015-03-25 23:48:00 +00:00
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com>
* @copyright (C) 2015-2023, Giuseppe Di Terlizzi
2015-03-25 23:48:00 +00:00
*/
class syntax_plugin_semantic extends DokuWiki_Syntax_Plugin
{
2015-03-25 23:48:00 +00:00
private $macros = array(
'~~NewsArticle~~', '~~Article~~', '~~TechArticle~~',
'~~BlogPosting~~', '~~Recipe~~', '~~NOSEMANTIC~~',
);
2015-03-25 23:48:00 +00:00
public function getType()
{return 'substition';}
public function getSort()
{return 99;}
2015-03-25 23:48:00 +00:00
public function connectTo($mode)
{
foreach ($this->macros as $macro) {
$this->Lexer->addSpecialPattern($macro, $mode, 'plugin_semantic');
}
2015-03-25 23:48:00 +00:00
}
public function handle($match, $state, $pos, Doku_Handler $handler)
{
return array($match, $state, $pos);
}
public function render($mode, Doku_Renderer $renderer, $data)
{
2015-03-25 23:48:00 +00:00
if ($mode == 'metadata') {
2015-03-25 23:48:00 +00:00
list($match, $state, $pos) = $data;
2015-03-25 23:48:00 +00:00
if ($match == '~~NOSEMANTIC~~') {
$renderer->meta['plugin']['semantic']['enabled'] = false;
} else {
$renderer->meta['plugin']['semantic']['schema.org']['type'] = trim(str_replace('Schema.org/', '', $match), '~~');
$renderer->meta['plugin']['semantic']['enabled'] = true;
}
}
2015-03-25 23:48:00 +00:00
return false;
}
2015-03-25 23:48:00 +00:00
}