GitHubMarkdownPreview icon indicating copy to clipboard operation
GitHubMarkdownPreview copied to clipboard

urlopen error [Errno 111] Connection refused

Open maishuguang opened this issue 9 years ago • 3 comments

When I press "ctrl+shift+g", error occurs as bellow: image

maishuguang avatar Aug 26 '16 08:08 maishuguang

Could you provide Sublime logs?

dotcypress avatar Aug 26 '16 17:08 dotcypress

Potentially related:

  • https://github.com/dotcypress/GitHubMarkdownPreview/issues/32
  • https://github.com/dotcypress/GitHubMarkdownPreview/issues/33

0xdevalias avatar Jan 25 '23 23:01 0xdevalias

The error I hit is while editing a document, that hasn't been saved to a file, and thus also isn't going to be part of a GitHub repo:

Error in GitHubMarkdownPreview package:

'NoneType' object has no attribute 'rfind'

Using Sublime Text (build 4143) on macOS Ventura


For what's it's worth, I'm pretty sure the problem is that the package assumes the markdown file exists in a git repo.

Exploring how this addon works, for my own benefit, but also to help others figure out where there errors may be occuring/why..

The command is defined here, and calls the github_markdown_preview function in the code: https://github.com/dotcypress/GitHubMarkdownPreview/blob/bafa0df006d05750f06614049953cd78b54e93c3/Default.sublime-commands#L3-L4

github_markdown_preview_command:

  • tries to get the repoName with repoName = get_github_repo_name(self.view.file_name())
  • which is later used to generate the html of the preview with html = generate_preview(self.view.substr(selection), repoName)
  • this html is then written to a temporary file (temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.html')), and opened in the web browser (webbrowser.open("file://" + temp_file.name))

https://github.com/dotcypress/GitHubMarkdownPreview/blob/bafa0df006d05750f06614049953cd78b54e93c3/GHMarkdownPreview.py#L64-L82

get_github_repo_name will return None if the filename is None; otherwise it will call git to try and parse the repo name from the git remote, when it's using HTTPS (not SSH):

https://github.com/dotcypress/GitHubMarkdownPreview/blob/bafa0df006d05750f06614049953cd78b54e93c3/GHMarkdownPreview.py#L36-L49

generate_preview:

  • calls the https://api.github.com/markdown API (either with urllib2, or curl when on linux (because "The python package included with sublime text for Linux is missing the ssl module (for technical reasons)")
    • it puts the git repo_name in the context field of the json body sent to the /markdown API
      • The repository context to use when creating references in gfm mode. For example, setting context to octo-org/octo-repo will change the text #42 into an HTML link to issue 42 in the octo-org/octo-repo repository.

  • returns the response, which appears to be a string containing the HTML from rendering the provided markdown

https://github.com/dotcypress/GitHubMarkdownPreview/blob/bafa0df006d05750f06614049953cd78b54e93c3/GHMarkdownPreview.py#L51-L62

The docs for GitHub's /markdown API endpoint are at:

  • https://docs.github.com/en/rest/markdown?apiVersion=2022-11-28#render-a-markdown-document

Originally posted by @0xdevalias in https://github.com/dotcypress/GitHubMarkdownPreview/issues/33#issuecomment-1404361635

0xdevalias avatar Jan 25 '23 23:01 0xdevalias