• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

generic text markup tools


Commit MetaInfo

Revisãoff58a35752148fc8750ef8d95b8b49f87727be5f (tree)
Hora2014-02-06 19:45:05
Autorhylom <hylom@hylo...>
Commiterhylom

Mensagem de Log

implement ctable and fix expand vars bug

Mudança Sumário

Diff

--- a/ctable.json
+++ b/ctable.json
@@ -22,9 +22,9 @@
2222 "rules": {
2323 "tableRow": {
2424 "priority": 102,
25- "regexp": "^(.*)$",
25+ "regexp": "^([^〓].*)$",
2626 "call": [ "ctable.tableRow", "$1" ],
27- "replace": ""
27+ "replace": null
2828 },
2929 "tableHeaderRow": {
3030 "priority": 104,
@@ -34,7 +34,7 @@
3434 "yes"
3535 ],
3636 "call": ["ctable.tableHeaderRow", "$1"],
37- "replace": ""
37+ "replace": null
3838 },
3939 "tableCell": {
4040 "priority": 103,
--- a/jarkup
+++ b/jarkup
@@ -3,4 +3,10 @@ BASE_DIR=~/repos/tlexi
33 TLEXI="python ${BASE_DIR}/tlexi.py"
44 LEXI=${BASE_DIR}jare.py
55
6-$TLEXI -r ${BASE_DIR}/jarkup.json $1 $2
6+case $1 in
7+-c)
8+ $TLEXI -r ${BASE_DIR}/jarkup.json -a ${BASE_DIR}/ctable.json $2 $3 ;;
9+*)
10+ $TLEXI -r ${BASE_DIR}/jarkup.json $1 $2 ;;
11+esac
12+
--- a/plugins/ctable.py
+++ b/plugins/ctable.py
@@ -22,7 +22,7 @@ def tableHeaderRow(context, args):
2222
2323 def start_tag(tag, attrs={}):
2424 if len(attrs) > 0:
25- attr = " " + " ".join([x + "=" + '"' + attrs[x] + '"' for x in attrs.keys()])
25+ attr = " " + " ".join([x + "=" + '"' + str(attrs[x]) + '"' for x in attrs.keys()])
2626 else:
2727 attr = ""
2828 return "<" + tag + attr + ">"
@@ -37,7 +37,8 @@ def renderTable(context, args):
3737 buf += "<tr>\n "
3838 width = len(table_rows[i])
3939 for j in range(0, width):
40- print ":" + str(i) + "," + str(j)
40+ if table_rows[i][j] == "":
41+ continue
4142 attrs = {}
4243 # check: cell is header?
4344 if table_attrs.get((i, j), False):
@@ -45,14 +46,21 @@ def renderTable(context, args):
4546 else:
4647 tag = "td"
4748 # check:
48- if i == 0:
49- rowspan = 0
50- for x in range(i+1, height):
51- if table_rows[x][j] != "":
52- break;
53- rowspan += 1;
54- if rowspan > 0:
55- attrs["rowspan"] = rowspan
49+ if j == 0:
50+ rowspan = 0
51+ for x in range(i+1, height):
52+ if table_rows[x][j] != "":
53+ break;
54+ rowspan += 1;
55+ if rowspan > 0:
56+ attrs["rowspan"] = rowspan
57+ colspan = 0
58+ for y in range(j+1, width):
59+ if table_rows[i][y] != "":
60+ break;
61+ colspan += 1;
62+ if colspan > 0:
63+ attrs["colspan"] = colspan
5664
5765 buf += start_tag(tag, attrs) + table_rows[i][j] + end_tag(tag)
5866 buf += "\n</tr>"
--- a/test/ctable.txt
+++ b/test/ctable.txt
@@ -1,4 +1,73 @@
11
2+
3+☆image_dir: img
4+
5+<h2 class="title">
6+基本的に生HTMLや文字列はそのまま出力されます。
7+</h2>
8+
9+ 行頭が全角スペースの行はパラグラフテキストとして認識されます。
10+
11+●大見出し
12+
13+ 空行、もしくはホワイトスペースのみの行は無視されます。
14+ Wiki記法などとは異なり、改行はパラグラフの終了と見なされます。
15+
16+ 文字中の<や>、&は適切にエンティティに変換されます。
17+
18+ バグがありそうなのは文中に$hogeがあるケースです。
19+
20+○中見出し
21+ jareでは*[http://example.com/]のようにリンクを埋め込めます。*[http://hylom.net/ このように]リンクを埋めることも可能です。
22+
23+☆図1 図のキャプション
24+<network.png>
25+
26+ また、*図1のようにして参照を埋め込めます。*[http://example.com/]のようにリンクも埋め込めます。*[http://hylom.net/ このように]リンクを埋めることも可能です。
27+
28+○箇条書き
29+ 箇条書きは以下のようにliタグに変換されます。
30+
31+・1つめ
32+・2つめ(*g[強調]付き)
33+・3つめ(*[http://example.com/ リンク]付き
34+
35+○実行例/リストの埋め込み
36+
37+☆+---
38+実行例/リストなどは
39+このようにして
40+埋め込めます
41+文字装飾*b[太字]や*g[赤字]なども
42+もしくは*b{こういう感じ}や*g{こんな風}にもできます
43+☆+---
44+
45+☆note 注釈/コラム
46+ 注釈/コラム内ではほかのマークアップがそのまま使えます。
47+☆note-end
48+
49+ 下記、テストその2。
50+
51+☆+---
52+実行例/リストなどは
53+このようにして
54+うめこめます
55+☆+---
56+
57+☆表1 表のキャプション
58+〓表の見出し1 見出し2
59+アイテム1 アイテム2
60+ アイテム3
61+foo bar
62+
63+☆comment
64+コメント部分です。
65+何も出力されません。
66+☆comment-end
67+
68+hylomのWebサイト
69+http:/hylom.net/
70+
271 ●ctableのテスト
372
473  ctableでは、空セルが自動的に上下のセルに連結されます。
--- a/test/test.txt
+++ b/test/test.txt
@@ -15,6 +15,8 @@
1515
1616  文字中の<や>、&は適切にエンティティに変換されます。
1717
18+ バグがありそうなのは文中に$hogeがあるケースです。
19+
1820 ○中見出し
1921  jareでは*[http://example.com/]のようにリンクを埋め込めます。*[http://hylom.net/ このように]リンクを埋めることも可能です。
2022
--- a/test/test_ctable.sh
+++ b/test/test_ctable.sh
@@ -1,3 +1,4 @@
1+python ../tlexi.py -r ../jarkup.json ctable.txt out0.txt
12 python ../tlexi.py -r ../jarkup.json -a ../ctable.json ctable.txt out.txt
23 cat out.txt
34
--- a/textparser.py
+++ b/textparser.py
@@ -236,18 +236,22 @@ class Parser(object):
236236 while self.current_mode():
237237 l = iter_in.next().strip('\r\n')
238238 out = self._markup(l)
239- self.write(out)
240- self.write('\n')
239+ if out != None:
240+ self.write(out)
241+ self.write('\n')
241242 except StopIteration:
242243 return
243244
244245 def raw_write(self, text):
245- self.stream_out.write(text)
246+ if text != None:
247+ self.stream_out.write(text)
246248
247249 def write(self, text):
248250 self.raw_write(self._expand_variable(text))
249251
250252 def _expand_variable(self, text, match=None):
253+ if text == None:
254+ return None
251255 if text.find(u'$') < 0:
252256 return text
253257 # expand $[0-9]+
@@ -264,8 +268,14 @@ class Parser(object):
264268 # expand vars
265269 rex = re.compile('\${?([A-Za-z0-9_]+)}?')
266270 m = rex.search(text)
267- sub_func = lambda x:self.store.load(x.group(1), x.string)
268- text = rex.sub(sub_func, text)
271+ if m:
272+ def sub_func(x):
273+ val = self.store.load(x.group(1))
274+ if val != None:
275+ return val
276+ else:
277+ return "$" + x.group(1)
278+ text = rex.sub(sub_func, text)
269279 return text
270280
271281 def _markup(self, text):
@@ -350,8 +360,11 @@ class Parser(object):
350360 self.store.save(arg[0], arg[1])
351361
352362 if 'replace' in rule:
353- text = rex.sub(rule['replace'], text)
354- text = self._expand_variable(text)
363+ if rule['replace'] == None:
364+ text = None
365+ else:
366+ text = rex.sub(rule['replace'], text)
367+ text = self._expand_variable(text)
355368
356369 if 'continue' in rule:
357370 if rule['continue'] == False:
@@ -366,9 +379,10 @@ class Parser(object):
366379 return (False, text)
367380
368381 if 'regexp' in rule:
369- rex = re.compile(rule['regexp'])
370- match = rex.search(text)
371- if match:
372- return self.execute_action(rex, match, rule, text)
382+ if text != None:
383+ rex = re.compile(rule['regexp'])
384+ match = rex.search(text)
385+ if match:
386+ return self.execute_action(rex, match, rule, text)
373387 return (False, text)
374388