• 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ão5f2dafea1cf41da06d4e952903a6bf7b0cbfa759 (tree)
Hora2013-04-01 19:59:57
Autorhylom <hylom@hylo...>
Commiterhylom

Mensagem de Log

writing 'call' action....

Mudança Sumário

Diff

--- a/jarkup.json
+++ b/jarkup.json
@@ -119,6 +119,7 @@
119119 "priority": 101,
120120 "regexp": "^<(.*)>$",
121121 "continue": false,
122+ "call": ["getImageGeom", "${image_dir}/\\1"],
122123 "replace": "<a href=\"${image_dir}/\\1\" target=\"_blank\"><img src=\"${image_dir}/\\1\" alt=\"図$ref $caption\" width=\"480\"></a><span class=\"caption\">図$ref $caption</span>"
123124 },
124125 "caption": {
--- a/test/test.txt
+++ b/test/test.txt
@@ -17,7 +17,7 @@
1717  jareでは*[http://example.com/]のようにリンクを埋め込めます。*[http://hylom.net/ このように]リンクを埋めることも可能です。
1818
1919 ☆図1 図のキャプション
20-<imagefile.png>
20+<network.png>
2121
2222  また、*図1のようにして参照を埋め込めます。*[http://example.com/]のようにリンクも埋め込めます。*[http://hylom.net/ このように]リンクを埋めることも可能です。
2323
--- a/textparser.py
+++ b/textparser.py
@@ -15,6 +15,9 @@ class Parser(object):
1515 self.mode_stack = ["global", ]
1616 self.mode_stores = {}
1717 self._global_stores = {}
18+ self.functions = {
19+# "getImageGeom": getImageGeom,
20+ }
1821
1922 def currentMode(self):
2023 try:
@@ -123,9 +126,6 @@ class Parser(object):
123126 text = self._do_action(mode, text, new_actions, rex, match)
124127 return text
125128
126- if 'replace' in actions:
127- text = rex.sub(actions['replace'], text)
128- text = self._expand_variable(mode, text)
129129 if 'store' in actions:
130130 arg = actions['store']
131131 if isinstance(arg, list):
@@ -139,6 +139,17 @@ class Parser(object):
139139 if 'set' in actions:
140140 arg = actions['set']
141141 self._store(mode, arg[0], arg[1])
142+ if 'call' in actions:
143+ (func, newarg) = actions['call']
144+ if func in self.functions:
145+ arg = match.group(1)
146+ context = self.mode_stores.get(mode, {})
147+ results = self.functions[func](context, arg)
148+ for (k, v) in results:
149+ self._store(mode, k, v)
150+ if 'replace' in actions:
151+ text = rex.sub(actions['replace'], text)
152+ text = self._expand_variable(mode, text)
142153 return text
143154
144155 def _apply_rules(self, mode, text):
@@ -183,3 +194,7 @@ class Parser(object):
183194 break
184195
185196 return text
197+
198+
199+def getImageGeom(context, filename):
200+ return [('width', str(128)), ('height', str(256))]
--- a/tlexi.py
+++ b/tlexi.py
@@ -9,7 +9,6 @@ from optparse import OptionParser
99 from lexi import Lexi
1010 from textparser import Parser
1111
12-
1312 def parse_arguments():
1413 "Generate option parser and parse arguments"
1514 usage = "usage: %prog [options] <source_file> <output_file>"
@@ -33,7 +32,6 @@ def parse_arguments():
3332 options.output_file = args[1]
3433 return options
3534
36-
3735 def main():
3836 opts = parse_arguments()
3937 lexi = Lexi(opts.rule_file)
@@ -48,12 +46,10 @@ def main():
4846 else:
4947 output = codecs.open(opts.output_file, 'w', 'utf8')
5048
51-
5249 # do markup
5350 parser = Parser(lexi)
5451 parser.markup(source, output)
5552
56-
5753 if __name__ == '__main__':
5854 main()
5955