timonwong / OmniMarkupPreviewer

Sublime Text 2&3 plugin to live preview markup files, supported (not limited to) markup formats are markdown, reStructuredText, WikiCreole and textile.
MIT License
502 stars 75 forks source link

fix: no need to encode arguments in python 3.x #120

Open ansiz opened 7 years ago

ansiz commented 7 years ago

It seems there is no need to encode arguments in python 3.x, it reports errors on Windows while I set "browser_command": ["C:\Program Files (x86)\Google\Chrome\Application\chrome.exe","{url}"],:

OmniMarkupPreviewer: [ERROR] Error while launching user defined web browser
  Traceback (most recent call last):
    File "C:\Users\Ansiz\AppData\Roaming\Sublime Text 3\Packages\OmniMarkupPreviewer\OmniMarkupPreviewer.py", line 81, in launching_web_browser_for_url
    subprocess.Popen(browser_command)
    File "./python3.3/subprocess.py", line 819, in __init__
    File "./python3.3/subprocess.py", line 1063, in _execute_child
    File "./python3.3/subprocess.py", line 632, in list2cmdline
  TypeError: Type str doesn't support the buffer API
duoluoxiaosheng commented 5 years ago

I have the same problem. Have you solved it?

ansiz commented 5 years ago

I have the same problem. Have you solved it?

yep, just modify the file as I commited

duoluoxiaosheng commented 5 years ago

It dosen't work!
My system is Windows 10
2

1

ansiz commented 5 years ago

@duoluoxiaosheng 把你修改过的代码发来看一下吧,看看第80行报错的代码是什么内容

duoluoxiaosheng commented 5 years ago

我只是在用户配置文件添加了"browser_command"
并没有修改程序文件

def launching_web_browser_for_url(url, success_msg_default=None, success_msg_user=None):
    try:
        setting = Setting.instance()
        if setting.browser_command:
            browser_command = [os.path.expandvars(arg).format(url=url)
                               for arg in setting.browser_command]

            if os.name == 'nt':
                # unicode arguments broken under windows
                encoding = locale.getpreferredencoding()
                browser_command = [arg.encode(encoding) for arg in browser_command]

            subprocess.Popen(browser_command)
            if success_msg_user:
                sublime.status_message(success_msg_user)
        else:
            # Default web browser
            desktop.open(url)
            if success_msg_default:
                sublime.status_message(success_msg_default)
    except:
        if setting.browser_command:
            log.exception('Error while launching user defined web browser')
        else:
            log.exception('Error while launching default web browser')

第80行就是 subprocess.Popen(browser_command)

其中subprocessimport 的一个包

ansiz commented 5 years ago

@duoluoxiaosheng 那你自己改一下吧,我写得很清楚呀,需要修改的地方在我提交的文件中,你照着改那么一行就行了

duoluoxiaosheng commented 5 years ago

好了,可以了,谢谢你