fixes #34
This commit is contained in:
parent
1a932d3a08
commit
6c513ea720
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
|
import io
|
||||||
import shutil
|
import shutil
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
@ -156,14 +157,24 @@ def add_to_tmpl(note, **kwargs):
|
|||||||
addings = js.strip()
|
addings = js.strip()
|
||||||
if addings not in afmt:
|
if addings not in afmt:
|
||||||
if not addings.startswith(u'<script') and not addings.endswith(u'/script>'):
|
if not addings.startswith(u'<script') and not addings.endswith(u'/script>'):
|
||||||
addings = u'\r\n<script>{}</script>'.format(addings)
|
addings = u'\n<script type="text/javascript">\n{}\n</script>'.format(addings)
|
||||||
afmt += addings
|
afmt += addings
|
||||||
if jsfile:
|
if jsfile:
|
||||||
new_jsfile = u'_' + \
|
#new_jsfile = u'_' + \
|
||||||
jsfile if not jsfile.startswith(u'_') else jsfile
|
# jsfile if not jsfile.startswith(u'_') else jsfile
|
||||||
copy_static_file(jsfile, new_jsfile)
|
#copy_static_file(jsfile, new_jsfile)
|
||||||
addings = u'\r\n<script src="{}"></script>'.format(new_jsfile)
|
#addings = u'\r\n<script src="{}"></script>'.format(new_jsfile)
|
||||||
afmt += addings
|
jsfile = jsfile if isinstance(jsfile, list) else [jsfile]
|
||||||
|
addings = u''
|
||||||
|
for fn in jsfile:
|
||||||
|
try:
|
||||||
|
f = io.open(fn, mode="r", encoding="utf-8")
|
||||||
|
addings += u'\n<script type="text/javascript">\n{}\n</script>'.format(f.read())
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if addings not in afmt:
|
||||||
|
afmt += addings
|
||||||
note.model()['tmpls'][0]['afmt'] = afmt
|
note.model()['tmpls'][0]['afmt'] = afmt
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -572,8 +572,9 @@ class MdxService(LocalService):
|
|||||||
@export([u'默认', u'Default'])
|
@export([u'默认', u'Default'])
|
||||||
def fld_whole(self):
|
def fld_whole(self):
|
||||||
html = self.get_default_html()
|
html = self.get_default_html()
|
||||||
js = re.findall(r'<script.*?>.*?</script>', html, re.DOTALL)
|
js = re.findall(r'<script .*?>(.*?)</script>', html, re.DOTALL)
|
||||||
return QueryResult(result=html, js=u'\n'.join(js))
|
jsfile = re.findall(r'<script .*?src=[\'\"](.+?)[\'\"]', html, re.DOTALL)
|
||||||
|
return QueryResult(result=html, js=u'\n'.join(js), jsfile=jsfile)
|
||||||
|
|
||||||
def _get_definition_mdx(self):
|
def _get_definition_mdx(self):
|
||||||
"""according to the word return mdx dictionary page"""
|
"""according to the word return mdx dictionary page"""
|
||||||
|
|||||||
@ -156,14 +156,25 @@ def add_to_tmpl(note, **kwargs):
|
|||||||
addings = js.strip()
|
addings = js.strip()
|
||||||
if addings not in afmt:
|
if addings not in afmt:
|
||||||
if not addings.startswith(u'<script') and not addings.endswith(u'/script>'):
|
if not addings.startswith(u'<script') and not addings.endswith(u'/script>'):
|
||||||
addings = u'\r\n<script>{}</script>'.format(addings)
|
addings = u'\n<script type="text/javascript">\n{}\n</script>'.format(addings)
|
||||||
afmt += addings
|
afmt += addings
|
||||||
if jsfile:
|
if jsfile:
|
||||||
new_jsfile = u'_' + \
|
#new_jsfile = u'_' + \
|
||||||
jsfile if not jsfile.startswith(u'_') else jsfile
|
# jsfile if not jsfile.startswith(u'_') else jsfile
|
||||||
copy_static_file(jsfile, new_jsfile)
|
#copy_static_file(jsfile, new_jsfile)
|
||||||
addings = u'\r\n<script src="{}"></script>'.format(new_jsfile)
|
#addings = u'\r\n<script src="{}"></script>'.format(new_jsfile)
|
||||||
afmt += addings
|
#afmt += addings
|
||||||
|
jsfile = jsfile if isinstance(jsfile, list) else [jsfile]
|
||||||
|
addings = u''
|
||||||
|
for fn in jsfile:
|
||||||
|
try:
|
||||||
|
with open(fn, 'r', encoding="utf-8") as f:
|
||||||
|
addings += u'\n<script type="text/javascript">\n{}\n</script>'.format(f.read())
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if addings not in afmt:
|
||||||
|
afmt += addings
|
||||||
note.model()['tmpls'][0]['afmt'] = afmt
|
note.model()['tmpls'][0]['afmt'] = afmt
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -578,8 +578,10 @@ class MdxService(LocalService):
|
|||||||
@export([u'默认', u'Default'])
|
@export([u'默认', u'Default'])
|
||||||
def fld_whole(self):
|
def fld_whole(self):
|
||||||
html = self.get_default_html()
|
html = self.get_default_html()
|
||||||
js = re.findall(r'<script.*?>.*?</script>', html, re.DOTALL)
|
js = re.findall(r'<script .*?>(.*?)</script>', html, re.DOTALL)
|
||||||
return QueryResult(result=html, js=u'\n'.join(js))
|
jsfile = re.findall(r'<script .*?src=[\'\"](.+?)[\'\"]', html, re.DOTALL)
|
||||||
|
return QueryResult(result=html, js=u'\n'.join(js), jsfile=jsfile)
|
||||||
|
|
||||||
|
|
||||||
def _get_definition_mdx(self):
|
def _get_definition_mdx(self):
|
||||||
"""according to the word return mdx dictionary page"""
|
"""according to the word return mdx dictionary page"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user