Jump to content

扩展:Poem

From mediawiki.org
This page is a translated version of the page Extension:Poem and the translation is 89% complete.
此扩展随附于MediaWiki 1.21及更新版本,因此您無需下載它。 但其余的配置的指示仍须依循執行。
MediaWiki扩展手册
Poem
发行状态: 稳定版
实现 标签
描述 添加‎<poem>标签用于格式化诗歌
作者 Nikola Smolenski留言
最新版本 持续更新
MediaWiki 1.25+
数据库更改
‎<poem>
许可证 Creative Commons Zero v1.0 Universal
下載
前往translatewiki.net翻譯Poem扩展
問題 开启的任务 · 报告错误

Poem扩展允许在Wiki文本中轻松格式化诗歌或类似的文段。 一旦该扩展被开启,您可以将任何文本段落放在‎<poem>‎</poem>标签内,这将导致以下效果:

  • 所有的换行符都会保留,它们将会转换为‎<br />标签
  • 文本块包含在‎<p>...‎</p>标签中(以及一个带有“poem”类的div标签)
  • 行首的冒号转换为1em的缩进
  • 保留行首的空格,不再调用‎<pre>标签

若poem中存在维基链接、加粗等格式,该扩展程序将予以保留。

用法

Wikisource provides the best usage model for this extension. It uses several templates and a module to create indentation, line numbers, etc. See Wikisource:Help:Poetry for an explanation of how this is used there. This requires Extension:Scribunto and Extension:TemplateStyles, which are both now bundled as standard.

示例

输入文本 输出
<poem>
In [[Wikipedia:Xanadu|Xanadu]] did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.

So twice five miles of fertile ground
With walls and towers were girdled round:
And there were gardens bright with sinuous rills,
Where blossomed many an incense-bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.
</poem>

In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.

So twice five miles of fertile ground
With walls and towers were girdled round:
And there were gardens bright with sinuous rills,
Where blossomed many an incense-bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.

带有缩进的例子

输入文本 输出
<poem>
Une terre au flanc maigre, âpre, avare, inclément
Où les vivants pensifs travaillent tristement, 
::Et qui donne à regret à cette race humaine
Un peu de pain pour tant de labeur et de peine ; 
::Des hommes durs, éclos sur ces sillons ingrats ; 
Des cités d’où s’en vont, en se tordant les bras, 
::La charité, la paix, la foi, sœurs vénérables ; 
L’orgueil chez les puissants et chez les misérables ; 
</poem>

Une terre au flanc maigre, âpre, avare, inclément
Où les vivants pensifs travaillent tristement,
Et qui donne à regret à cette race humaine
Un peu de pain pour tant de labeur et de peine ;
Des hommes durs, éclos sur ces sillons ingrats ;
Des cités d’où s’en vont, en se tordant les bras,
La charité, la paix, la foi, sœurs vénérables ;
L’orgueil chez les puissants et chez les misérables ;

Style

poem文本包裹在一个默认无样式的div中,但会继承传递给poem的任何styleclass选项。

例如,虽然缩进文本可用于简单示例以防止填充并绘制漂亮的蓝色框,但在某些情况下可能难以阅读,因为长行不会被换行。 类似但效果稍佳的方法可采用:

<poem style="border: 2px solid #d6d2c5; color: var(--color-base, #202122); background-color: var(--background-color-warning-subtle, #fdf2d5); padding: 1em;">

应用于上述示例时,结果如下:

In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.

So twice five miles of fertile ground
With walls and towers were girdled round:
And there were gardens bright with sinuous rills,
Where blossomed many an incense-bearing tree;
And here were forests ancient as the hills,
Enfolding sunny spots of greenery.


"compact" 选项

对超过两行的文本应用带有compact选项的‎<poem>标签时,每一行都会成为独立的段落。 (也就是说,它允许更简洁的标记,而非更紧凑的输出结果。)

随后使用‎<poem>标签与compact选项(中间最多有两个换行符),在文本之间只会产生单个换行,而不会形成新的段落。

因此,当应用于每段超过两行的文本时,除每段末行与下一段首行会合并为一个段落外,其余每行均自成独立段落。

输入 输出 输入 输出
<poem>
One,
Two.
</poem>
<poem>
Three?
Four!
</poem>

One,
Two.

Three?
Four!

<poem compact>
One,
Two.
</poem>
<poem compact>
Three?
Four!
</poem>
One,
Two.
Three?
Four!
输入 输出 输入 输出
<poem>
One,
Two.
Extra.
</poem>
<poem>
Three?
Four!
Extra.
</poem>

One,
Two.
Extra.

Three?
Four!
Extra.

<poem compact>
One,
Two.
Extra.
</poem>
<poem compact>
Three?
Four!
Extra.
</poem>
One,

Two.

Extra.
Three?

Four!

Extra.

Problems and solutions

  • Variables和ParserFunctions在‎<poem>...‎</poem>容器内有效,但在<poem ... >标签本身内部无效;这样可以防止模板中出现类似<poem style="{{{1}}}">的代码。
  • One workaround is to use <div style="{{{1}}}"><poem> ... </poem></div> instead.
  • Another way is to use the #tag magic word: {{#tag:poem| ... |style="{{{1}}}"}}.
    • NB: this would however seem not to work with the "compact" option.
输入(标签内正常,标签中不正常) 输出
<poem style="{{{1|border: 1px solid Black;}}}">
One,
{{{2|Two.}}}
</poem>

One,
Two.

输入(标签内和标签中都正常) 输出
<div style="{{{1|border: 1px solid Black;}}}">
<poem>
One,
{{{2|Two.}}}
</poem>
</div>

One,
Two.

{{#tag:poem|
One,
{{{2|Two.}}}
|style="{{{1|border: 1px solid Black;}}}"
}}

One,
Two.


安装

此扩展随附于MediaWiki 1.21及更新版本,因此您無需下載它。 但其余的配置的指示仍须依循執行。
  • 下载文件,并解压Poem文件夹到extensions/目录中。
    开发者和代码贡献人员应改从Git安装此扩展,输入:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Poem
    
  • 請新增下列代码到您的LocalSettings.php 文件的底部:
    wfLoadExtension( 'Poem' );
    
  • Yes 完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。


使用Vagrant安装:

  • 如果你有使用Vagrant ,请通过vagrant roles enable poem --provision安装