syntax.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * Manlinks plugin: convert manpage descriptions to links to the manpages.
  4. */
  5. if(!defined('DOKU_INC')) die();
  6. if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  7. require_once(DOKU_PLUGIN.'syntax.php');
  8. class syntax_plugin_manlink extends DokuWiki_Syntax_Plugin {
  9. function getType() { return 'substition'; }
  10. function getPType() { return 'normal'; }
  11. function getSort() { return 361; }
  12. function connectTo($mode) {
  13. $this->Lexer->addSpecialPattern(
  14. '\!?[a-zA-Z0-9_.+\[\]-]*\([0-9]\)',
  15. $mode,
  16. 'plugin_manlink');
  17. }
  18. function handle($match, $state, $pos, Doku_Handler $handler){
  19. if ($state != DOKU_LEXER_SPECIAL)
  20. return false;
  21. if (substr($match, 0, 1) == "!") {
  22. $handler->_addCall('cdata', array(substr($match, 1)), $pos);
  23. return true;
  24. }
  25. $mantarget = $this->getconf('mantarget');
  26. $manpage = preg_replace('/^([a-zA-Z0-9_+\[\].-]*)\(([0-9])\)$/', '\1', $match);
  27. $section = preg_replace('/^([a-zA-Z0-9_+\[\].-]*)\(([0-9])\)$/', '\2', $match);
  28. if ($mantarget == 'NetBSD')
  29. $target = 'http://mdoc.su/n/'.$manpage.'.'.$section;
  30. elseif ($mantarget == 'FreeBSD')
  31. $target = 'http://mdoc.su/f/'.$manpage.'.'.$section;
  32. elseif ($mantarget == 'OpenBSD')
  33. $target = 'http://mdoc.su/o/'.$manpage.'.'.$section;
  34. elseif ($mantarget == 'DragonFlyBSD')
  35. $target = 'http://mdoc.su/d/'.$manpage.'.'.$section;
  36. $handler->_addCall('externallink', array($target, $match), $pos);
  37. return true;
  38. }
  39. function render($format, Doku_Renderer $renderer, $data) {
  40. return true;
  41. }
  42. }
  43. ?>