|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +category : 轻量级标记语言 |
| 4 | +tagline: "Textile" |
| 5 | +tags : [Textile,test] |
| 6 | +--- |
| 7 | + |
| 8 | + |
| 9 | +Textile会在你的文档中寻找段落,就是html中的 @<p>@ 标签,段落由一个独立的空行分隔。 |
| 10 | +<pre><code>第一段 |
| 11 | + |
| 12 | +第二段</code></pre> |
| 13 | + |
| 14 | +会生成对应的html为 |
| 15 | + |
| 16 | +<pre><code><p>第一段</p> |
| 17 | + |
| 18 | +<p>第二段</p></code></pre> |
| 19 | + |
| 20 | +你也可以直接使用html的标记在你的texile文档中。使用 *pre* 或者 *code* 标签可以避免里面的内容被转义。 |
| 21 | + |
| 22 | +所有换行符会被解析为html中的换行符,注意不是 *br* 而是文本的换行。 |
| 23 | + |
| 24 | +"双引号"或者'单引号' 会直接被作为实体解析,对应html代码为:<code>“双引号”或者‘单引号’</code> 。 |
| 25 | + |
| 26 | +还有一些实体: @--、-、...、x、(TM)、(R)、(C)@ 就不一一介绍了,作为playtime吧。 |
| 27 | + |
| 28 | +@hn.@ 对应html中的hn,其中n从1-6。注意 *hn.* 后面有一个空格,比如文中的标题就是如此生成的。 |
| 29 | + |
| 30 | +@bq.@ 代表html中的 @<blockquote>@ 。 |
| 31 | + |
| 32 | +想写脚注非常简单,这是脚注f[1],其实就是在你要脚注的位置用 @[@ 和 @]@ 之间加一个数字,如这里的 @[1]@ 。 |
| 33 | + |
| 34 | +fn1. www.baidu.com |
| 35 | + |
| 36 | +那么对应的脚注链接地址,可以这么设置 @fn1. 这是脚注一对应的地址@ ,这里注意要新起一个段落。 |
| 37 | + |
| 38 | +**这是发现一个textile的bug,就是如果以中文或者.结尾加上[1]是没有反应的。** |
| 39 | + |
| 40 | +@_word_@ 会对应 @<em>word</em>@ ,这是效果: _word_ |
| 41 | + |
| 42 | +@__word__@ 对应 @<i>word</i>@ ,这是效果: __word__ |
| 43 | + |
| 44 | +@*@ 对应 @<strong>@ , 这是效果: *word* |
| 45 | + |
| 46 | +@**@ 对应 @<b>@ , 这是效果: **word** |
| 47 | + |
| 48 | +@??@ 对应 @<cite>@ , 这是效果: ??word?? |
| 49 | + |
| 50 | +这是分别的效果 *word* **word** ??word?? |
| 51 | + |
| 52 | +这里我发现一个小技巧就是 @****@ 代表一个 @<hr />@ |
| 53 | + |
| 54 | +这是效果 **** 有下划线么?好像没有。 |
| 55 | + |
| 56 | +对于 *code* 这个html标签来说,在textile里可以简单的用两个@包起来 |
| 57 | + |
| 58 | +@-word-@ 对应 @<del>word</del>@ ,这是效果: -word- |
| 59 | + |
| 60 | +@+word+@ 对应 @<ins>word</ins>@ ,这是效果: +word+ |
| 61 | + |
| 62 | +这个比较好玩: @a ^2^ + b ^2^ = c ^2^@ ,这是效果: a ^2^ + b ^2^ = c ^2^ |
| 63 | + |
| 64 | +这里有一个小bug被发现,就是我用的是RedCloth 3.0.4,对于处理 @a^2^ + b^2^ = c^2^@ 会出现混乱 |
| 65 | + |
| 66 | +解决方法很简单就是用它的3.0.3,因为我看到README中说3.0.3是稳定的,但不知为什么2005年就发布的3.0.4有问题。有时间我再研究下它的代码。 |
| 67 | + |
| 68 | +<pre><code>#!ruby |
| 69 | +require 'rubygems' |
| 70 | +gem 'RedCloth', '=3.0.3' |
| 71 | +require 'redcloth' |
| 72 | + |
| 73 | +textiletext = $<.read |
| 74 | + |
| 75 | +r = RedCloth.new(textiletext) |
| 76 | + |
| 77 | +File.open('a.html', 'w') do |f| |
| 78 | +f.puts r.to_html |
| 79 | +end</code></pre> |
| 80 | + |
| 81 | +你这样来强制使用3.0.3,这里注意 *gem* 已经取代了原来的 *require_gem* |
| 82 | + |
| 83 | +@log ~2~ x@ 那么你就会得到 log ~2~ x |
| 84 | + |
| 85 | +@%word%@ 对应 @<span>word</span>@ ,你甚至可以施以魔法 @%{color:red}word%@ ,这是效果: %{color:red}word% |
| 86 | + |
| 87 | +你可以给任意的标记加上CSS属性,这样你就可以施加更多的魔法了。 |
| 88 | + |
| 89 | +如 @p(example1). An example@ 、 @p(#big-red). Red here@ ,设置class和id一起用 @p(example1#big-red2). Red here@ |
| 90 | + |
| 91 | +你也可以直接写css style里的东西,像这样 @p{color:blue;margin:30px}. Spacey blue@ |
| 92 | + |
| 93 | +@p[ruby]. your code@ 这样会生成语言相关的标签。 |
| 94 | + |
| 95 | +上面上面的代码会被解释成这样的html |
| 96 | + |
| 97 | +<pre><code><p class="example1">An example</p> |
| 98 | +<p id="big-red">Red here</p> |
| 99 | +<p class="example1" id="big-red2">Red here</p> |
| 100 | +<p style="color:blue; margin:30px;">Spacey blue</p> |
| 101 | +<p lang="ruby">your code</p></code></pre> |
| 102 | + |
| 103 | +如果想快速的地位你的区块,可以使用 @<. >. =. <>.@ ,它们分别对应text-align: left right center justify |
| 104 | + |
| 105 | +@(. ((. (((. ))).@ 有左或者右缩进的效果 |
| 106 | + |
| 107 | +使用html的pre内包code标签可以实现贴代码的效果,我这里的大区域,里面有代码的就是这样实现的。 |
| 108 | + |
| 109 | +<pre><code><div style="float:right;"> |
| 110 | + |
| 111 | +h3. 右边导航 |
| 112 | + |
| 113 | +"HuJinpu":http://hujinpu.net/ |
| 114 | +"Feed Me":http://feed.hujinpu.net/ |
| 115 | + |
| 116 | +</div> |
| 117 | + |
| 118 | +你要写的内容</code></pre> |
| 119 | + |
| 120 | +效果如下: |
| 121 | + |
| 122 | +<div style="float:right;"> |
| 123 | + |
| 124 | +h3. 右边导航 |
| 125 | + |
| 126 | +"HuJinpu":http://hujinpu.net/ |
| 127 | +"Feed Me":http://feed.hujinpu.net/ |
| 128 | + |
| 129 | +</div> |
| 130 | + |
| 131 | +你要写的内容 |
| 132 | + |
| 133 | +你要写的内容 |
| 134 | + |
| 135 | +你要写的内容 |
| 136 | + |
| 137 | +你要写的内容 |
| 138 | + |
| 139 | +<pre><code># A first item |
| 140 | +# A second item |
| 141 | +# A third</code></pre> |
| 142 | + |
| 143 | +生成带数字的列表,效果如下: |
| 144 | + |
| 145 | +# A first item |
| 146 | +# A second item |
| 147 | +# A third |
| 148 | + |
| 149 | +增加#的数目就可以产生内嵌的数字列表 |
| 150 | + |
| 151 | +@* your list item@ 可以实现带符号的列表,也叫bulleted list。当然如果 @*@ 数目增加也可以实现内嵌。看效果: |
| 152 | + |
| 153 | +* outter1 |
| 154 | +** inner11 |
| 155 | +*** inner111 |
| 156 | +** inner12 |
| 157 | +** inner13 |
| 158 | +* outter2 |
| 159 | +** inner21 |
| 160 | +** inner22 |
| 161 | + |
| 162 | +# outter1 |
| 163 | +## inner11 |
| 164 | +### 我是非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长非常长的一句话 |
| 165 | +## inner12 |
| 166 | +## inner13 |
| 167 | +# outter2 |
| 168 | +## inner21 |
| 169 | +## inner22 |
| 170 | + |
| 171 | +插入链接也很简单:<code>"my blog":http://hujinpu.net</code> ,效果: "my blog":http://hujinpu.net |
| 172 | +注意这里也发现一个bug,就是<code>@</code>符号包住的链接不会被正确显示里面的代码,这里我是用 **code** 标签做的 |
| 173 | + |
| 174 | +如果有很多相同链接,就可以定义链接别名: |
| 175 | + |
| 176 | +<pre><code>I am "HuJinpu":hujinpu |
| 177 | +and "it's":hujinpu "all":hujinpu I ever |
| 178 | +"link to":hujinpu! |
| 179 | + |
| 180 | +[hujinpu]http://hujinpu.net</code></pre> |
| 181 | + |
| 182 | +效果: |
| 183 | + |
| 184 | +I am "HuJinpu":hujinpu |
| 185 | +and "it's":hujinpu "all":hujinpu I ever |
| 186 | +"link to":hujinpu! |
| 187 | + |
| 188 | +[hujinpu]http://hujinpu.net |
| 189 | + |
| 190 | +<pre><code>!your_image_url(your_title)!</code></pre>在两个!中间的是你的图片地址,还可以加上title |
| 191 | + |
| 192 | +<pre><code>!http://www.blogbus.com/profile/6/1/1/4328116/avatar_4328116_96.jpg(狄仁杰)!:http://hujinpu.net/</code></pre>这是联合使用链接和图片,注意 @>. <.@ b等位移符号也可以用于图片 |
| 193 | + |
| 194 | +效果: |
| 195 | + |
| 196 | +!http://www.blogbus.com/profile/6/1/1/4328116/avatar_4328116_96.jpg(狄仁杰)!:http://hujinpu.net/ |
| 197 | + |
| 198 | +<pre><code>| name | age | sex | |
| 199 | +| joan | 24 | f | |
| 200 | +| archie | 29 | m | |
| 201 | +| bella | 45 | f |</code></pre> |
| 202 | + |
| 203 | +这是最简单的表格 |
| 204 | +看效果: |
| 205 | + |
| 206 | +| name | age | sex | |
| 207 | +| joan | 24 | f | |
| 208 | +| archie | 29 | m | |
| 209 | +| bella | 45 | f | |
| 210 | + |
| 211 | +会生成对应的html |
| 212 | + |
| 213 | +<pre><code><table> |
| 214 | + <tr> |
| 215 | + <td> name </td> |
| 216 | + <td> age </td> |
| 217 | + <td> sex </td> |
| 218 | + </tr> |
| 219 | + <tr> |
| 220 | + <td> joan </td> |
| 221 | + <td> 24 </td> |
| 222 | + <td> f </td> |
| 223 | + </tr> |
| 224 | + <tr> |
| 225 | + <td> archie </td> |
| 226 | + <td> 29 </td> |
| 227 | + <td> m </td> |
| 228 | + </tr> |
| 229 | + <tr> |
| 230 | + <td> bella </td> |
| 231 | + <td> 45 </td> |
| 232 | + <td> f </td> |
| 233 | + </tr> |
| 234 | +</table></code></pre> |
| 235 | + |
| 236 | +这是一个复杂的表格实例,你可以看到表格的各种变化 |
| 237 | + |
| 238 | +<pre><code>|_. attribute list | |
| 239 | +|<. align left | |
| 240 | +|>. align right| |
| 241 | +|=. center | |
| 242 | +|<>. justify | |
| 243 | +|^. valign top | |
| 244 | +|~. bottom |</code></pre> |
| 245 | + |
| 246 | +看效果: |
| 247 | + |
| 248 | +|_. attribute list | |
| 249 | +|<. align left | |
| 250 | +|>. align right| |
| 251 | +|=. center | |
| 252 | +|<>. justify | |
| 253 | +|^. valign top | |
| 254 | +|~. bottom | |
| 255 | + |
| 256 | +你可以跨列 |
| 257 | + |
| 258 | +<pre><code>|\2. spans two cols | |
| 259 | +| col 1 | col 2 |</code></pre> |
| 260 | + |
| 261 | +跨列效果: |
| 262 | + |
| 263 | +|\2. spans two cols | |
| 264 | +| col 1 | col 2 | |
| 265 | + |
| 266 | +你也可以跨行 |
| 267 | + |
| 268 | +<pre><code>|/3. spans 3 rows | a | |
| 269 | +| b | |
| 270 | +| c |</code></pre> |
| 271 | + |
| 272 | +跨行效果: |
| 273 | + |
| 274 | +|/3. spans 3 rows | a | |
| 275 | +| b | |
| 276 | +| c | |
| 277 | + |
| 278 | +这是运用CSS到表格的例子: |
| 279 | + |
| 280 | +<pre><code>|{background:#ddd}. Grey cell| |
| 281 | + |
| 282 | +table{border:1px solid black}. |
| 283 | +|This|is|a|row| |
| 284 | +|This|is|a|row| |
| 285 | + |
| 286 | +|This|is|a|row| |
| 287 | +{background:#ddd}. |This|is|grey|row|</code></pre> |
| 288 | + |
| 289 | +这是效果: |
| 290 | + |
| 291 | +|{background:#ddd}. Grey cell| |
| 292 | + |
| 293 | +table{border:1px solid black}. |
| 294 | +|This|is|a|row| |
| 295 | +|This|is|a|row| |
| 296 | + |
| 297 | +|This|is|a|row| |
| 298 | +{background:#ddd}. |This|is|grey|row| |
| 299 | + |
| 300 | +我想看到这些效果你就知道textile做了什么,如果不清楚就直接看下生成的表格的源码吧。so easy! |
| 301 | + |
| 302 | +好了,这篇教程就介绍到这里,希望对你有用。 |
| 303 | + |
| 304 | +该页面的源码可以到 "github":sourceurl 中下载。 |
| 305 | + |
| 306 | +[sourceurl]https://github.com/simonjava/simonjava.github.io/blob/master/_posts/2014-05-21-Textile-Google%E6%BA%90%E7%A0%81%E7%94%9F%E6%88%90%E6%95%88%E6%9E%9C.textile |
0 commit comments