Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with latest version of sublime #86

Closed
marius-cristian opened this issue Mar 20, 2019 · 3 comments
Closed

Incompatible with latest version of sublime #86

marius-cristian opened this issue Mar 20, 2019 · 3 comments

Comments

@marius-cristian
Copy link

Issue:
Cannot preview the markup. As I write the markup, there will be no preview.

Sublime version: Sublime Text Build 3200

OS: Ubuntu 16

StackTrace:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 593, in on_modified_async
    callback.on_modified_async(v)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MarkdownLivePreview.py", line 72, in on_modified_async
    self.update(view)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MarkdownLivePreview.py", line 64, in update
    show_html(view, preview)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MLPApi.py", line 76, in show_html
    html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MLPApi.py", line 40, in markdown2html
    html = '<style>\n{}\n</style>\n'.format(get_style(color_scheme))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/functions.py", line 131, in get_style
    css += pygments_from_theme(get_resource(color_scheme))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/functions.py", line 139, in get_resource
    return sublime.load_resource(resource)
  File "/opt/sublime_text/sublime.py", line 192, in load_resource
    raise IOError("resource not found")
OSError: resource not found
@dderiso
Copy link

dderiso commented Mar 26, 2019

It works with OSX Mojave and the latest Sublime.

@marius-cristian If you can, please copy and paste your User settings (not default settings) here as a response. (Preferences > Settings > opens up two panels, copy the right panel). That will be helpful to the devs here.

Possible solution: I think your color scheme might be the problem. Are you getting an "Error loading color scheme" popup when you start Sublime? If so, try using a default color theme (Preferences > color scheme) and the problem should go away.

Hope this helps!


For devs:

sublime.load_resource(resource) # line 139 in functions.py

has

resource = view.settings().get('color_scheme')

as its argument, which points to the "color_scheme" entry in User settings.

The issue is that the path to the "color_scheme" doesn't exist, which could mean that the file is located in some other place on the user's computer (for example in the Textmate application). Since it the file doesn't exist, the package thinks it's a system default. In this case, it's not a default, which is why the application is throwing an error. Seeing the user preferences will be helpful.

# functions.py
def get_resource(resource):
    if os.path.exists(os.path.join(sublime.packages_path(), '..', resource)):
        with open(os.path.join(sublime.packages_path(), '..', resource), encoding='utf-8') as fp:
            return fp.read()
    else:
        return sublime.load_resource(resource)

@marius-cristian
Copy link
Author

marius-cristian commented Mar 27, 2019

Hi,

User Settings:
{
	"font_size": 8,
	"ignored_packages":
	[
		"Rust",
		"Vintage"
	]
}

I get no errors when I open sublime. Just this little message: [16211408] get image_dir_name: None

Updated to the latest version of sublime.

I still get the error:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 593, in on_modified_async
    callback.on_modified_async(v)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MarkdownLivePreview.py", line 72, in on_modified_async
    self.update(view)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MarkdownLivePreview.py", line 64, in update
    show_html(view, preview)
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MLPApi.py", line 76, in show_html
    html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/MLPApi.py", line 40, in markdown2html
    html = '<style>\n{}\n</style>\n'.format(get_style(color_scheme))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/functions.py", line 131, in get_style
    css += pygments_from_theme(get_resource(color_scheme))
  File "/home/marius/.config/sublime-text-3/Installed Packages/MarkdownLivePreview.sublime-package/functions.py", line 139, in get_resource
    return sublime.load_resource(resource)
  File "/opt/sublime_text/sublime.py", line 192, in load_resource
    raise IOError("resource not found")
OSError: resource not found

After explicitly selecting a color scheme:
It works nicely (as in there are no errors, and can preview it the markup). I can confirm it works with the following ones:
Breakers, Celeste, Mariana, Monokai, Sixteen

After selecting a color scheme, the user preferences got updated and now they look like:

{
	"color_scheme": "Packages/Color Scheme - Default/Monokai.sublime-color-scheme",
	"font_size": 8,
	"ignored_packages":
	[
		"Rust",
		"Vintage"
	]
}

I would say the problem is solved with the following fix: One must explicitly select a color_scheme.

I would mark it as closed if by default you add a fallback such that when in the user settings there is no 'color_scheme' field, the default settings for the color scheme would be used (as there it is always present).

@dderiso
Copy link

dderiso commented Mar 28, 2019

@marius-cristian good suggestion. PR submitted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants