• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

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

修訂53662205ab30b86aaad5ec3e64797e3ba7e7f032 (tree)
時間2013-04-18 19:50:25
作者hylom <hylom@hylo...>
Commiterhylom

Log Message

update jarkup

Change Summary

差異

--- a/jarkup.json
+++ b/jarkup.json
@@ -22,7 +22,7 @@
2222 "red1": {
2323 "priority": 102,
2424 "regexp": "\\*g\\[(.*?)]",
25- "replace": "<strong class=\"red-text\">\\1</strong>"
25+ "replace": "<strong class=\"color-red\">\\1</strong>"
2626 },
2727 "bold2": {
2828 "priority": 103,
@@ -32,7 +32,7 @@
3232 "red2": {
3333 "priority": 104,
3434 "regexp": "\\*g\\{(.*?)}",
35- "replace": "<strong class=\"red-text\">\\1</strong>"
35+ "replace": "<strong class=\"color-red\">\\1</strong>"
3636 },
3737 "bold1": {
3838 "priority": 105,
@@ -246,7 +246,7 @@
246246 },
247247 "blockDevider": "\n",
248248 "globalVariables": [
249- "image_dir",
250- "."
249+ "image_dir", ".",
250+ "defaultFigureWidth", "480"
251251 ]
252252 }
--- a/textparser.py
+++ b/textparser.py
@@ -134,38 +134,42 @@ class ModeStack(object):
134134 return None
135135
136136 class Store(dict):
137- def __init__(self):
137+ def __init__(self, mode_stack):
138138 self.mode_stores = {}
139139 self.global_store = {}
140+ self._mode_stack = mode_stack;
141+
142+ def _mode(self):
143+ return self._mode_stack.current()
140144
141145 def save_global(self, key, value):
142146 self.global_store[key] = value
143147
144- def save(self, mode, key, value):
145- modekey = mode.name
146- if not modekey in self.mode_stores:
147- self.mode_stores[modekey] = {}
148- self.mode_stores[modekey][key] = value
148+ def save(self, key, value):
149+ mode = self._mode()
150+ if not mode in self.mode_stores:
151+ self.mode_stores[mode] = {}
152+ self.mode_stores[mode][key] = value
149153
150- def load(self, mode, key, default=None):
151- modekey = mode.name
152- if (modekey in self.mode_stores) and (key in self.mode_stores[modekey]):
153- return self.mode_stores[modekey][key]
154+ def load(self, key, default=None):
155+ mode = self._mode()
156+ if (mode in self.mode_stores) and (key in self.mode_stores[mode]):
157+ return self.mode_stores[mode][key]
154158 else:
155159 return self.global_store.get(key, default)
156160
157- def delete(self, mode, key):
158- modekey = mode.name
159- if not modekey in self.mode_stores:
161+ def delete(self, key):
162+ mode = self._mode()
163+ if not mode in self.mode_stores:
160164 return
161- if not key in self.mode_stores[modekey]:
165+ if not key in self.mode_stores[mode]:
162166 return
163- del self.mode_stores[modekey][key]
167+ del self.mode_stores[mode][key]
164168
165- def clear(self, mode):
166- modekey = mode.name
167- if modekey in self.mode_stores:
168- del self.mode_stores[modekey]
169+ def clear(self):
170+ mode = self._mode()
171+ if mode in self.mode_stores:
172+ del self.mode_stores[mode]
169173
170174
171175 class Parser(object):
@@ -180,7 +184,7 @@ class Parser(object):
180184 self.mode_stack = ModeStack()
181185 self.mode_stack.push("global")
182186
183- self.store = Store()
187+ self.store = Store(self.mode_stack)
184188 self.functions = {
185189 "getImageGeometry": getImageGeometry,
186190 }
@@ -212,7 +216,6 @@ class Parser(object):
212216 self.stream_out.write(text)
213217
214218 def _expand_variable(self, text, match=None):
215- mode = self.current_mode()
216219 if text.find(u'$') < 0:
217220 return text
218221 # expand $[0-9]+
@@ -225,7 +228,7 @@ class Parser(object):
225228 # expand vars
226229 rex = re.compile('\${?([A-Za-z0-9_]+)}?')
227230 m = rex.search(text)
228- sub_func = lambda x:self.store.load(mode, x.group(1), '')
231+ sub_func = lambda x:self.store.load(x.group(1), '')
229232 text = rex.sub(sub_func, text)
230233 return text
231234
@@ -242,6 +245,7 @@ class Parser(object):
242245 #_debug_print(mode.name)
243246 if mode.test("end", text):
244247 text = mode.on_exit(self, text)
248+ self.store.clear()
245249 self.mode_stack.pop()
246250 next_mode = self.current_mode()
247251 if next_mode:
@@ -275,7 +279,7 @@ class Parser(object):
275279 args = [self._expand_variable(x, match) for x in args]
276280 results = self.functions[func](context, args)
277281 for (k, v) in results:
278- self.store.save(self.current_mode(), k, v)
282+ self.store.save(k, v)
279283
280284
281285 if 'apply' in rule:
@@ -285,7 +289,7 @@ class Parser(object):
285289
286290 if 'switch' in rule:
287291 for key in rule['switch'].keys():
288- value = self.store.load(self.current_mode(), key)
292+ value = self.store.load(key)
289293 if value == None:
290294 continue
291295 if value not in rule['switch'][key]:
@@ -297,17 +301,17 @@ class Parser(object):
297301 arg = rule['store']
298302 if isinstance(arg, list):
299303 for index in range(len(arg)):
300- self.store.save(self.current_mode(), arg[index], match.group(index+1))
304+ self.store.save(arg[index], match.group(index+1))
301305 else:
302- self.store.save(self.current_mode(), arg, match.group(1))
306+ self.store.save(arg, match.group(1))
303307
304308 if 'unset' in rule:
305309 key = rule['unset']
306- self.store.delete(self.current_mode(), key)
310+ self.store.delete(key)
307311
308312 if 'set' in rule:
309313 arg = rule['set']
310- self.store.save(self.current_mode(), arg[0], arg[1])
314+ self.store.save(arg[0], arg[1])
311315
312316 if 'replace' in rule:
313317 text = rex.sub(rule['replace'], text)
@@ -338,4 +342,7 @@ def getImageGeometry(context, args):
338342 data = f.read()
339343 f.close()
340344 (w, h) = imagesize.get_image_size(data)
341- return [('width', str(w)), ('height', str(h))]
345+ return [
346+ ('width', str(w)),
347+ ('height', str(h))
348+ ]