`
alienj
  • 浏览: 77417 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

第17章. Seam文本

阅读更多

17. Seam文本

面向协作站点需要一种更有友好的标记语言,容易输入在论坛帖子、 wiki页面、博客和评论等中的格式化文本。Seam提供了<s:formattedText/>控件,显示符合Seam 文本语言的格式化文本。Seam文本用基于ANTLR ANother Tool for Language Recognition)解析器实现。然而,你不必了解任何与使用ANTLR有关的东西。

[有关ANTLR 问题请参考http://www.antlr.org/wiki/display/ANTLR3/FAQ+-+Getting+Started]

17.1. 基本格式

这里是一个简单例子:

It's easy to make *emphasis*, |monospace|,

~deleted text~, super^scripts^ or _underlines_.

 

如果我们使用 <s:formattedText/>显示这些, 我们会得到下面的HTML结果:

 

<p>
It's easy to make <i>emphasis</i>, <tt>monospace</tt>
<
del>deleted text</del
>, super<sup>scripts</sup> or <u>underlines</u>.
</p>

我们能使用一个空行显示一个新段,并且用+显示一个标题:

 

+This is a big heading

You /must/ have some text following a heading!

 

++This is a smaller heading

This is the first paragraph. We can split it across multiple

lines, but we must end it with a blank line.

 

This is the second paragraph.

(注意:一个简单的换行符被忽略,你需要一个另外的空行,裹包着文本成为一个新段落。) 这是HTML结果:

 

<h1>This is a big heading</h1>


<p>

You <i>must</i> have some text following a heading!

</p>

 

 <h2>This is a smaller heading</h2>

 

<p>

This is the first paragraph. We can split it across multiple 

lines, but we must end it with a blank line.

</p>

 

<p>

This is the second paragraph.

</p>

有序列表使用#字符创建。无序列表使用=字符创建:

 

An ordered list:       

#first item

#second item

#and even the /third/ item

 

An unordered list:

=an item

=another item

 

HTML结果:

 

<p>
An ordered list:
</p>

<ol>       
<li>first item</li>
<li>second item</li>
<li>and even the <i>third</i> item</li>
</ol>

<p>
An unordered list:
</p>

<ul>
<li>an item</li>
<li>another item</li>
</ul>

引用部分应该用双引号括起来:

 

The other guy said:    

"Nyeah nyeah-nee

/nyeah/ nyeah!"

 

But what do you think he means by "nyeah-nee"?

 

<p>
The other guy said:
</p>

 

<q>Nyeah nyeah-nee
<i>nyeah</i> nyeah!</q>

<p>
But what do you think he means by <q>nyeah-nee</q>?
</p>

17.2. 输入带特殊字符的代码和文本

*| #等特殊符号,以及象<> &HTML字符可以使用\转义:

 

You can write down equations like 2\*3\=6 and HTML tags

like \<body\> using the escape character: \\.

 

HTML结果:

<p>
You can write down equations like 2*3=6 and HTML tags
like &lt;body&gt; using the escape character: \.
</p>

并且我们能使用倒引号引用代码块:

 

My code doesn't work:

 

`for (int i=0; i<100; i--)

{

    doSomething();

}`

 

Any ideas?

 

结果:

 

<p>
My code doesn't work:
</p>

<pre>for (int i=0; i&lt;100; i--)
{
    doSomething();
}</pre>

<p>
Any ideas?
</p>

注意:内置的单间隔格式总被转义(大多数单间隔格式文本实事上是带有特殊字符的代码或标签)。所以,你能编写,例子:

 

This is a |<tag attribute="value"/>| example.

 

没有转义单间隔条内部的任何字符。缺点是你不能用任何其它方法来格式化内置的单间隔文本(斜体、下划线等等)。

17.3. 链接

使用下面语法创建一个链接:

 

Go to the Seam website at [=>http://jboss.com/products/seam].

 

或者,如果想指定链接文本:

 

Go to [the Seam website=>http://jboss.com/products/seam].

 

对高级用户,甚至自定义Seam文本解析器理解使用这种语法编写的wikiword链接是可能的。

17.4. 输入HTML

文本甚至可能包括HTML的某些有限子集(不要担心,选择的子集在跨站点脚本攻击下是安全的)。这对创建链接是有用的:

 

You might want to link to <a href="http://jboss.com/products/seam">something cool</a>, or even include an image: <img src="/logo.jpg"/>

以及创建表:

<table>
    <tr><td>First name:</td><td>Gavin</td></tr>
    <tr><td>Last name:</td><td>King</td></tr>
</table>

然而,如果你想,你能做更多的事。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics