QuickEdit.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:QuickEdit 作者: gamcoh 项目源码 文件源码
def formatCodeFunction(self):
        try:
            reportHtml = '<div class="function">'
            reportHtml += '<p class="files"><em>in this file, at line : </em><a href="line-{line}">{line}</a></p>'.format(line=self.functionFound['line'])

            # format the code for a better syntax coloration
            reportHtmlContent = re.sub('(private|public|protected)', '<p class="monokai_red">\g<1></p>', self.functionFound['code'])
            reportHtmlContent = re.sub('(function)', '<p class="monokai_blue"><em>\g<1></em></p>', reportHtmlContent)
            reportHtmlContent = re.sub('(function</em></p> )([a-zA-Z0-9_]+)( ?\()', '\g<1><p class="monokai_green">\g<2></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(function</em></p> <p class="monokai_green">[a-zA-Z0-9_]+</p>\()(.*)(\))', '\g<1><p class="monokai_params"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(\$)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(->)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)
            reportHtmlContent = re.sub('(\{.*)(return)(.*\})', '\g<1><p class="monokai_red"><em>\g<2></em></p>\g<3>', reportHtmlContent)

            reportHtml += reportHtmlContent
            reportHtml += '</div>'
        except AttributeError:
            print('[Errno 2] Function not found')

        # 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)


    ########################################################################
    # format the css code in order to show 
    # it in a phantom report modal
    ########################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号