Translations of this page?:

NoNewline: no more '\\'

Nature of the problem

I would like to have your feedback about the '\\' needed to force a newline within a dokuwiki text.
I find those '\\' an aberration since they introduce a structural markup which duplicate the existing natural one, that is the linefeed (when you hit return and get back to a newline)
I have massive import of text document to do in my dokuwiki website, and I do not feel like adding all the needed '\\'… Even if it can be made automatically, it will not improve the 'native' reading of those texts (that is, the reading of a text file outside a dokuwiki html rendering).

Back in the days, such a feature might be needed in order to be able to force a 'wrap' for a very long line.
That was a way to avoid horizontal scrolling in order to read such a long line.

But today, every decent text editors support the 'true wrap' mode for long line (jedit, crimson, ultraedit, …)
A 'true wrap' mode will make your very long line automatically displayed on several lines, adjusting itself to the current width of your editor window, and considering those several physical lines as one logical line.

That topic has been raised in the FAQ and in the Help page

See the linebreak plugin. It doesn't disable \\ syntax but enables sensible replication of line breaks in the raw wiki text in the html output. Possibly some one could extend the plugin to add a configuration option making it useable on a page by page basis with ~~LINEBREAK~~ or perhaps on a namespace by namespace basis. — Christopher Smith 2006-05-25 21:54

Proposition: NONEWLINE mode

Anyway, my feeling is, the user should have a choice here, whether on the dokuwiki web site level (through an option on a local.php file), or on a page level, (through a ~~NONEWLINE~~ mode)

Without this mode, nothing changes: the dokuwiki behaves itself as it has always done:
\”a long line1 \\ end of long line 1 \\ line2\” will be displayed as
a long line1
end of long line 1
line2\”

With this \”NONEWLINE\” mode activate, the \\ are ignored (should be suppressed), and a line like:
a long line1 ends of long line1
line2
would be displayed as is, without having added '\\' anywhere

That NONEWLINE mode has no effect upon 'new paragraph' (that you create when you leave a blank line).
Leave a blank line and you will still have a new paragraphe as before.

This is a feature I am really missing. I like to see it as an Option in the main config file or as an Plugin via the new Plugin-System. I can't get familiar with ~~NONEWLINE~~ in every page. For I am not a coder I just can help with some testing(set up an testing wiki), documentation or what ever. Just drop me a note — Sebastian Koch 2005-07-15 16:47
I can only second that. I find the current solution very clumsy. I my Wiki there's a number of users who are not really tech-savvy, and they find it rather a nuisance. So I'm all for keeping it simple: there should definitely be an option to turn that off or at least a line-break button in the menu.

Implementation (proposition)

For those who want to experiment with such a mode, here is an implementation which detects a '~~NONEWLINE~~' mode within a page and inserts 'linebreak' each time the line does actually return to the line.
That means “when one type 'return' within the dokuwiki editor, the html result will display a linebreak at the end of the edited line”.
No '\\' should be used in such a page.
Reminder: for every other page that does not contain a '~~NONEWLINE~~' mode, the default behavior stands, nothing is changed, the '\\' are needed to force an linebreak.
Reminder bis: The NONEWLINE mode has no effect upon 'new paragraph' (that you create when you leave a blank line)

The following sections represent the different php files to be modified to insert this new mode.
Those are based on php sources from the latest released dokuwiki, 07.05.2005

inc\parser\handler.php

var $meta = array(
[...] 
        'nonewline' => FALSE, // <= added
[...]

add a nonewline meta flag for the Doku_Handler class.

function _finalize(){
[...] 
        if ( $this->rewriteBlocks ) {
            $B = & new Doku_Handler_Block();
            $B->$nonewline = $this->meta['nonewline']; // <= added
            $this->calls = $B->process($this->calls);
        }
[...]

When encounters a block, transfers the meta flag 'nonewline' to the Doku_Handler_Block object.
Add the following function within the Doku_Handler class:

function nonewline($match, $state, $pos) {
        $this->meta['nonewline'] = TRUE;
        $this->_addCall('nonewline',array(),$pos);
        return TRUE;
}

That function switch on the meta flag and register a nonewline function for text processing.

class Doku_Handler_Block {
[...] 
    var $inParagraph = FALSE;
    var $atStart = TRUE;
    var $nonewline = FALSE; // <= added
    var $skipEolKey = -1;
[...]

By default, a block handler has a nonewline desactivated (and will process the \\)
Now for the core of this modification:

class Doku_Handler_Block {
function process($calls) {
[...] 
            if ( !$this->atStart ) {
                if ( $call[0] == 'eol' ) {
                    # Check this isn't an eol instruction to skip...
                    if ( $this->skipEolKey != $key ) {
						//msg("A/ eol $call[2]"); 
                         # Look to see if the next instruction is an EOL
                        if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {
 
                            if ( $this->inParagraph ) {
                                $this->closeParagraph($call[2]);
                            }
 
                            $this->calls[] = array('p_open',array(), $call[2]);
                            $this->inParagraph = TRUE;
 
                            # Mark the next instruction for skipping
                            $this->skipEolKey = $key+1;
                        }else{
                                // INSERT THE FOLLOWING LINES REPLACING THE BELOW ELSE
                        	if ( $this->$nonewline && isset($calls[$key-1]) && $calls[$key-1][0] != 'linebreak' && $calls[$key-1][0] != 'nonewline' && $calls[$key-1][0] != 'eol' ) {
	                        	$this->calls[] = array('linebreak',array(), $call[2]);
				}else{
                            		$this->calls[] = array('cdata',array(" "), $call[2]);
				}
                        }
                    }
[...]

The inserted lines at the end of this code will insert a linebreak:

  • If an eol is parsed and nonewline is true
  • if it is not followed by another eol
  • if it does not follow a linebreak or an eol

then insert linebreak (rendered in xhtml as <br />), else put a space instead.

inc\parser\parser.php

add the following parser class

  class Doku_Parser_Mode_NoNewline extends Doku_Parser_Mode {
 
      function connectTo($mode) {
          $this->Lexer->addSpecialPattern('~~NONEWLINE~~',$mode,'nonewline');
      }
      function getSort() {
      return 370;
    }
  }

It register a new string to parse from a dokuwiki text: '~~NONEWLINE~~', and associates it with the mode/function 'nonewline'

// Modes where the token is simply replaced - contain no
// other modes
function Doku_Parser_Substition() {
    $modes = array(
        'acronym','smiley','wordblock','entity','camelcaselink',
        'internallink','media','externallink','linebreak','emaillink',
        'windowssharelink','filelink','notoc','nonewline','nocache','multiplyentity', // 'nonewline' added
        'quotes','rss',
    );
    return $modes;
}

Declares 'nonewline' as a to-be-replaced token.

inc\parser\renderer.php

Add the following function to the Doku_Renderer class.

class Doku_Renderer {
[...]
     function nonewline() {} // nothing to render (function added)
[...]

a default non-specialized renderer has nothing to render for this token

inc\parserutils.php

Finally,

function p_get_instructions($text){
[...]
    $Parser->addMode('notoc',new Doku_Parser_Mode_NoToc());
    $Parser->addMode('nonewline',new Doku_Parser_Mode_NoNewline()); // ADDED
    $Parser->addMode('nocache',new Doku_Parser_Mode_NoCache());
[...]

Declares the 'nonewline' mode to the local Doku_Parser

Daniel Chaffiol 02/06/2005

Discussion

OK, it worked fine for me. If you use last (2005-09-22) version of dokuwiki you must change two things:

  • in parserutils.php just add 'nonewline' in line:

$std_modes = array('listblock','preformatted','notoc','nocache', 'nonewline',

  • in parser.php

class Doku_Parser_Mode_nonewline extends Doku_Parser_Mode {
instead of
class Doku_Parser_Mode_NoNewline extends Doku_Parser_Mode {

  • When you want to use the nonewline mode, just add at the top of the page:

~~NONEWLINE~~
vincent Rioux 18/10/2005


Couldn't this solution be done as a plugin…? - Nowotny 14/11/2005
Second that! - g4b 24/10/2006
I agree with the discussion above. Non tech users find the double backslash syntax very nonintuitive. A plugin, with a switch in local.php to turn on nonewline mode would be good. PaulM 25/11/2005
Yes, yes, a plugin or option to turn on nonewline, it will be great! Thx. - Vojtec 13/1/2006

I actually prefer the way things work right now. Having to skip a line helps ensure that there is some structure to the file. Those non tech savvy people might be the ones who hit enter before the cursor gets to the end of the line when writing paragraphs (just like on an old fashioned typewriter). Then when someone with higher resolution comes along, the text becomes problematic because it only goes halfway across the screen. For example…

If I lower my screen resolution considerably, and start typing with the idea in mind
that I need to hit Enter to create a new line, the result when viewed in higher
resolution will be unacceptable.

Also, why is the double backslash any harder for users than putting ~~NONEWLINE~~ in the file?


For me, a tech savvy user, it introduces a visual deficiency to the documents that I create. Maybe I want to have something look like this:

“Samba is a free software implementation of Microsoft's networking system.”
http://en.wikipedia.org/wiki/SAMBA

As opposed to this:

“Samba is a free software implementation of Microsoft's networking system.”

http://en.wikipedia.org/wiki/SAMBA

Also, what if I want some extra spacing in there. I have to enter slashslash after slashslash? This looks fugly and unreadable in the text version.

Bottom Line: I think that an option in the local.php should be standard (not a plugin) and that ~~NONEWLINE~~ should NOT be required when the option is on -Nick Yeates 01/13/2006


Nonewline option is great! This solution worked fine for me but only on one server. On another I got error in handler.php “Cannot access empty property”. To make it work do following: after you make all changes to file handler.php change line 44 (ver.2005-09-22):

  $B->$nonewline = $this->meta['nonewline']; // <= added

to

  $B->nonewline = $this->meta['nonewline']; // <= added

and line 1386:

if ( $this->$nonewline && isset($calls[$key-1]) && $calls[$key-1][0] != 'linebreak' && $calls[$key-1][0] !=   'nonewline' && $calls[$key-1][0] != 'eol' ) {

to

if ( $this->nonewline && isset($calls[$key-1]) && $calls[$key-1][0] != 'linebreak' && $calls[$key-1][0] != 'nonewline' && $calls[$key-1][0] != 'eol' ) {

No more '\\'! ;-)


What would you think of a word processor that did nothing when you pressed the enter key? That's essentially what we have here. There was mention of non technical users possibly pressing enter at the end of every line and that they might depend on new lines for spacing that may not show up right on different resolutions. I work with the non technical people every day and I can predict what they will do when the enter key doesn't generate a new line. They will simply hold down the space bar until the cursor wraps to the next line. Now that will create a formatting nightmare.


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't make inquiry by the users?

 
wiki/discussion/nonewline.txt · Last modified: 2007/03/04 20:10 by 82.103.132.227
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate