8

By default, MediaWiki ignores single line breaks, treating them as a single space. To insert a new line in a page, you must insert two consecutive line breaks in the source, which results in a new paragraph: </p><p>. It's also possible to insert <br /> directly into the source.

How can I modify the MediaWiki parsing engine so single line breaks in the source are replaced automatically with a <br /> in the resulting HTML?

(Source: http://www.mediawiki.org/wiki/Help:Formatting)

Nemo
  • 2,441
  • 2
  • 29
  • 63
meetar
  • 7,443
  • 8
  • 42
  • 73

3 Answers3

4
<pre></pre>

This html tag seems to do the job for me.

Ryan
  • 76
  • 7
  • 1
    No, don't do this! Reason 1:
    -blocks don't appear in normal formatting but wrapped in grey boxes. Reason2: You create 
    -blocks in Mediawiki not by manually entering the tags but simply by beginning each line that should be wrapped in 
     with a single space.
    – Jpsy Sep 15 '14 at 07:02
  • 1
    My purpose is to store some useful sql scripts on wiki. And copy/paste to from Sql Server or a text editor must be instant. No way I am going to insert html tags one way and remove them the other. And I don't want to install a poetic extension. Surrounding my code with
     looks good and I don't care about the text being displayed in a box.
    – pasx Dec 05 '14 at 00:01
3

Use https://www.mediawiki.org/wiki/Extension:Poem

<poem>
Roses are red
Violets are blue
</poem>
MaxSem
  • 3,457
  • 21
  • 34
2

You could write an extension that adds br tags to newlines when parsing the wikicode. However, you'd have to be very careful - you don't want every newline in the wikicode to actually be a br tag, do you?

Edit: you don't want every newline to be a br tag, because not every newline in the wikicode should actually be a linebreak. For example, a table:

{|
|+ The table's caption
|-
|Cell 1
|Cell 2
|-
|Cell A
|Cell B
|}

It would turn quite messy if you added br tags into the table code.