raster pushed a commit to branch master. http://git.enlightenment.org/website/www.git/commit/?id=828f80b5fcf1f6e1f5dfdb76515502303415fca2
commit 828f80b5fcf1f6e1f5dfdb76515502303415fca2 Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com> Date: Fri Apr 24 18:07:07 2015 +0900 WIKI CUSTOM - add codelink plugin to auto-link pages with keywords this will find keywords registered for extension like we added in a patch to geshi and dokuwiki core in regular paragraphs and auto-link them like the geshi blocks to the reference docs. pages need to know what language they are in so before you have any links working, you need to declare a language like: ~~CODE-c~~ --- public_html/lib/plugins/codelink/README | 27 +++++ public_html/lib/plugins/codelink/plugin.info.txt | 7 ++ public_html/lib/plugins/codelink/syntax.php | 131 +++++++++++++++++++++++ 3 files changed, 165 insertions(+) diff --git a/public_html/lib/plugins/codelink/README b/public_html/lib/plugins/codelink/README new file mode 100644 index 0000000..0afee5d --- /dev/null +++ b/public_html/lib/plugins/codelink/README @@ -0,0 +1,27 @@ +codelink Plugin for DokuWiki + +Link code keywords from regular wiki markdown not just code blocks + +All documentation for this plugin can be found at +http://www.enlightenment.org + +If you install this plugin manually, make sure it is installed in +lib/plugins/codelink/ - if the folder is called different it +will not work! + +Please refer to http://www.dokuwiki.org/plugins for additional info +on how to install plugins in DokuWiki. + +---- +Copyright (C) Carsten Haitzler <ras...@rasterman.com> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See the COPYING file in your DokuWiki folder for details diff --git a/public_html/lib/plugins/codelink/plugin.info.txt b/public_html/lib/plugins/codelink/plugin.info.txt new file mode 100644 index 0000000..cb9afb1 --- /dev/null +++ b/public_html/lib/plugins/codelink/plugin.info.txt @@ -0,0 +1,7 @@ +base codelink +author Carsten Haitzler +email ras...@rasterman.com +date 2015-04-24 +name codelink plugin +desc Link code keywords from regular wiki markdown not just code blocks +url http://www.enlightenment.org diff --git a/public_html/lib/plugins/codelink/syntax.php b/public_html/lib/plugins/codelink/syntax.php new file mode 100644 index 0000000..fbffdec --- /dev/null +++ b/public_html/lib/plugins/codelink/syntax.php @@ -0,0 +1,131 @@ +<?php +/** + * DokuWiki Plugin codelink (Syntax Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Carsten Haitzler <ras...@rasterman.com> + */ + +// must be run within Dokuwiki +if (!defined('DOKU_INC')) die(); + +class syntax_plugin_codelink extends DokuWiki_Syntax_Plugin { + + var $keydata = array(); + var $keylanguage; + + function load_lang_data($language) { + global $conf; + if (!empty($this->keydata[$language])) { + return; + } + + $extn_dir = $conf['datadir'] . '/' . $conf['code_extn']; + if (!file_exists($extn_dir)) { + $extn_dir = ''; + } + else { + $extn_link = $extn_dir . '/' . $language . '/keyword-link.txt'; + $extn_list = $extn_dir . '/' . $language . '/keyword-list.txt'; + if (file_exists($extn_link) && file_exists($extn_list)) { + $link_array = file($extn_link, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $keys_array = file($extn_list, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $this->keydata[$language]['link'] = $link_array[0]; + $this->keydata[$language]['keys'] = $keys_array; + foreach ($keys_array as $k) { + $this->Lexer->addSpecialPattern($k . '()', 'base', 'plugin_codelink'); + $this->Lexer->addSpecialPattern($k, 'base', 'plugin_codelink'); + } + } + } + } + /** + * @return string Syntax mode type + */ + public function getType() { + return 'substition'; + } + /** + * @return string Paragraph type + */ + public function getPType() { + return 'normal'; + } + /** + * @return int Sort order - Low numbers go before high numbers + */ + public function getSort() { + return 999; + } + + /** + * Connect lookup pattern to lexer. + * + * @param string $mode Parser mode + */ + public function connectTo($mode) { + // FIXME: make this cleaner + // languages supported here (languages supported list) + $langs = array('c'); + foreach($langs as $l) { + $this->Lexer->addSpecialPattern('~~CODE-' . $l . '~~', $mode, 'plugin_codelink'); + $this->load_lang_data($l); + } + } + + /** + * Handle matches of the codelink syntax + * + * @param string $match The match of the syntax + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler + * @return array Data for the renderer + */ + public function handle($match, $state, $pos, Doku_Handler &$handler){ + $data = array(); + + if (preg_match('/^~~CODE-/', $match)) { + // find special codelang tag and find declared language in it + // i.e. ~~CODE-c~~ -> c + // ~~CODE-py~~ -> py + // ~~CODE-lua~~ -> lua + // ~~CODE-cpp~~ -> cpp + $language = str_replace('~~CODE-', '', $match); + $language = str_replace('~~', '', $language); + $this->keylanguage = $language; + } else { + $data[0] = '<code class="code"><a href=' . + str_replace + ( + array( + '{FNAME}', + '{FNAMEL}', + '{FNAMEU}'), + array( + str_replace('+', '%20', urlencode($match)), + str_replace('+', '%20', urlencode(strtolower($match))), + str_replace('+', '%20', urlencode(strtoupper($match))), + ), + $this->keydata[$this->keylanguage]['link']) . + '><span class="kw5">' . $match . '</span></a></code>'; + } + return $data; + } + + /** + * Render xhtml output or metadata + * + * @param string $mode Renderer mode (supported modes: xhtml) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler() function + * @return bool If rendering was successful. + */ + public function render($mode, Doku_Renderer &$renderer, $data) { + if ($mode != 'xhtml') return false; + $renderer->doc .= $data[0]; + return true; + } +} + +// vim:ts=4:sw=4:et: --