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
500 stars 74 forks source link

404 error on preview RST file. ( temporary fix it) #134

Open YaKazama opened 5 years ago

YaKazama commented 5 years ago

PS:

  1. There is no docutils module in the default python3.3.zip. used the python3.3 command to install it yourself and move the docutils module into python3.3.zip.
  2. If you want to preview md file, you can remove "strikeout", "subscript", "superscript". Or see: #85 .
  3. Version of OmniMarkupPreviewer: v3.0.0.
  4. Version of docutils: 0.10, if you are 0.14, see: Temporary repair methods -> step 1.

I get the following error in the browser:

Error: 404 Not Found
Sorry, the requested URL 'http://127.0.0.1:51005/view/27' caused an error:

'buffer_id(27) is not valid (closed or unsupported file format)'

**NOTE:** If you run multiple instances of Sublime Text, you may want to adjust
the `server_port` option in order to get this plugin work again.

This is what I see in the console:

  Traceback (most recent call last):
    File "/opt/sublime_text/Data/Packages/OmniMarkupPreviewer/OmniMarkupLib/RendererManager.py", line 266, in render_text
    rendered_text = renderer.render(text, filename=filename)
    File "/opt/sublime_text/Data/Packages/OmniMarkupPreviewer/OmniMarkupLib/Renderers/RstRenderer.py", line 51, in render
    text, writer=writer, settings_overrides=settings_overrides
    File "/opt/sublime_text/python3.3.zip/docutils/core.py", line 448, in publish_parts
    enable_exit_status=enable_exit_status)
    File "/opt/sublime_text/python3.3.zip/docutils/core.py", line 662, in publish_programmatically
    output = pub.publish(enable_exit_status=enable_exit_status)
    File "/opt/sublime_text/python3.3.zip/docutils/core.py", line 219, in publish
    output = self.writer.write(self.document, self.destination)
    File "/opt/sublime_text/python3.3.zip/docutils/writers/__init__.py", line 80, in write
    self.translate()
    File "/opt/sublime_text/python3.3.zip/docutils/writers/html4css1/__init__.py", line 176, in translate
    self.output = self.apply_template()
    File "/opt/sublime_text/python3.3.zip/docutils/writers/html4css1/__init__.py", line 185, in apply_template
    template_file = open(self.document.settings.template, 'rb')
  NotADirectoryError: [Errno 20] Not a directory: '/opt/sublime_text/python3.3.zip/docutils/writers/html4css1/template.txt'

Temporary repair methods are as follows:

  1. Make sure docutils 0.10 exists in python3.3.zip. If you are using docutils 0.14 , you must modify Writer.default_stylesheet in OmniMarkupPreviewer/OmniMarkupLib/Renderers/RstRenderer.py to Writer.default_stylesheets[0].
  2. cp docutils/writers/html4css1/template.txt to /path/to/the/file/template.txt.
  3. Modify the code in docutils/writers/html4css1/__init__.py(about 178 lines, function: apply_template) to:
    def apply_template(self):
        _f = self.document.settings.template
        try:
            template_file = open(_f, 'rb')
        except NotADirectoryError as e:
            _f = "/".join(_f.split("/")[:3]) + "/" + "Data/Packages/User/OmniMarkupPreviewer/public/template.txt"
            template_file = open(_f, 'rb')
        #template_file = open(self.document.settings.template, 'rb')                                                                                                                                                                          
        template = str(template_file.read(), 'utf-8')
        print(template)
        template_file.close()
        subs = self.interpolation_dict()
        print(subs)
        return template % subs
  4. Repackage python3.3.zip and overwrite the original file.
    zip -q -r python3.3.zip .
    mv python3.3.zip /opt/sublime_text/
  5. Restart the sublime.

OK, you can preview RST file in browser.