• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

generic text markup tools


コミットメタ情報

リビジョン5649b28e2f691304c4faddbd26f6625dc3ea2dd6 (tree)
日時2013-11-18 20:22:38
作者hylom <hylom@hylo...>
コミッターhylom

ログメッセージ

add ctable plugin

変更サマリ

差分

--- a/ctable.json
+++ b/ctable.json
@@ -1,12 +1,30 @@
11 {
2- "rules": {
2+ "usePlugins": [
3+ "ctable"
4+ ],
5+ "modes": {
6+ "global": {
7+ "rules": {
8+ },
9+ "transitions": [
10+ "figure",
11+ "code",
12+ "langCode",
13+ "ctable",
14+ "unOrderdList",
15+ "note",
16+ "comment",
17+ "codeList"
18+ ]
19+ },
320 "ctable": {
421 "extends": "table",
522 "rules": {
623 "tableRow": {
724 "priority": 102,
825 "regexp": "^(.*)$",
9- "call:" ["ctable.tableRow", "$1"]
26+ "call": [ "ctable.tableRow", "$1" ],
27+ "replace": ""
1028 },
1129 "tableHeaderRow": {
1230 "priority": 104,
@@ -15,7 +33,8 @@
1533 "isHeader",
1634 "yes"
1735 ],
18- "call:" ["ctable.tableHeaderRow", "$1"]
36+ "call": ["ctable.tableHeaderRow", "$1"],
37+ "replace": ""
1938 },
2039 "tableCell": {
2140 "priority": 103,
@@ -23,9 +42,11 @@
2342 "replace": "\\t"
2443 }
2544 },
45+ "begin": "^☆表.*",
46+ "end": "^\\s*$",
2647 "onFinished": {
27- "call:" ["ctable.getTable"],
28- "insert": "${table}"
48+ "call": ["ctable.flushTable"],
49+ "insert": "${ctable}\n</table></div>\n"
2950 }
3051 }
3152 }
--- /dev/null
+++ b/plugins/ctable.py
@@ -0,0 +1,31 @@
1+#
2+# -*- codeing: utf-8 -*-
3+'ctable.py'
4+
5+import re
6+
7+table_rows = []
8+
9+def tableRow(context, args):
10+ line = args[0]
11+ cells = line.split("\t")
12+ table_rows.append(cells)
13+ return []
14+
15+def tableHeaderRow(context, args):
16+ return tableRow(context, args)
17+
18+def renderTable(context, args):
19+ buf = ""
20+ for row in table_rows:
21+ buf += "<tr>\n "
22+ for cell in row:
23+ buf += "<td>" + cell + "</td>"
24+ buf += "\n</tr>"
25+ return [('ctable', buf)]
26+
27+def flushTable(context, args):
28+ ret = renderTable(context, args)
29+ table_rows = []
30+ return ret
31+
--- /dev/null
+++ b/test/ctable.txt
@@ -0,0 +1,14 @@
1+
2+●ctableのテスト
3+
4+ ctableでは、空セルが自動的に上下のセルに連結されます。
5+
6+○実例
7+
8+☆表1 ctableの例
9+〓見出し1 見出し2 見出し3 見出し4
10+アイテム11 アイテム21 アイテム31 アイテム41
11+ アイテム22 アイテム32 アイテム42
12+アイテム13 アイテム33 アイテム43
13+アイテム14 アイテム34 アイテム44
14+
--- /dev/null
+++ b/test/test_ctable.sh
@@ -0,0 +1,3 @@
1+python ../tlexi.py -r ../jarkup.json -a ../ctable.json ctable.txt out.txt
2+cat out.txt
3+
--- a/textparser.py
+++ b/textparser.py
@@ -109,6 +109,15 @@ class Mode(object):
109109 '''action when mode finished'''
110110 if self.has_attr("onFinished"):
111111 m = self.attr("onFinished")
112+ if "call" in m:
113+ param = m["call"]
114+ (func, args) = param[0], param[1:]
115+ if func in writer.functions:
116+ context = writer.store
117+ args = [writer._expand_variable(x, match) for x in args]
118+ results = writer.functions[func](context, args)
119+ for (k, v) in results:
120+ writer.store.save(k, v)
112121 if "insert" in m:
113122 writer.write(m["insert"])
114123 if "replace" in m:
@@ -176,9 +185,14 @@ def embed_loader(parser, name):
176185 plugins = __import__(mod_name, globals(), locals(), [], -1)
177186 mod = plugins.__getattribute__(name)
178187 for elem in mod.__dict__:
188+ if elem[0] == '_':
189+ continue
190+ func = mod.__getattribute__(elem)
191+ if not hasattr(func, '__call__'):
192+ continue
179193 func_name = name + "." + elem
180- parser.add_function(func_name, mod.__getattribute__(elem))
181- print func_name
194+ parser.add_function(func_name, func)
195+ print "load_function: " + func_name
182196
183197 class Parser(object):
184198 """markupper class"""
@@ -227,8 +241,11 @@ class Parser(object):
227241 except StopIteration:
228242 return
229243
230- def write(self, text):
244+ def raw_write(self, text):
231245 self.stream_out.write(text)
246+
247+ def write(self, text):
248+ self.raw_write(self._expand_variable(text))
232249
233250 def _expand_variable(self, text, match=None):
234251 if text.find(u'$') < 0:
@@ -339,6 +356,7 @@ class Parser(object):
339356 if 'continue' in rule:
340357 if rule['continue'] == False:
341358 return (True, text)
359+
342360 return (False, text)
343361
344362