How can I force MediaWiki to respect single line breaks?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 10:57:02

问题


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)


回答1:


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

<poem>
Roses are red
Violets are blue
</poem>



回答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.




回答3:


<pre></pre>

This html tag seems to do the job for me.



来源:https://stackoverflow.com/questions/10375821/how-can-i-force-mediawiki-to-respect-single-line-breaks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!