plugin:linebreak
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
plugin:linebreak [2009-01-02 23:30] – 70.103.232.219 | plugin:linebreak [2018-06-04 23:00] (current) – Klap-in | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== linebreak Plugin ====== | ||
+ | ---- plugin ---- | ||
+ | description: | ||
+ | author | ||
+ | email : chris@jalakai.co.uk | ||
+ | type : syntax, action | ||
+ | lastupdate : 2007-01-20 | ||
+ | compatible : Weatherwax | ||
+ | depends | ||
+ | conflicts | ||
+ | similar | ||
+ | tags : typography, !experimental | ||
+ | downloadurl: | ||
+ | ---- | ||
+ | |||
+ | [[: | ||
+ | |||
+ | **Use [[plugin: | ||
+ | Linebreak is a hack from the time before render plugins were possible.\\ | ||
+ | Its reported not to work (at least in some wikis) with the latest version of DokuWiki. | ||
+ | \\ | ||
+ | - [[http:// | ||
+ | (author of both xbr and linebreak plugins)** | ||
+ | |||
+ | |||
+ | ^ :!: | Packages updated to include functions missing from 2006-03-09 DokuWiki. | ||
+ | |||
+ | This [[:plugin]] changes the way DokuWiki treats single line break in the raw wiki text - instead of the default behaviour, where the line break is absorbed, it will generate a line break in the HTML output. | ||
+ | |||
+ | This plugin maybe useful for wiki pages which include poetry, song lyrics or other content which is naturally written with meaningful single line breaks. | ||
+ | |||
+ | ===== Syntax ===== | ||
+ | |||
+ | The plugin will recognize single line breaks in the wiki page. | ||
+ | |||
+ | The plugin also supports two directives which can turn on and turn off generation of line breaks in the output HTML. | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Installation ===== | ||
+ | Search and install the plugin using the [[plugin: | ||
+ | |||
+ | Plugin sources: | ||
+ | * for DokuWiki rc2006-09-28 and later --- [[http:// | ||
+ | * for DokuWiki 2006-03-09 --- [[http:// | ||
+ | * for DokuWiki development version --- [[http:// | ||
+ | |||
+ | |||
+ | |||
+ | ===== Configuration ===== | ||
+ | |||
+ | The plugin has two configuration settings: | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | You can override the default values by either modifying '' | ||
+ | |||
+ | $conf[' | ||
+ | |||
+ | Depending on your DokuWiki version you may be able to edit these settings from within the '' | ||
+ | |||
+ | ===== Details ===== | ||
+ | |||
+ | The plugin consists of five files, only the plugin scripts, [[# | ||
+ | |||
+ | ==== syntax.php ==== | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Plugin Linebreak: Inserts a line break | ||
+ | | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | // must be run within Dokuwiki | ||
+ | if(!defined(' | ||
+ | |||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_linebreak extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | var $no_quotes = array(300, ' | ||
+ | var $in_quotes = array(100, ' | ||
+ | # var $no_quotes = array(300, ' | ||
+ | # var $in_quotes = array(100, ' | ||
+ | var $ptn_pageon = ' | ||
+ | var $ptn_pageoff = ' | ||
+ | |||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | function getType() { return ' | ||
+ | function getSort() { return ($this-> | ||
+ | function connectTo($mode) { | ||
+ | |||
+ | $ptn = $this-> | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | function handle($match, | ||
+ | |||
+ | if (substr($match, | ||
+ | $marker = substr($match, | ||
+ | return array(' | ||
+ | } | ||
+ | |||
+ | if (!isset($handler-> | ||
+ | $handler-> | ||
+ | } | ||
+ | |||
+ | if ($match == " | ||
+ | |||
+ | if ($match == $this-> | ||
+ | $handler-> | ||
+ | } else if ($match == $this-> | ||
+ | $handler-> | ||
+ | } | ||
+ | |||
+ | return array(false); | ||
+ | } | ||
+ | |||
+ | function render($mode, | ||
+ | |||
+ | if($mode == ' | ||
+ | if ($data[0]) $renderer-> | ||
+ | return true; | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== action.php ==== | ||
+ | |||
+ | **Note** This file is not present in the version of the plugin for DokuWiki release 2006-03-xx. | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * Plugin Linebreak: Inserts a line break | ||
+ | | ||
+ | * @license | ||
+ | * @author | ||
+ | */ | ||
+ | |||
+ | // must be run within Dokuwiki | ||
+ | if(!defined(' | ||
+ | |||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class action_plugin_linebreak extends DokuWiki_Action_Plugin { | ||
+ | |||
+ | var $marker_id = 0; | ||
+ | var $linebreak_conversions = array(); | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * plugin should use this method to register its handlers with the DokuWiki' | ||
+ | */ | ||
+ | function register(Doku_Event_Handler $controller) { | ||
+ | $controller-> | ||
+ | $controller-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * add spaces before line breaks, required so syntax component pattern will match correctly | ||
+ | * record the offset changes so we can fix up the section edit offsets later | ||
+ | */ | ||
+ | function _addspaces(& | ||
+ | |||
+ | // preg pattern used to find line breaks which require spaces inserted before them | ||
+ | $pattern = '/ | ||
+ | |||
+ | // marker to add at the start of the raw wiki data, it contains an id we use to access the location | ||
+ | // of the additional spaces added into the file | ||
+ | $marker = " | ||
+ | |||
+ | // get the location (offset) of all the spaces to be added | ||
+ | $linebreaks = array(); | ||
+ | preg_match_all($pattern, | ||
+ | |||
+ | for ($i=0; $i< | ||
+ | $conversion[] = $linebreaks[0][$i][1]; | ||
+ | } | ||
+ | |||
+ | // save details of the added spaces | ||
+ | $this-> | ||
+ | |||
+ | // add in the spaces | ||
+ | $event-> | ||
+ | |||
+ | // update the marker id so that the next use gets a fresh id. | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | function _fixsecedit(& | ||
+ | |||
+ | // find our linebreak marker instruction and get the marker id | ||
+ | $calls =& $event-> | ||
+ | $marker = null; | ||
+ | |||
+ | for ($i=0; $i < count($calls); | ||
+ | if ($calls[$i][0] == ' | ||
+ | $marker = $calls[$i][1][1][' | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (is_null($marker)) return; | ||
+ | |||
+ | // calculate the amount added to the start of the raw wiki data for our marker tag | ||
+ | $this-> | ||
+ | $this-> | ||
+ | |||
+ | // iterate through the instruction list and set the file offset values (usually the $pos variable) | ||
+ | // back to the values they would be if no spaces had been added by this plugin | ||
+ | for ($i=0; $i < count($calls); | ||
+ | if ($calls[$i][0] == ' | ||
+ | $calls[$i][1][0] = $this-> | ||
+ | $calls[$i][1][1] = $this-> | ||
+ | $calls[$i][2] = $this-> | ||
+ | } else { | ||
+ | // $calls[$i][2] = $this-> | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | | ||
+ | */ | ||
+ | function _convert($pos) { | ||
+ | global $debug; | ||
+ | |||
+ | // file start values will still be file start values - don't change them | ||
+ | if ($pos <= 1) return $pos; | ||
+ | |||
+ | $pos -= $this-> | ||
+ | if ($pos < 0) return 0; | ||
+ | |||
+ | // simplify access to the conversion data | ||
+ | $conversion =& $this-> | ||
+ | |||
+ | for ($i=0; $i< | ||
+ | // the conversion contains the original source position | ||
+ | // we need to add in the modifications up to that point and compare against $pos | ||
+ | // remembering we have already modified $pos for the marker string we added first | ||
+ | if ($conversion[$i] + $i >= $pos) { | ||
+ | return $pos - $i; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // $i will be one more than the number of modifications made | ||
+ | return $pos - $i -1; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 :} | ||
+ | </ | ||
+ | |||
+ | ===== Revision History ===== | ||
+ | |||
+ | * 2007-02-18 | ||
+ | * Fix problems with wiki pages which don't end with a new line. | ||
+ | * Efficiency improvements, | ||
+ | * 2007-01-20 --- Fix problems with section editing | ||
+ | * 2006-06-09 --- Package updated to match DokuWiki release version | ||
+ | * '' | ||
+ | * darcs version released (as previous version, i.e., without '' | ||
+ | * 2006-05-26 --- Updated | ||
+ | * Configuration settings added, see [[# | ||
+ | * '' | ||
+ | * Pattern modified to avoid clashing with quotes and to recognize line breaks within quotes. | ||
+ | * 2006-05-25 --- Released. | ||
+ | |||
+ | |||
+ | ===== To Do ===== | ||
+ | |||
+ | |||
+ | |||
+ | ===== Bugs ===== | ||
+ | |||
+ | :!: Often, when I have the plugin installed: pages will not load, and I get this error: | ||
+ | |||
+ | < | ||
+ | Fatal error: Maximum execution time of 30 seconds exceeded in / | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | Fatal error: Maximum execution time of 30 seconds exceeded in / | ||
+ | </ | ||
+ | |||
+ | It may have to do with the size of the file. It seem to choke of files over 1300 lines. | ||
+ | |||
+ | ---- | ||
+ | * Plugin works mostly fine for me, but lines don't break when they end with a markup symbol, For example: < | ||
+ | and this is another.</ | ||
+ | |||
+ | >> Its an unfortunate side-effect of the way the DokuWiki syntax engine works. | ||
+ | |||
+ | >>> | ||
+ | |||
+ | >>>> | ||
+ | |||
+ | * After I updated DokuWiki from 2006-03 to 2006-11 (latest version), linebreak (version 2006-10-18) began to destroy my editing: Every time I tried to edit a section, the beginning and the ending was not recognized and broke (something inserted linebreaks at the beginning and the ending, inside of headings.) I had to erase the plugin (and now its fine again). I miss it... Will there be an update? --- // | ||
+ | |||
+ | > Yes. For now, you can either stick to using "Edit Page" rather than "edit section" | ||
+ | |||
+ | >> :!: This problem is now fixed --- // | ||
+ | |||
+ | * In normal pages this linebreak plugin (version 2007-01-20) does exactly what I want. But after a while I realized that some pages don't work. I first thought that Esthers discussion plugin or some other may be faulty, but after deactivating several plugins in the plugin manager I was able to find the plugin that doesn' | ||
+ | |||
+ | > The work around is to make sure there is a line break at the end of your page. I'll look into the cause and release a fix asap. --- // | ||
+ | >> Fix is a simple change to the pattern used by the action component. I have updated source packages and darcs release. | ||
+ | >>> | ||
+ | >>>> | ||
+ | >>>>> | ||
+ | |||
+ | * Just installed this plug-in (from 2007-01-20), | ||
+ | * I've noticed that a line break doesn' | ||
+ | |||
+ | * This is not a real bug, but a feature request. Is it possible to extend the plug-in for double line new paragraphs? I mean when I press 3 enter after a sentence, there will be two empty line in the edit window, but only one in the wiki page. Now I have to do this to get a double empty line in the wiki:< | ||
+ | |||
+ | \\ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | IMO: DokuWiki should treat linebreaks as linebreaks, and not require a %%\\%% for a linebreak. | ||
+ | |||
+ | - requiring a %%\\%% makes it more difficult to move text files into DokuWiki | ||
+ | - the source text file looks ugly, cluttered, and unnatural | ||
+ | - requiring an invisible character at the end of the %%\\%% means I can not just look at my source text file and tell if there is line break or not. | ||
+ | |||
+ | That said, the I don't know if integrating this plugin would be the best solution. In my experience, this plugin causing longer pages to not load. | ||
+ | |||
+ | > Take a look at [[plugin: | ||
+ | |||
+ | >> I can not figure out how to use or install the xbr plugin. | ||
+ | >> IMO: the xbr plugin is critically short of basic instruction. A link to the plugin page does not constitute proper documentation. | ||
+ | >> For example, where does the code specified in the xbr plugin go? / | ||
+ | >> How do I change the configuration manager so that I can change the renderer_xhtml settings in the configuration file? I suppose I have to edit the canRender() function, but which file? Which directory? | ||
+ | >> I feel like I would have to second guess, and hit-or-miss every step of the way. This is just too difficult to be worth it. | ||
+ | |||
+ | >>> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | I vote for integration of the plugin into DokuWiki! --- // | ||
+ | |||
+ | |||
+ | ---- | ||
+ | I find the text syntax of DokuWiki very well, better than Wikipedia. | ||
+ | The only thing witch is really ugly is the linebreak handling. Something so basic should a option in the main code and no plugin should by necessarily for this. | ||
+ | Why doesn' | ||
+ | |||
+ | ---- | ||
+ | Agree, single linebreak in //source code// should generate a linebreak in HTML result. | ||
+ | |||
+ | ---- | ||
+ | Agree even more ... my favorite behavior would be to have the described linebreaks for every inserted linebreak and use %%\\%% to turn them off ;) | ||
+ | ---- | ||
+ | This broke several other plugins for me (code replacement 2, footnote, etc.). Additionally, | ||
+ | ---- | ||
+ | Agree, because a plugin never gets the same support like the main code, and problems with updates, incompatibilities and other plugins are possible. And destruction of source text is a very bad effect. (i had problems with linebreak and had to deactivate it. I use now a patch witch change the main code, and had never problems anymore). 20-12-2007 | ||
+ | ---- | ||
+ | Agree, please include in main code -- GB 10-01-08 | ||
+ | ---- | ||
+ | Its always my first plugin in all DokuWiki installations :) -- sw 10-02-08 | ||
+ | ---- | ||
+ | +1 to include in main code -- VR 06-04-08 | ||
+ | ---- | ||
+ | Just installed it... LOVE IT, no more backslash backslash space (however, it will take some time to get it out of my system ;-) ) 29-07-2008 MvD | ||
+ | ---- | ||
+ | Another vote to include in the main code and/or make it a configuration setting. | ||
+ | |||
+ | ---- | ||
+ | 11-09-10 | ||
+ | Linebreak plug-in was working very well until I installed the latest version. | ||
+ | |||
+ | Now when pressing ' | ||
+ | |||
+ | How can I bring into same effect as linebreak is on, NOT using \\ ? | ||
+ | |||
+ | example. | ||
+ | |||
+ | **Source** | ||
+ | < | ||
+ | ====== test ====== | ||
+ | |||
+ | Hello, world. | ||
+ | |||
+ | ====== temp ====== | ||
+ | </ | ||
+ | |||
+ | |||
+ | **clicking middle edit button** | ||
+ | < | ||
+ | |||
+ | == | ||
+ | |||
+ | Hello, world. | ||
+ | |||
+ | ====== temp ===== | ||
+ | </ |