• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
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

修订版dca924bc0ab8f5d661ed0dee9d86b57bde12cd94 (tree)
时间2013-04-18 19:05:06
作者hylom <hylom@hylo...>
Commiterhylom

Log Message

fix action: call

更改概述

差异

--- a/jarkup.json
+++ b/jarkup.json
@@ -158,7 +158,7 @@
158158 "priority": 101,
159159 "regexp": "^<(.*)>$",
160160 "continue": false,
161- "call": ["getImageGeometry", "${image_dir}/\\1"],
161+ "call": ["getImageGeometry", "${image_dir}/$1"],
162162 "replace": "<figure style=\"width:${width}px;\">\n<a href=\"${image_dir}/\\1\" target=\"_blank\"><img src=\"${image_dir}/\\1\" alt=\"図$ref $caption\" width=\"${width}\" height=\"${height}\"></a><figcaption>図$ref $caption</figcaption>"
163163 },
164164 "caption": {
--- a/textparser.py
+++ b/textparser.py
@@ -211,10 +211,18 @@ class Parser(object):
211211 def write(self, text):
212212 self.stream_out.write(text)
213213
214- def _expand_variable(self, text):
214+ def _expand_variable(self, text, match=None):
215215 mode = self.current_mode()
216- if not text.find('$'):
216+ if text.find(u'$') < 0:
217217 return text
218+ # expand $[0-9]+
219+ rex = re.compile('\$([0-9]+)')
220+ m = rex.search(text)
221+ if m and match:
222+ sub_func = lambda x:match.group(int(x.group(1)))
223+ text = rex.sub(sub_func, text)
224+
225+ # expand vars
218226 rex = re.compile('\${?([A-Za-z0-9_]+)}?')
219227 m = rex.search(text)
220228 sub_func = lambda x:self.store.load(mode, x.group(1), '')
@@ -260,11 +268,12 @@ class Parser(object):
260268
261269 def execute_action(self, rex, match, rule, text):
262270 if 'call' in rule:
263- (func, newarg) = rule['call']
271+ param = rule['call']
272+ (func, args) = param[0], param[1:]
264273 if func in self.functions:
265- arg = match.group(1)
266274 context = self.store
267- results = self.functions[func](context, arg)
275+ args = [self._expand_variable(x, match) for x in args]
276+ results = self.functions[func](context, args)
268277 for (k, v) in results:
269278 self.store.save(self.current_mode(), k, v)
270279
@@ -323,7 +332,8 @@ class Parser(object):
323332 return (False, text)
324333
325334
326-def getImageGeometry(context, filepath):
335+def getImageGeometry(context, args):
336+ filepath = args[0]
327337 f = open(filepath, 'r')
328338 data = f.read()
329339 f.close()