added date and color to SimpleWebPage
This commit is contained in:
@@ -469,15 +469,31 @@ def add_highlight(s,opts):
|
||||
return colorify(tagged,opts)
|
||||
|
||||
def launch(reader,opts,offset):
|
||||
""" Launch in a string using tags $!command$!
|
||||
Used with highlight
|
||||
Remove empty lines from beginning and end of stdout.
|
||||
""" Launch in a string using tags $!command$! or $>command$>
|
||||
Remove empty lines from beginning and end of stdout in $> commands.
|
||||
Detects URLS and markdown images 
|
||||
"""
|
||||
if not opts.execute:
|
||||
return
|
||||
s=reader.get_current_page()[offset[1]]
|
||||
if s.find("$!")+s.find("$>")==-2:
|
||||
return
|
||||
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', s)
|
||||
images = re.findall('!\[[^]]+\]\([^\)]+\)', s)
|
||||
if s.find("$!")==-1 and s.find("$>")==-1 and len(urls)==0 and len(images)==0:
|
||||
return
|
||||
|
||||
if len(urls)>0:
|
||||
# Remove ) at the end of url: [name](link) markdown syntax
|
||||
subprocess.call("xdg-open '%s' &"%(urls[0].rstrip(")"),),
|
||||
stdout=subprocess.PIPE,stderr=subprocess.PIPE,
|
||||
shell=True)
|
||||
return
|
||||
|
||||
if len(images)>0:
|
||||
image = re.sub('.*\(([^\)]+)\).*', "\\1",images[0])
|
||||
subprocess.call("xdg-open '%s' &"%(image,),
|
||||
stdout=subprocess.PIPE,stderr=subprocess.PIPE,
|
||||
shell=True)
|
||||
return
|
||||
|
||||
run_command=re.match("(.*)\$!(.*)\$!(.*)",s)
|
||||
show_command=re.match("(.*)\$>(.*)\$>(.*)",s)
|
||||
@@ -496,8 +512,6 @@ def launch(reader,opts,offset):
|
||||
return
|
||||
if run_command != None:
|
||||
subprocess.call(run_command.group(2),
|
||||
#~ stdout=subprocess.PIPE,
|
||||
#~ stderr=subprocess.PIPE,
|
||||
shell=True,executable="/bin/bash")
|
||||
inkey=getch.get()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user