Open tjliupeng opened 7 years ago
Which OS do you use?
I use windows 10. If need logs, where can I find the log files?
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.
Can confirm I have this issue too.
Windows 10 64-bit. Sublime Text 3, 3126
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.
Doesn't work on Sublime Text (build 3211) on macOS
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
:
repoName
with repoName = get_github_repo_name(self.view.file_name())
html
of the preview with html = generate_preview(self.view.substr(selection), repoName)
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)
)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):
generate_preview
:
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)"
)
repo_name
in the context
field of the json body
sent to the /markdown
APIThe repository context to use when creating references in
gfm
mode. For example, setting context toocto-org/octo-repo
will change the text#42
into an HTML link to issue42
in theocto-org/octo-repo
repository.
The docs for GitHub's /markdown
API endpoint are at:
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:
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.