dotcypress / GitHubMarkdownPreview

Sublime Text 2/3 plugin for GitHub Flavored Markdown.
http://dotcypress.github.io/GitHubMarkdownPreview/
MIT License
71 stars 14 forks source link

There is error when pressing the shortcut "ctrl+shift+g" #33

Open tjliupeng opened 7 years ago

tjliupeng commented 7 years ago

Hi,

when I install this package, open an MD file, and press "ctrl+shift+g", get the error below at console:

error: Error in GitHubMarkdownPreview package:

''

What happens?

I use sublime Text 3.

dotcypress commented 7 years ago

Which OS do you use?

tjliupeng commented 7 years ago

I use windows 10. If need logs, where can I find the log files?

fadelm0 commented 7 years ago

It happens with me as well. Using sublime 3 build 3126 on windows 7 x64.

Tried both installing from package control and manually, as instructed on the main page.

The page renders fine in the browser, aside from a few characters that are not displayed correctly, such as the ' apostrophe and — em dash (but I don't know if it's related to this issue).

The error reads:

Error in GitHubMarkdownPreview package: [WinError 2] The system cannot find the file specified.

vladdeSV commented 7 years ago

Can confirm I have this issue too.

Windows 10 64-bit. Sublime Text 3, 3126

SteveVacasa commented 5 years ago

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.

zigmd commented 4 years ago

Doesn't work on Sublime Text (build 3211) on macOS

0xdevalias commented 1 year ago

Potentially related:

0xdevalias commented 1 year ago

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:

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:

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

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

0xdevalias commented 1 year ago

If you wanted to achieve similar to this, here is a hacky little command line script you could use, that will read the markdown from the clipboard (with pbpaste, so only works on macOS), calls the API using the gh CLI tool, encodes the html response in a data:// url, then opens that url in Chrome:

markdown=$(pbpaste)
output=$(gh api --method POST -H "Accept: application/vnd.github+json" /markdown -f text="$markdown")
base64_output=$(echo "$output" | base64)
data_url="data:text/html;base64,$base64_output"

echo data_url
open -a "Google Chrome" "$data_url"

It looks like there is already a gh extension written by @itspriddle that basically does the same thing (though doesn't encode it in a data:// URL nor open it in Chrome to preview: