*/ class syntax_plugin_doi_doi extends \dokuwiki\Extension\SyntaxPlugin { /** @inheritDoc */ public function getType() { return 'substition'; } /** @inheritDoc */ public function getPType() { return 'normal'; } /** @inheritDoc */ public function getSort() { return 155; } /** @inheritDoc */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('\[\[doi>[^\]]+\]\]', $mode, 'plugin_doi_doi'); } /** @inheritDoc */ public function handle($match, $state, $pos, Doku_Handler $handler) { $doi = substr($match, 6, -2); return ['id' => $doi]; } /** @inheritDoc */ public function render($mode, Doku_Renderer $renderer, $data) { $resolver = $this->getResolver(); $data['id'] = $resolver->cleanID($data['id']); try { $publication = $resolver->getData($data['id']); $url = $publication['url']; $title = $publication['title']; } catch (Exception $e) { msg(hsc($e->getMessage()), -1); $publication = null; $url = $resolver->getFallbackURL($data['id']); $title = $data['id']; } // FIXME use nicer rendering for non-xhtml modes if ($mode !== 'xhtml' || !$publication) { $renderer->externallink($url, $title); return true; } /** @var Doku_Renderer_xhtml $renderer */ $this->formatPub($publication, $renderer); return true; } /** * @return AbstractResolver */ protected function getResolver() { return new DoiResolver(); } /** * Render the given data * * @param array $data * @param Doku_Renderer_xhtml $renderer * @return void */ protected function formatPub($data, $renderer) { $renderer->doc .= '