fix regexes
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
"""Markslider: a slideshow engine based on markdown."""
|
"""Markslider: a slideshow engine based on markdown."""
|
||||||
|
|
||||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||||
__version__ = "1.3.1"
|
__version__ = "1.3.2"
|
||||||
|
|
||||||
import sys, os, argparse, re, datetime
|
import sys, os, argparse, re, datetime
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@@ -73,8 +73,8 @@ class slide_reader:
|
|||||||
self.max_width = None
|
self.max_width = None
|
||||||
self.max_height = None
|
self.max_height = None
|
||||||
self.data = []
|
self.data = []
|
||||||
self.re_image_convert = re.compile("(.*)(!\[.*\])\((.*)\)>")
|
self.re_image_convert = re.compile(r"(.*)(!\[.*\])\((.*)\)>")
|
||||||
self.re_command = re.compile("(.*)`(.*)`>(.*)")
|
self.re_command = re.compile(r"(.*)`(.*)`>(.*)")
|
||||||
# ~ self.control_chars = ''.join(map(unichr, range(0,32) + range(127,160)))
|
# ~ self.control_chars = ''.join(map(unichr, range(0,32) + range(127,160)))
|
||||||
# ~ self.control_char_re = re.compile('[%s]' % re.escape(self.control_chars))
|
# ~ self.control_char_re = re.compile('[%s]' % re.escape(self.control_chars))
|
||||||
self.background = []
|
self.background = []
|
||||||
@@ -207,19 +207,19 @@ class slide_reader:
|
|||||||
if self.opts.toc_depth > 1:
|
if self.opts.toc_depth > 1:
|
||||||
for line in page:
|
for line in page:
|
||||||
title = line.strip("# ")
|
title = line.strip("# ")
|
||||||
if re.search("^##[^#]", line):
|
if re.search(r"^##[^#]", line):
|
||||||
subh = [subh[0] + 1, 0, 0]
|
subh = [subh[0] + 1, 0, 0]
|
||||||
TOC.append(" %d.%d. %s" % (h1 + 1, subh[0], title))
|
TOC.append(" %d.%d. %s" % (h1 + 1, subh[0], title))
|
||||||
if self.opts.toc_depth == 2:
|
if self.opts.toc_depth == 2:
|
||||||
continue
|
continue
|
||||||
if re.search("^###[^#]", line):
|
if re.search(r"^###[^#]", line):
|
||||||
subh = [subh[0], subh[1] + 1, 0]
|
subh = [subh[0], subh[1] + 1, 0]
|
||||||
TOC.append(
|
TOC.append(
|
||||||
" %d.%d.%d. %s" % (h1 + 1, subh[0], subh[1], title)
|
" %d.%d.%d. %s" % (h1 + 1, subh[0], subh[1], title)
|
||||||
)
|
)
|
||||||
if self.opts.toc_depth == 3:
|
if self.opts.toc_depth == 3:
|
||||||
continue
|
continue
|
||||||
if re.search("^####[^#]", line):
|
if re.search(r"^####[^#]", line):
|
||||||
subh = [subh[0], subh[1], subh[2] + 1]
|
subh = [subh[0], subh[1], subh[2] + 1]
|
||||||
TOC.append(
|
TOC.append(
|
||||||
" %d.%d.%d.%d. %s"
|
" %d.%d.%d.%d. %s"
|
||||||
@@ -863,7 +863,7 @@ def colorify(s, opts):
|
|||||||
def cut_line(s, i):
|
def cut_line(s, i):
|
||||||
"""cut a color tagged string, and remove control chars"""
|
"""cut a color tagged string, and remove control chars"""
|
||||||
s = s[:i]
|
s = s[:i]
|
||||||
s = re.sub("\$$", "", re.sub("\$\{$", "", re.sub("\$\{.$", "", s)))
|
s = re.sub(r"\$$", "", re.sub(r"\$\{$", "", re.sub(r"\$\{.$", "", s)))
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
@@ -888,16 +888,16 @@ def launch(reader, opts, offset):
|
|||||||
return
|
return
|
||||||
s = reader.get_current_page()[offset[1]]
|
s = reader.get_current_page()[offset[1]]
|
||||||
urls = re.findall(
|
urls = re.findall(
|
||||||
"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+",
|
r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+",
|
||||||
s,
|
s,
|
||||||
)
|
)
|
||||||
images = re.findall("!\[[^]]+\]\([^\)]+\)", s)
|
images = re.findall(r"!\[[^]]+\]\([^\)]+\)", s)
|
||||||
# sanity check
|
# sanity check
|
||||||
if s.find("`") == -1 and len(urls) == 0 and len(images) == 0:
|
if s.find("`") == -1 and len(urls) == 0 and len(images) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
run_command = re.match("(.*)`(.*)`!(.*)", s)
|
run_command = re.match(r"(.*)`(.*)`!(.*)", s)
|
||||||
show_command = re.match("(.*)`(.*)`>(.*)", s)
|
show_command = re.match(r"(.*)`(.*)`>(.*)", s)
|
||||||
if show_command != None:
|
if show_command != None:
|
||||||
output = subprocess.check_output(show_command.group(2).strip(), shell=True)
|
output = subprocess.check_output(show_command.group(2).strip(), shell=True)
|
||||||
if type(output) == bytes:
|
if type(output) == bytes:
|
||||||
@@ -936,7 +936,7 @@ def launch(reader, opts, offset):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
if len(images) > 0:
|
if len(images) > 0:
|
||||||
image = re.sub(".*\(([^\)]+)\).*", "\\1", images[0])
|
image = re.sub(r".*\(([^\)]+)\).*", "\\1", images[0])
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
"%s '%s' &"
|
"%s '%s' &"
|
||||||
% (
|
% (
|
||||||
|
|||||||
Reference in New Issue
Block a user