Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Is it possible to support github flavored markdown #27

Closed
335g opened this Issue · 82 comments
@335g

I've tried to modified MarkdownPreview.py:

before

markdown_html = markdown.markdown(contents)

after

data = json.dumps({"text":contents, "mode":"gfm"})
url = "https://api.github.com/markdown"
value = urllib2.urlopen(url, data)
html = value.read()
markdown_html = markdown.markdown(html)

I can see html.
But I cannot use normal markdown preview in this case.

I think that I must support css too.

Do you have any plan to support github flavored markdown?

@revolunet
Owner

Thats indeed a very good idea, i didn't know that GH provide markdown in their API.

I think the better would be to create a separate plugin because

1) it will be slower
2) not everyboy wants his code to be sent to GH

So if you're ok with this, i can create that new plugin in the next days

@335g

Thank you for reply.

1) it will be slower
2) not everyboy wants his code to be sent to GH

I think so certainly.
It's a good idea, but I thought that it can branch by the argument (ex, User Setting) .

So if you're ok with this, i can create that new plugin in the next days

Thank you !!
I'm waiting in the hope.

@isimmons

Yes, thanks for the great plugin but while looking at a tutorial on md the first thing I looked at was github md and realized I can change these options in markdown pad(for windows) but would much rather do everything from ST2. If it's not too difficult, having a user setting to make the flavor optional would be awesome.

@revolunet
Owner

what do you think ? separate plugin or user settings ?

@tijptjik

User settings would be the way to go.
This feature would be much appreciated!

@335g

I think that separate plugin is good idea.

@isimmons

Yeah thinking about it, a separate plugin would be great so we can setup key bindings for each depending on which flavor we're using.

I was thinking user setting too but that would require editing the user setting every time we want to switch wouldn't it?

Thanks

@parkeryoung

Any progress on this?

@revolunet
Owner

Yes... the conversion works but i have problems to find a correct CSS.

Anyone knows if we can get the github markdown CSS from somewhere ? +@mojombo ?

@mihaipaun

You can also try and get in touch with @chenluois, who is the creator of Moo. Moo app has this setting where you can use GitHub flavoured markdown CSS: http://cl.ly/image/1x0a2p3r0G1U and perhaps he can point you in the right direction.

@parkeryoung

After a quick google search I found https://gist.github.com/2554919 I haven't looked at what the result of that css actually looks like though.

@parkeryoung

@revolunet have you taken a look at the CSS I posted to see if it is appropriate?

@revolunet revolunet closed this in ff23e40
@revolunet
Owner

Ho Hi :)
Just pushed an update. you can now set "parser": "github" in the settings to use the github markdown API and github.css.
Please confirm everything is ok for you all !
Cheers

@tijptjik

Seems there is still a problem.

When I try to preview:

cannot use github API to convert markdown. Please check your settings.

With the following settings:

{
    "browser": "default",
    "parser": "github",
    "css": "default"
}
@revolunet
Owner

thanks

can you please open the ST2 console and tell me if this works :

import json
@mihaipaun

Seems to be working for me.

@revolunet
Owner

@tijptjik would be nice if you could open your ST2 console and paste any traceback here

@tijptjik
@revolunet
Owner

@tijptjik ok i initialized the variable but this doesnt help with the github failed conversion.

do you have any proxy ?

the github APi is accessible via https://api.github.com/markdown

@tijptjik
@revolunet
Owner

hum... can you please comment the try/except clause from line 93 in MarkdownPreview.py to get the full traceback ?

@tijptjik
Traceback (most recent call last):
  File "./sublime_plugin.py", line 356, in run_
  File "./MarkdownPreview.py", line 95, in run
  File ".\urllib2.py", line 126, in urlopen
  File ".\urllib2.py", line 391, in open
  File ".\urllib2.py", line 414, in _open
  File ".\urllib2.py", line 369, in _call_chain
  File ".\urllib2.py", line 1194, in unknown_open
urllib2.URLError: <urlopen error unknown url type: https>

Could it have to do with the version of Python I'm working with?

>>> sys.version
'2.6.6 (r266:84292, Jun 16 2011, 22:27:44) \n[GCC 4.4.5]'
@revolunet
Owner

oops, look like SSL is not supported in Python installation.

im looking for solutions

@tijptjik
@revolunet
Owner

@tijptjik can you tell your linux distro plz ?

@tijptjik

Fedora 17

Linux qi 3.5.3-1.fc17.x86_64 #1 SMP Wed Aug 29 18:46:34 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Have kept global as clean as possible from python package, and use virtualenv to install any additional packages.

@revolunet
Owner

heres some pointers : http://www.xinotes.org/notes/note/628/

looks like you need to recompile python with SSL support :/

please keep us informed thanks

@tijptjik

Thanks for your help @revolunet.

Any idea why it seems like SublimeText is using a 2.6.6 interpreter when my global python intepreter is version 2.7.3?

@revolunet
Owner

I think sublime uses its own python version. i have to dig in

@tijptjik

Yes, I think so too :)

Seems like ST2 is packaged with a v2.6 intepreter. Wondering how come it's working on other systems. Is everyone else who has reported it working using OSX? Also wondering how I'd be able to replace the intepreter sublime was packaged with :L

@revolunet
Owner

works on OSX here

@parkeryoung

I have an Ubuntu setup at home and an OSX setup at work. At home it didn't work at first, but I think it was just because of the caching that sublime does because I fiddled with settings and then ultimately changed them back to what they were, and it works fine. And on OSX it worked fine right after I upgraded the package.

@revolunet
Owner

thanks for reporting

@parkeryoung

Thank you for making this change, it has made this package much more valuable to me.

@Kwlio

I have a similar issue. I get Cannot use github to convert markdown. SSL is not included in your Python installation..
I only get this (so far) if I use the % symbol in my markdown; removing the % stops the error.

@aleiphoenix

+1 to Cannot use github to convert markdown. SSL is not included in your Python installation.

may be escape the erb code or render them first?

@panglaoying

+1 to Cannot use github to convert markdown. SSL is not included in your Python installation.

@revolunet
Owner

Looks like the GitHub API has a slight problem, see example here : https://gist.github.com/3742011

I'll report this to github.

@revolunet
Owner

Also i removed percent signs temporary and added a better error message

@jorgebg

+1 to Cannot use github to convert markdown. SSL is not included in your Python installation

@ronjouch

+1 to Cannot use github to convert markdown. SSL is not included in your Python installation under Ubuntu

@revolunet
Owner

To all with "SSL problems" can you confirm you have an error when doing this in a python shell :

import _ssl

you should get an ImportError

@tijptjik
@revolunet
Owner

you're right. can you find it somewhere in the app directory ?

@tijptjik
@revolunet
Owner

Mmm so yes looks like the builtin python for Linux isnt built with SSL.

And the github API only accepts SSL so we're kinda stuck for this, sorry.

(Except setting up a proxy)

@Hubro

Can this be fixed? I can no longer use the Markdown preview plugin, which sucks.

@revolunet
Owner

@Codemonkey1991 : you can, just change "github" to "default" in your settings

@revolunet
Owner

github parser should not be the default, so i made the builtin the default in the settings.
please edit your settings guy

@Hubro

@revolunet: Thanks

@mindfulmonk

So is there a solution for Linux users to make github parser working?

@revolunet
Owner

No solution on this right now :/ the bundled Python does not include SSL and github API is ssl-only. So you have to use the builtin markdown parser

@revolunet
Owner

FYI the percent sign issue has been fixed, was due to missing header... (lol)

@aponxi

Still no news I suppose? No work-arounds found for ssl? If there's a practical solution to this please gist it :)

@revolunet
Owner

no known workaround for me sorry :/
ask the ST2 team here : http://sublimetext.userecho.com/topic/50801-bundle-python-ssl-module/

@aponxi

voted and such on the link you have provided, thank you for the fast reply! And keep up the good work! I love your plug-in!

@revolunet
Owner

@aponxi , thanks to @wbond , i bundled the SSL module right in the plugin. i have no linux with GUI currently so can you please tell us if it works now ?

You need to :

  • update the plugin
  • in the Markdown Preview settings, set linux_enable_ssl:true
  • restart ST2

Cheers and bigup to @wbond for the help :)

@aponxi

Oh this is indeed great news! Thank you @wbond and @revolunet !!

I have tried testing it, but had no luck. But I might be doing something wrong since I'm fairly new to Sublime Text 2.

What I have done is:

  • ctrl+shift+P uninstall markdown preview
  • ctrl+shift+P install markdown preview
  • go to preferences of the plugin and set linux_enable_ssl:true
  • ctrl+Q to quit sublime
  • start sublime, open a markdown file and ctrl+shift+P preview markdown in browser

I get the same error:

Imgur
Imgur
Imgur

@wbond

Just because the SSL module is loaded, does not mean the httplib module will use it. Likely the httplib module is being loaded before your package, and at that point the SSL module is not yet loaded.

You will probably have to play around with reloading httplib or possibly even urllib and urllib2 after you load ssl. I have not done this because I only use it for FTPS.

Another alternative to that is to look at the Package Control source and extract the Curl and Wget downloaders. Most linux installs come with one of those by default.

@revolunet
Owner

just added a force reload on the urllib2 module to test.. @aponxi , tell me if its better please.

if not, i'll go the curl way, like in the gist plugin or the package control source.

@aponxi

@revolunet Unfortunately it didn't work :( Still getting the same error after following the same steps: upgrade, set settings and restart ST2.

@aponxi

@revolunet Maybe the console output will help (although I'm not sure if its that important to load 0.9.8 since it successfully loads 1.0.0), I just noticed this error:

I added print to see which directory it looked for and couldn't find the _ssl module for 0.9.8 here on the third line:

for ssl_ver in ['0.9.8', '1.0.0', '10']:
        lib_path = os.path.join(arch_lib_path, 'libssl-' + ssl_ver)
        print "lib_path: " + lib_path
        try:
            m_info = imp.find_module('_ssl', [lib_path])
            m = imp.load_module('_ssl', *m_info)
            print 'Markdown Preview: successfully loaded _ssl module for libssl.so.%s' % ssl_ver
            break
        except (ImportError) as (e):
            print 'Markdown Preview: _ssl module import error - ' + str(e)
    if '_ssl' in sys.modules:
        plat_lib_path = os.path.join(sublime.packages_path(), 'Markdown Preview', 'lib',
            'linux')
        try:
            m_info = imp.find_module('ssl', [plat_lib_path])
            m = imp.load_module('ssl', *m_info)
        except (ImportError) as (e):
            print 'Markdown Preview: ssl module import error - ' + str(e)
    reload(urllib2)

The console output is:

Reloading plugin /home/nox/.config/sublime-text-2/Packages/Markdown Preview/MarkdownPreview.py
Markdown Preview: enabling custom linux ssl module
lib_path: /home/nox/.config/sublime-text-2/Packages/Markdown Preview/lib/linux-x64/libssl-0.9.8
Markdown Preview: _ssl module import error - libssl.so.0.9.8: cannot open shared object file: No such file or directory
lib_path: /home/nox/.config/sublime-text-2/Packages/Markdown Preview/lib/linux-x64/libssl-1.0.0
Markdown Preview: successfully loaded _ssl module for libssl.so.1.0.0
error: cannot use github API to convert markdown. SSL is not included in your Python installation

This is the folder structure of ssl libraries, it seemed legit to me however I might be missing something:

nox@green-flame:~/.config/sublime-text-2/Packages/Markdown Preview/lib/linux-x64$ ls -lartR
.:
total 20
drwxrwxr-x 2 nox nox 4096 Dec 19 11:30 libssl-1.0.0
drwxrwxr-x 2 nox nox 4096 Dec 19 11:30 libssl-0.9.8
drwxrwxr-x 2 nox nox 4096 Dec 19 11:30 libssl-10
drwxrwxr-x 5 nox nox 4096 Dec 19 11:30 ..
drwxrwxr-x 5 nox nox 4096 Dec 19 11:30 .

./libssl-1.0.0:
total 144
drwxrwxr-x 2 nox nox   4096 Dec 19 11:30 .
drwxrwxr-x 5 nox nox   4096 Dec 19 11:30 ..
-rw-rw-r-- 1 nox nox 128697 Dec 19 17:57 _ssl.so

./libssl-0.9.8:
total 124
drwxrwxr-x 2 nox nox   4096 Dec 19 11:30 .
drwxrwxr-x 5 nox nox   4096 Dec 19 11:30 ..
-rw-rw-r-- 1 nox nox 110450 Dec 19 17:57 _ssl.so

./libssl-10:
total 148
drwxrwxr-x 5 nox nox   4096 Dec 19 11:30 ..
drwxrwxr-x 2 nox nox   4096 Dec 19 11:30 .
-rw-rw-r-- 1 nox nox 132945 Dec 19 17:57 _ssl.so
@dusteye

sublime use a python26.zip in itself.
Use pythonbrew can easily solve this problem:

curl -kL http://xrl.us/pythonbrewinstall | bash

pythonbrew is now installed in $HOME/.pythonbrew
add this line at end of .bashrc

[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc

then use pythonbrew to install python 2.6

pythonbrew install --configure="--enable-unicode=ucs4 --with-zlib --with-ssl --with-threads --enable-share" 2.6

Note that the configure is mine, here just with ' --with-ssl' does matter
At last, make a link of the pythonbrew 2.6 lib to the sublime python2.6 lib

ln -s $HOME/.pythonbrew/pythons/Python-2.6/lib/python2.6 /Your_Sublime_Install_Path/lib/python2.6

Now sublime text will use python 2.6 lib under pythonbrew with ssl enabled.

@aponxi

It works!! Thank you @dusteye

Imgur

@dusteye

@aponxi glad it did help. In fact there are several sublime plugins can't work on ubuntu due to lack of python lib, pythonbrew is a relatively elegant choice

@aponxi

@dusteye I have one question, how does sublime know which python to use? I mean why does it choose the symlink we just brewed over the usual python26.zip ? What if I had anotther python lib symlink under sublime/lib, would it try to load both libs?

@dusteye

@aponxi Actually, the official document does not explain how it does deal with python26.zip and how to search python lib, but in sublime startup information(you cat get it in the console after sublime start) you can see that:

Py_GetProgramName(): sublime_text
Py_GetExecPrefix(): .
Py_GetProgramFullPath(): 
Py_GetPath(): ./lib/python26.zip:./lib/python2.6/:./lib/python2.6/plat-linux2:./lib/python2.6/lib-tk:./lib/python2.6/lib-old:./lib/python2.6/lib-dynload
Py_GetPythonHome(): .

I had made several test, no matter /lib/python2.6 exists or not, and no matter other version of python lib such as python2.7 exists, this startup information makes no difference.
It seems sublime hard coded './lib/python26.zip:./lib/python2.6/:./lib/python2.6/plat-linux2:./lib/python2.6/lib-tk:./lib/python2.6/lib-old:./lib/python2.6/lib-dynload' to the PYTHONPATH.

@aponxi

ah gotcha, thanks for the explanation @dusteye :thumbsup:

@revolunet
Owner

thanks @dusteye, you rock :+1: I'll add your protip to the README

@marcantonio

I just tried this on Ubuntu 12.10 and the building Python failed. It appears that others have had the same issue:

https://github.com/quarnster/SublimeClang/issues/35

The solution (towards the end off the page) is to run the same command that @dusteye posted, but with 2.6.7 rather than 2.6.

Just thought I'd mention it for everyone. Thanks guys!

@aponxi

@marcantonio Interesting indeed... So you get an error in sublime text? or when brewing python 2.6 ? Could you please specify the error you get for referencing in the future please? Thanks :)

@marcantonio

The error occurs when building python. However, this led to another problem. Apparently, newer versions of Ubuntu don't include support for SSLv2 because of security issues. So when building Python the _ssl module doesn't compile. .. However, pythonbrew includes a patch to address this, but only applies the patch on versions of python <= 2.6.5. This is hardcoded into pythonbrew. :rage:

tl;dr:

Run:

pythonbrew install --configure="--enable-unicode=ucs4 --with-zlib --with-ssl --with-threads --enable-share" 2.6.5

then:

ln -s $HOME/.pythonbrew/pythons/Python-2.6.5/lib/python2.6 /Your_Sublime_Install_Path/lib/python2.6

and everything comes up roses.

@aponxi

@marcantonio ah I see... I downgraded from 12.10 to 12.04 for things like that... Plus I was getting app crashes too frequently...

@OlivierBlanvillain OlivierBlanvillain referenced this issue in dotcypress/GitHubMarkdownPreview
Closed

The way GitHubMarkdownPreview supposed to work #2

@mrgamer

My own solution linux-agnostic, it's based off nginx

First of all i created a nginx site, the syntax shown below it's from Ubuntu 12.04

$ sudo gedit /etc/nginx/sites-available/github

Content of site

server {
        listen 80;
        server_name github.localhost;

        location / {
                proxy_set_header Host api.github.com;
                proxy_pass https://api.github.com/;
        }

        access_log      /var/log/nginx/github_access.log combined;
        error_log       /var/log/nginx/github_error.log error;
}

add this in /etc/hosts

127.0.0.1    github.localhost

remember to reboot nginx sudo service nginx restart

Install Markdown Preview for Sublime Text 3:

$ cd .config/sublime-text-3/Packages/
$ git clone https://github.com/revolunet/sublimetext-markdown-preview.git 'Markdown Preview'
$ cd 'Markdown Preview'
$ git checkout ST3

Edit MarkdownPreview.py

--- a/MarkdownPreview.py
+++ b/MarkdownPreview.py
@@ -178,7 +178,7 @@ class MarkdownPreviewCommand(sublime_plugin.TextCommand):
                 if github_oauth_token:
                     headers['Authorization'] = "token %s" % github_oauth_token
                 data = json.dumps(data).encode('utf-8')
-                url = "https://api.github.com/markdown"
+                url = "http://github.localhost/markdown"
                 sublime.status_message(url)
                 request = urllib.request.Request(url, data=data, headers=headers)
                 markdown_html = urllib.request.urlopen(request).read().decode('utf-8')

And..

HAVE FUN!

@geekuillaume

@mrgamer Don't forget to create a symbolic link in /etc/nginx/sites-enabled/ of your file /etc/nginx/sites-available/github to make it work

@zhouqianghfut

@mrgamer Thx a lot. I am a ST3 user too.

@PaBLoX-CL

I tried the nginx solution, and works partially.. urls are auto-linked for example, but the auto-linked references like

revolunet/sublimetext-markdown-preview#27

revolunet/sublimetext-markdown-preview#27

Doesn't work... it has to do with SSL?

@silvadev

@mrgamer The best solution. Leave the nginx to resolve HTTPS connections.

@noquierouser

I did what @dusteye commented, but still didn't work.

But looking at my terminal I found out this:

SFTP: enabling custom linux ssl module
SFTP: successfully loaded _ssl module for libssl.so.1.0.0

So maybe @wbond could give you a hand about it.

@mvalim

About the @mrgamer solution, if you already have Apache installed you can configure a reverse proxy instead of instaling nginx

<VirtualHost *:80>
ServerName github.localhost
SSLProxyEngine On
RequestHeader set Front-End-Https "On"
ProxyPass       /       https://api.github.com/
ProxyPassReverse    /       https://api.github.com/
Redirect Permanent  /       https://api.github.com/
CacheDisable *
<IfModule mod_deflate.c> 
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript application/xml application/xhtml+xml "application/x-javascript \n\n" "text/html \n\n"
    DeflateCompressionLevel   9
</IfModule>
</VirtualHost>
@tombh

I wrote this little bit of code to wrap curl. This way you don't have to mess about with a custom python install or proxying through your local web server. It's submitted as a Pull Request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.