LineBreaks

Superceded

Question

How can I get PmWiki to honor line breaks (newlines) in the markup text?

Answer

In a local customization? file, add the line

    $HTMLPNewline = '<br />';

The (:linebreaks:) markup is now part of the core distribution as of 2.0.11.

Or, if you want to enable (:linebreaks:) and (:nolinebreaks:) markups to toggle between the modes, add the following:

    
    Markup('linebreaks', 'directives', 
      '/\\(:(no)?linebreaks:\\)/e',
      "PZZ(\$GLOBALS['HTMLPNewline'] = ('$1'!='no') ? '<br />' : '')");
    

Discussion

By default, PmWiki wraps consecutive lines of text into a single paragraph. For example, the markup

     one
     two
     three

gets displayed as

one two three

Making the change listed above causes PmWiki to recognize newlines as forced line breaks, so that the above markup would be displayed as:

one
two
three

Using style definitions in GroupHeader pages

If you use $HTMLPNewline = '<br />'; and style defintions in GroupHeader pages, then one or more new lines will appear at the top of each page. to avoid this enclose your style definitions in a comment division, like:

    >>comment<<
    %define=style1 ...%
    %define=style2 ...%
    %define=style3 ...%
    >><<

Notes

In PmWiki v.1 the variable was $HTMLLineBreak .

Author

  • Pm, 01-Oct-2004

Sandbox

This customization has been enabled on this page, so you can experiment with it below.


%style1%
%style2%
%style3%
(:comment xyz:)
(:comment xyz:)
(:comment xyz:)


(:linebreaks:)

Four score and seven years ago
our forefathers brought forth on this continent
a new nation
conceived in liberty
and dedicated to the proposition that all men are 
created equal.

(:nolinebreaks:)
Four score and seven years ago
our forefathers brought forth on this continent
a new nation
conceived in liberty
and dedicated to the proposition that all men are 
created equal.

Four score and seven years ago
our forefathers brought forth on this continent
a new nation
conceived in liberty
and dedicated to the proposition that all men are
created equal.

Four score and seven years ago our forefathers brought forth on this continent a new nation conceived in liberty and dedicated to the proposition that all men are created equal.