Merge pull request #408 from Oberon00/rst-fix-python3
rst: Improve compatibility of snippets with Python 3
This commit is contained in:
commit
23e1406784
@ -42,18 +42,9 @@ INCLUDABLE_DIRECTIVES = ['image', 'figure', 'include']
|
|||||||
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
|
CJK_RE = re.compile(u'[⺀-⺙⺛-⻳⼀-⿕々〇〡-〩〸-〺〻㐀-䶵一-鿃豈-鶴侮-頻並-龎]', re.UNICODE)
|
||||||
|
|
||||||
|
|
||||||
def has_cjk(char):
|
def has_cjk(s):
|
||||||
"""
|
"""Detect if s contains CJK characters."""
|
||||||
Detect char contains CJK character
|
return CJK_RE.search(s) is not None
|
||||||
|
|
||||||
:param char: characters needs to be detect
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
CJK_RE.finditer(char).next()
|
|
||||||
except StopIteration:
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def real_filename(filename):
|
def real_filename(filename):
|
||||||
"""pealeextension name off if possible
|
"""pealeextension name off if possible
|
||||||
@ -96,7 +87,7 @@ def make_items(times, leading='+'):
|
|||||||
times = int(times)
|
times = int(times)
|
||||||
if leading == 1:
|
if leading == 1:
|
||||||
msg = ""
|
msg = ""
|
||||||
for x in xrange(1, times+1):
|
for x in range(1, times+1):
|
||||||
msg += "%s. Item\n" % x
|
msg += "%s. Item\n" % x
|
||||||
return msg
|
return msg
|
||||||
else:
|
else:
|
||||||
@ -182,7 +173,7 @@ endsnippet
|
|||||||
|
|
||||||
snippet em "Emphasize string" i
|
snippet em "Emphasize string" i
|
||||||
`!p
|
`!p
|
||||||
# dirty but works with CJK charactor detection
|
# dirty but works with CJK character detection
|
||||||
if has_cjk(vim.current.line):
|
if has_cjk(vim.current.line):
|
||||||
snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p
|
snip.rv ="\ "`*${1:${VISUAL:Em}}*`!p
|
||||||
if has_cjk(vim.current.line):
|
if has_cjk(vim.current.line):
|
||||||
|
Loading…
Reference in New Issue
Block a user