def formatCode(self):
reportHtml=""
for code in self.stylesFound:
# adding the file name
if code['file'] == 'self':
reportHtml += '<p class="files"><em>in this file</em>, at line : <a href="line-{line}">{line}</a></p>'.format(line=code['line'])
else:
reportHtml += '<p class="files"><em>in %s</em></p>' % (code['file'])
reportHtml += code['code']
# no css style were found
if not reportHtml:
self.aErrors.append('Could not find any css style')
# put minihtml tag and class name
# in order to stylize the css
reportHtml = re.sub(r'\n|\t', '', reportHtml)
# found all the pre-brackets code
pre_brackets = re.findall(r'([#a-zA-Z0-9_. ]+)(\s?){', reportHtml)
for r in pre_brackets:
# for all the pre-brackets code we search for tag names, id,
# and class name in order to format them
formattedCode = re.sub(r'([#a-zA-Z0-9_.-]+)', '<p class="tagName">\g<1></p>', r[0])
formattedCode = re.sub(r'<p class="tagName">(\.[a-zA-Z0-9_.-]+)<\/p>', '<p class="className">\g<1></p>', formattedCode)
formattedCode = re.sub(r'<p class="tagName">(#[#a-zA-Z0-9_-]+)<\/p>', '<p class="idName">\g<1></p>', formattedCode)
reportHtml = re.sub(r[0], formattedCode, reportHtml)
reportHtml = re.sub(r'}', '<p class="className"><b>}</b></p>', reportHtml)
reportHtml = re.sub(r'([a-zA-Z_-]+): ([a-zA-Z0-9_-]+);', '<p class="attributs"><em>\g<1></em>: <b>\g<2></b>;</p>', reportHtml)
# load the font
settings = sublime.load_settings('Preferences.sublime-settings')
font = ''
if settings.has('font_face'):
font = '"%s",' % settings.get('font_face')
# getting the errors that occured during the execution
htmlErrors = ''
if self.QuickEditSetting.get('show_errors'):
for e in self.aErrors:
htmlErrors += '<p class="error">• %s</p>' % e
# if errors were found
if htmlErrors:
htmlErrors = '<div class="panel panel-error mt20"><div class="panel-header">Errors that occured during the search</div><div class="panel-body">{errors}</div></div>'.format(errors=htmlErrors)
# load css, and html ui
css = sublime.load_resource('Packages/QuickEdit/resources/ui.css').replace('@@font', font)
html = sublime.load_resource('Packages/QuickEdit/resources/report.html').format(css=css, html=reportHtml, errors=htmlErrors)
self.view.erase_phantoms('quick_edit')
self.view.add_phantom("quick_edit", self.view.sel()[0], html, sublime.LAYOUT_BLOCK, self.click)
# when the user click on one of the phantom action
评论列表
文章目录