Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Is it possible to support github flavored markdown #27

Closed
335g opened this issue Aug 12, 2012 · 82 comments
Closed

Is it possible to support github flavored markdown #27

335g opened this issue Aug 12, 2012 · 82 comments

Comments

@335g
Copy link

335g commented Aug 12, 2012

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
Copy link
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
Copy link
Author

335g commented Aug 13, 2012

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
Copy link

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
Copy link
Owner

what do you think ? separate plugin or user settings ?

@tijptjik
Copy link

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

@335g
Copy link
Author

335g commented Aug 14, 2012

I think that separate plugin is good idea.

@isimmons
Copy link

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
Copy link

Any progress on this?

@revolunet
Copy link
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
Copy link

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
Copy link

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.

revolunet pushed a commit that referenced this issue Sep 8, 2012
Partially fix issue #27: support Github Flavored Markdown
@parkeryoung
Copy link

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

@revolunet
Copy link
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
Copy link

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
Copy link
Owner

thanks

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

import json

@mihaipaun
Copy link

Seems to be working for me.

@revolunet
Copy link
Owner

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

@tijptjik
Copy link

ah yes! That's more useful.

error: cannot use github API to convert markdown. Please check your
settings.
Traceback (most recent call last):
  File "./sublime_plugin.py", line 356, in run_
  File "./MarkdownPreview.py", line 117, in run
UnboundLocalError: local variable 'markdown_html' referenced before
assignment

The plugin updated with Package Control is the latest version with GFM support right?

@revolunet
Copy link
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
Copy link

No proxy, and I can access GitHub API just fine from a REST console.

@revolunet
Copy link
Owner

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

@tijptjik
Copy link

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
Copy link
Owner

oops, look like SSL is not supported in Python installation.
im looking for solutions

@tijptjik
Copy link

is there a package I could install with pip that would solve this problem?
Or, why does it work for some other peeps :)?

@revolunet
Copy link
Owner

@tijptjik can you tell your linux distro plz ?

@tijptjik
Copy link

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
Copy link
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
Copy link

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?

@wbond
Copy link

wbond commented Dec 19, 2012

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
Copy link
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
Copy link
Contributor

aponxi commented Dec 19, 2012

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

@aponxi
Copy link
Contributor

aponxi commented Dec 21, 2012

@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
Copy link

dusteye commented Dec 31, 2012

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
Copy link
Contributor

aponxi commented Dec 31, 2012

It works!! Thank you @dusteye

Imgur

@dusteye
Copy link

dusteye commented Dec 31, 2012

@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
Copy link
Contributor

aponxi commented Dec 31, 2012

@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
Copy link

dusteye commented Dec 31, 2012

@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
Copy link
Contributor

aponxi commented Dec 31, 2012

ah gotcha, thanks for the explanation @dusteye 👍

@revolunet
Copy link
Owner

thanks @dusteye, you rock 👍 I'll add your protip to the README

@marcantonio
Copy link

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
Copy link
Contributor

aponxi commented Jan 14, 2013

@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
Copy link

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. 😡

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
Copy link
Contributor

aponxi commented Jan 14, 2013

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

@colthreepv
Copy link

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
Copy link

@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
Copy link

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

@pablox-cl
Copy link

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

#27

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

@silvadev
Copy link

silvadev commented Oct 7, 2013

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

@noquierouser
Copy link

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
Copy link

mvalim commented Oct 16, 2013

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 added a commit to tombh/sublimetext-markdown-preview that referenced this issue Oct 29, 2013
@tombh
Copy link
Contributor

tombh commented Oct 29, 2013

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests