DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:source

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:source [2009-08-31 11:51] – standardize author name ChrisSplugin:source [2023-10-30 22:58] (current) Klap-in
Line 2: Line 2:
  
 ---- plugin ---- ---- plugin ----
-description: Allows you to include all or part of the contents of another file, with syntax highlighting, into the current page.+description: Allows you to include all or part of the contents of another file, with syntax highlighting, into the current page
 author     : Christopher Smith author     : Christopher Smith
 email      : chris@jalakai.co.uk email      : chris@jalakai.co.uk
 type       : syntax type       : syntax
 lastupdate : 2008-08-13 lastupdate : 2008-08-13
-compatible : 2007-06-26 and later, 2006-11-06+compatible : Hrun
 depends    :  depends    : 
 conflicts  conflicts 
 similar    :  similar    : 
-tags       : sourcesyntaxhighlightingcode, programming+tags       : codesyntaxhighlightincludefile 
 +downloadurl: http://dokuwiki.jalakai.co.uk/plugin-source.tar.gz
 ---- ----
  
Line 20: Line 21:
   * **//filename//** --- required, the name of the file to be included.  This can either be a normal path & file name or a URI. If you wish to use file URI' then ''allow_url_fopen=On'' must be set in the webserver's php.ini file (also refer to the [[#security|location]] setting and the [[#warnings|security warning]] below).  If //filename// includes spaces it must be surrounded by a matched pair of quotes (''%%'%%'' or ''%%"%%'').   * **//filename//** --- required, the name of the file to be included.  This can either be a normal path & file name or a URI. If you wish to use file URI' then ''allow_url_fopen=On'' must be set in the webserver's php.ini file (also refer to the [[#security|location]] setting and the [[#warnings|security warning]] below).  If //filename// includes spaces it must be surrounded by a matched pair of quotes (''%%'%%'' or ''%%"%%'').
   * **//#start-end//** --- optional, only show lines from ''start'' to ''end'' First line in the file is counted as 1.  Both ''start'' and ''end'' must be positive numbers. If ''end'' is less than ''start'' or ''start'' is greater than there are lines in the file nothing will be shown.   * **//#start-end//** --- optional, only show lines from ''start'' to ''end'' First line in the file is counted as 1.  Both ''start'' and ''end'' must be positive numbers. If ''end'' is less than ''start'' or ''start'' is greater than there are lines in the file nothing will be shown.
-  * **//language//** --- optional, the language string to be passed to [[http://qbnz.com/highlighter/|GeSHi]] for syntax highlighting.  This plug-in accepts the same language strings as [[:syntax#syntax_highlighting|DokuWiki's <code> markup]].  If the language string is not given, the plugin will attempt to deduce the language from the file extension.+  * **//language//** --- optional, the language string to be passed to [[http://qbnz.com/highlighter/|GeSHi]] for syntax highlighting.  This plug-in accepts the same language strings as [[:wiki:syntax#syntax_highlighting|DokuWiki's <code> markup]].  If the language string is not given, the plugin will attempt to deduce the language from the file extension.
   * **//title//** --- optional, a title to be displayed above the file contents.  Everything after the pipe (''|'') is treated as the ''title''. If not present the file name will be used, e.g. //"file: ''filename''"//   * **//title//** --- optional, a title to be displayed above the file contents.  Everything after the pipe (''|'') is treated as the ''title''. If not present the file name will be used, e.g. //"file: ''filename''"//
  
Line 58: Line 59:
  
 ===== Installation ===== ===== Installation =====
 +Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
 +
  
-This plugin can be installed by the [[plugin:plugin]] manager using the following packages: 
   * [[http://dokuwiki.jalakai.co.uk/plugin-source.zip|zip format (8k)]]   * [[http://dokuwiki.jalakai.co.uk/plugin-source.zip|zip format (8k)]]
   * [[http://dokuwiki.jalakai.co.uk/plugin-source.tar.gz|tar.gz format (5k)]]   * [[http://dokuwiki.jalakai.co.uk/plugin-source.tar.gz|tar.gz format (5k)]]
  
-Or using [[http://darcs.net/DarcsWiki|darcs]] 
-  * [[http://wiki.jalakai.co.uk/repo/dokuwiki/plugins/source|darcs repository]] 
- 
-=== Manual Installation === 
- 
-Download one of the first two packages to your plugin folder, ''lib/plugins'' and extract its contents.  That will create a new plugin folder, ''lib/plugins/source'' and install the plugin there. 
  
-The folder will contain: 
-  conf/ 
-  conf/default.php                       default setting values 
-  conf/metadata.php                      setting details for DokuWiki's configuration plugin 
-  lang/ 
-  lang/xx/                               directory for each supported language, will always include 'en' 
-  lang/xx/lang.php                       language strings used by the plugin itself 
-  lang/xx/setting.php                    language strings used by DokuWiki's configuration plugin 
-  action.php                             action plugin component - provides caching support 
-  style.css                              styles for the new boxes and titles 
-  syntax.php                             syntax plugin component 
  
-The plugin is now installed. 
  
 ===== Revision History ===== ===== Revision History =====
Line 92: Line 76:
     * add support for (basic) rules to govern source file access. The rules work in addition to the earlier 'location','allow' & 'deny' criteria. It is probably sensible to use one or the other.  That is, if you use rules set the other three settings to empty string.     * add support for (basic) rules to govern source file access. The rules work in addition to the earlier 'location','allow' & 'deny' criteria. It is probably sensible to use one or the other.  That is, if you use rules set the other three settings to empty string.
     * add support for line number selection.     * add support for line number selection.
-    * add support for any renderer format.  If a format other than 'XHTML' or 'metadata' is chosen, the plugin reads the appropriate lines from the source file and passes them to DokuWiki's ->code() method to be rendered in the same was as a code block+    * add support for any renderer format.  If a format other than 'XHTML' or 'metadata' is chosen, the plugin reads the appropriate lines from the source file and passes them to DokuWiki's ->code() method to be rendered in the same was as a code block.
   * 2006-05-01 --- (darcs version only, others to follow) Settings updated to use [[devel:common plugin functions]] which will allow them to be edited using the [[plugin:config|Configuration Manger]] in the admin menu.   * 2006-05-01 --- (darcs version only, others to follow) Settings updated to use [[devel:common plugin functions]] which will allow them to be edited using the [[plugin:config|Configuration Manger]] in the admin menu.
   * 2005-08-23 --- updated; supports filenames with spaces.   * 2005-08-23 --- updated; supports filenames with spaces.
Line 231: Line 215:
 ---- ----
  
 +==== Numbering Lines ====
 +
 +This change in syntax.php will number the lines:\\ 
 +<sup>last four source lines</sup>
 +
 +<file php syntax_changes.php>
 +    function _getSource($file,$start,$end) {
 +
 +      $source = @file($this->location.$file);
 +      if (empty($source)) return '';
 +
 +      // $start is a 1 based index, need to correct to 0 based when slicing arrray
 +      if (!empty($start)) {
 +        $lines = count($source);
 +        if ($start > $lines) {
 +          $source = $this->getLang('error_start');
 +        } else if ($end < $start) {
 +          $source = $this->getLang('error_end');
 +        } else if ($end > $lines) {
 +          $source = join('',array_slice($source,$start-1));
 +        } else {
 +          $source = join('',array_slice($source,$start-1,$end-$start));
 +        }
 +      } else {
 +        $source = join('',$source);
 +      }
 +
 +      $rows = explode("\n", $source);
 +      for($i = 0; $i <count($rows); $i++) {
 +          $new_text .= sprintf("%4d",($i +1)).": ".$rows[$i]."\n"; }
 +   return $new_text;
 +    }
 +</file><sub>Joe, 2013-01-10</sub>
  
 ===== Details ===== ===== Details =====
Line 263: Line 280:
  * @author     Christopher Smith <chris@jalakai.co.uk>  * @author     Christopher Smith <chris@jalakai.co.uk>
  */  */
-if(!defined('DOKU_INC')) die();  // no DokuWiki, no go+if(!defined('DOKU_INC')) die();  // no Dokuwiki, no go
  
 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
Line 316: Line 333:
      * Handle the match      * Handle the match
      */      */
-    function handle($match, $state, $pos, &$handler){+    function handle($match, $state, $pos, Doku_Handler $handler){
       $match = trim(substr($match,7,-1));                    //strip <source from start and > from end       $match = trim(substr($match,7,-1));                    //strip <source from start and > from end
  
Line 342: Line 359:
      * Create output      * Create output
      */      */
-    function render($format, &$renderer, $data) {+    function render($format, Doku_Renderer $renderer, $data) {
  
       $this->_loadSettings();       $this->_loadSettings();
Line 474: Line 491:
 </code> </code>
  
 + --- [[user>Juergen_aus_Zuendorf|Juergen_aus_Zuendorf]] //2018-02-06 17:27//\\
 +-> Changes for compatibility to PHP7:\\
 +"&$handler" and "&$renderer" to "Doku_Handler $handler" and "Doku_Renderer $renderer"
 ==== action.php ==== ==== action.php ====
  
Line 514: Line 534:
      * plugin should use this method to register its handlers with the DokuWiki's event controller      * plugin should use this method to register its handlers with the DokuWiki's event controller
      */      */
-    function register(&$controller) {+    function register(Doku_Event_Handler $controller) {
       $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');       $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');
     }     }
Line 668: Line 688:
   div.source .code .<geshi-hilite-code> {}    div.source .code .<geshi-hilite-code> {} 
 </code> </code>
-===== Bugs ===== 
  
 +\\
 +==== Tab size ====
 +You can set the tab-size to 4 as the default, for Chrome, Firefox and Opera, using:
 +<code css>
 +div.source pre.code {
 +  tab-size: 4;
 +  -moz-tab-size: 4;
 +  -o-tab-size: 4;
 +}
 +</code>
 +===== Bugs =====
  
  
plugin/source.1251712307.txt.gz · Last modified: 2009-08-31 11:51 by ChrisS

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki