iblog语法高亮示例

--------------------------------------------------------------------------------------

iblog 是一款 Sublime Text 2 博客插件,目前只支持cnblog。

项目地址:https://github.com/iskeeter/iblog

--------------------------------------------------------------------------------------

使用以下语法指定代码所使用的语言:

```python
# 代码写在这里
```

下面是语法高亮示例:

```python
class PublishCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if self.view.is_dirty():
            sublime.error_message(u'【错误】请先保存在发布!')
            return
        self.header_region = _get_header_region(self.view)
        if not self.header_region:
            sublime.error_message(u'【错误】请填写头部的博客信息!可按<Shift+F8>插入博客信息模板')
            return
        # status: 0-没有执行,1-正在执行,2-执行成功并停止,3-执行失败停止
        self.status = 0 
        self.file_name = self.view.file_name()
        header_str = self.view.substr(self.header_region)
        self.blog_info = _parse_blog_info(header_str)
        # self.action: 1--新建,2--更新
        if not self.blog_info['blog_id']:
            self.action = 1 
        else:
            self.action = 2
        global blog_settings
        if not blog_settings:
            settings = _load_setting()
            blog_settings = {
                'login_name': settings.get('login_name'),
                'login_password': settings.get('login_password'),
                'xml_rpc_url': settings.get('xml_rpc_url'),
            }
        file_type = check_file_type(self.file_name)
        content = ''
        if file_type == F_MD:
            region = sublime.Region(0, len(self.view))
            content = self._markdown2html(self.view.substr(region))
        else:
            body_region = sublime.Region(self.header_region.end(), len(self.view))
            content = header_str + _plain2html(self.view.substr(body_region))
        self.post = { 'title': self.blog_info['title'],
                'description': content,
                'link': '',
                'author': blog_settings['login_name'],
                'categories': self.blog_info['categories'],
                'mt_keywords': ''
            }
        content = None
        self.server = xmlrpclib.ServerProxy(blog_settings['xml_rpc_url'], allow_none=True)
        self._pulish_async()
```

输出后的效果:

class PublishCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        if self.view.is_dirty():
            sublime.error_message(u'【错误】请先保存在发布!')
            return
        self.header_region = _get_header_region(self.view)
        if not self.header_region:
            sublime.error_message(u'【错误】请填写头部的博客信息!可按<Shift+F8>插入博客信息模板')
            return
        # status: 0-没有执行,1-正在执行,2-执行成功并停止,3-执行失败停止
        self.status = 0 
        self.file_name = self.view.file_name()
        header_str = self.view.substr(self.header_region)
        self.blog_info = _parse_blog_info(header_str)
        # self.action: 1--新建,2--更新
        if not self.blog_info['blog_id']:
            self.action = 1 
        else:
            self.action = 2
        global blog_settings
        if not blog_settings:
            settings = _load_setting()
            blog_settings = {
                'login_name': settings.get('login_name'),
                'login_password': settings.get('login_password'),
                'xml_rpc_url': settings.get('xml_rpc_url'),
            }
        file_type = check_file_type(self.file_name)
        content = ''
        if file_type == F_MD:
            region = sublime.Region(0, len(self.view))
            content = self._markdown2html(self.view.substr(region))
        else:
            body_region = sublime.Region(self.header_region.end(), len(self.view))
            content = header_str + _plain2html(self.view.substr(body_region))
        self.post = { 'title': self.blog_info['title'],
                'description': content,
                'link': '',
                'author': blog_settings['login_name'],
                'categories': self.blog_info['categories'],
                'mt_keywords': ''
            }
        content = None
        self.server = xmlrpclib.ServerProxy(blog_settings['xml_rpc_url'], allow_none=True)
        self._pulish_async()

你可能感兴趣的:(Blog)