Using Markdown2 #5

Open
wants to merge 6 commits into
from

Conversation

Projects
None yet
3 participants
@amrElroumy
  • I replaced markdown with Markdown2
  • Added a setting to enable markdown2 extras
  • Made some modifications in markdown.css to properly display tables and played a bit with the display of other elements.

amrElroumy added some commits Jun 19, 2012

* Replaced PythonMarkdown with python-markdown2 (a fast and complete …
…Python implementation of Markdown)

* Added Support for enabling extras in the MarkdownBuild.sublime-settings file and the corresponding code for python-markdown2 in MarkdownBuild.py
* Updated markdown.css to properly display tables and made other modifications
Moved markdown2 to a seperate folder
Added License file for markdown2
Updated the readme to mention how to use extras
Removed footnotes from the default extras
@amrElroumy

This comment has been minimized.

Show comment Hide comment
@amrElroumy

amrElroumy Jun 20, 2012

You should wait on pulling this; everything was working fine, but after upgrading to Sublimetext Dev Build 2203 - Windows 64 bit it started complaining about not being able to import unicodedata in markdown2.py.
I reverted to Dev Build 2200 and it went back to normal, until I can figure out the problem I advise you not to pull.

You should wait on pulling this; everything was working fine, but after upgrading to Sublimetext Dev Build 2203 - Windows 64 bit it started complaining about not being able to import unicodedata in markdown2.py.
I reverted to Dev Build 2200 and it went back to normal, until I can figure out the problem I advise you not to pull.

@erinata

This comment has been minimized.

Show comment Hide comment
@erinata

erinata Jun 20, 2012

Owner

I actually encounter the same problem too. Sorry that I didn't reply earlier but I do notice your pull request and want to send you a BIG THANKS for incorporating python-markdown2. Do you think I still need to keep PythonMarkdown as an option? Or python-markdown2 actually can do everything that PythonMarkdown can do so I can just remove it?

Owner

erinata commented Jun 20, 2012

I actually encounter the same problem too. Sorry that I didn't reply earlier but I do notice your pull request and want to send you a BIG THANKS for incorporating python-markdown2. Do you think I still need to keep PythonMarkdown as an option? Or python-markdown2 actually can do everything that PythonMarkdown can do so I can just remove it?

amrElroumy added some commits Jun 22, 2012

* Fixed the import issue that resulted from using markdown2 by puttin…
…g it in a seperate package and added a license file for markdown2

* Brought back markdown_python files in case user wants to use this implementation instead of python-markdown2
* Added functionality to pick which implementaiton of markdown to use with default to markdown2
* Updated markdown.css file to add specific styling for inline code
* Updated the readme file to include instructions on how to select markdown implementation and how to use markdown2's extensions
@amrElroumy

This comment has been minimized.

Show comment Hide comment
@amrElroumy

amrElroumy Jun 22, 2012

I believe that I've figured out the problem, I forgot to add the init.py for markdown2 when I put it in a seperate directory.

To answer your question, I quote trentm (author of markdown2):
"It was written to closely match the behaviour of the original Perl-implemented Markdown.pl."

And his tests show that his implementation is faster and produces correct output.

The downside though is that Markdown2 has less implemented extras than Markdown V2.1.1; compare this with this. So to be on the safe side maybe you could provide both implementations and let the users pick whichever they prefer. If you believe this is a sound solution, tell me and I'll make a new pull request that contains my latest 2 commits, which prompts the user to pick the implementation that suits him and uses this implementation to generate the html. If no version is specified, it defaults to Markdown2

There is one thing else to mention, there is an issue that I can't figure out a solution for yet:

Markdown2 Extras work just fine and don't cause any issues, however when I try to use some of Markdown's extensions as it is shown in its documentation, it throws the following exception:

Doing this:

markdown.markdown(contents, extensions=['extra', 'nl2br', 'headerid'])

Yields the following result:

Traceback (most recent call last):
File ".\sublime_plugin.py", line 339, in run_
File ".\MarkdownBuild.py", line 39, in run
  md = markdown.markdown(contents, extensions=['extra', 'nl2br', 'headerid'])
File ".\markdown_python\__init__.py", line 395, in markdown
  md = Markdown(*args, **kwargs)
File ".\markdown_python\__init__.py", line 134, in __init__
  configs=kwargs.get('extension_configs', {}))
File ".\markdown_python\__init__.py", line 166, in registerExtensions
  % (ext.__class__.__module__, ext.__class__.__name__))
ValueError: Extension "__builtin__.NoneType" must be of type: "markdown.Extension".

I tried this with the older version and V2.1.1 but both had the same result. So for now, I've disabled using extension in case the user specifies implementation of Markdown only, but it is working just fine for Markdown2.

In the meantime, I'll close this pull request and as I mentioned, if you want to pull the new commit I made tell me and I'll make a fresh pull request.

I believe that I've figured out the problem, I forgot to add the init.py for markdown2 when I put it in a seperate directory.

To answer your question, I quote trentm (author of markdown2):
"It was written to closely match the behaviour of the original Perl-implemented Markdown.pl."

And his tests show that his implementation is faster and produces correct output.

The downside though is that Markdown2 has less implemented extras than Markdown V2.1.1; compare this with this. So to be on the safe side maybe you could provide both implementations and let the users pick whichever they prefer. If you believe this is a sound solution, tell me and I'll make a new pull request that contains my latest 2 commits, which prompts the user to pick the implementation that suits him and uses this implementation to generate the html. If no version is specified, it defaults to Markdown2

There is one thing else to mention, there is an issue that I can't figure out a solution for yet:

Markdown2 Extras work just fine and don't cause any issues, however when I try to use some of Markdown's extensions as it is shown in its documentation, it throws the following exception:

Doing this:

markdown.markdown(contents, extensions=['extra', 'nl2br', 'headerid'])

Yields the following result:

Traceback (most recent call last):
File ".\sublime_plugin.py", line 339, in run_
File ".\MarkdownBuild.py", line 39, in run
  md = markdown.markdown(contents, extensions=['extra', 'nl2br', 'headerid'])
File ".\markdown_python\__init__.py", line 395, in markdown
  md = Markdown(*args, **kwargs)
File ".\markdown_python\__init__.py", line 134, in __init__
  configs=kwargs.get('extension_configs', {}))
File ".\markdown_python\__init__.py", line 166, in registerExtensions
  % (ext.__class__.__module__, ext.__class__.__name__))
ValueError: Extension "__builtin__.NoneType" must be of type: "markdown.Extension".

I tried this with the older version and V2.1.1 but both had the same result. So for now, I've disabled using extension in case the user specifies implementation of Markdown only, but it is working just fine for Markdown2.

In the meantime, I'll close this pull request and as I mentioned, if you want to pull the new commit I made tell me and I'll make a fresh pull request.

@erinata

This comment has been minimized.

Show comment Hide comment
@erinata

erinata Jun 22, 2012

Owner

I got bug reports of extension not working. But I cannot replicate the result. If it's working fine in Markdown2 that's great!

In this case I think it's good to just keep the markdown2. It is because this is a package for building markdown but it's also a template for people to add support to other format say textile or restructuredtext. It's always good to be simple when it comes to "template".

Thanks for making this work.

Owner

erinata commented Jun 22, 2012

I got bug reports of extension not working. But I cannot replicate the result. If it's working fine in Markdown2 that's great!

In this case I think it's good to just keep the markdown2. It is because this is a package for building markdown but it's also a template for people to add support to other format say textile or restructuredtext. It's always good to be simple when it comes to "template".

Thanks for making this work.

@mkosler

This comment has been minimized.

Show comment Hide comment
@mkosler

mkosler Jun 22, 2012

I am having the same problem with extensions not working. Using Sublime Beta Build 2181 on my work Windows 7 computer. Would really like to have some code syntax highlighting added.

mkosler commented Jun 22, 2012

I am having the same problem with extensions not working. Using Sublime Beta Build 2181 on my work Windows 7 computer. Would really like to have some code syntax highlighting added.

@amrElroumy

This comment has been minimized.

Show comment Hide comment
@amrElroumy

amrElroumy Jun 23, 2012

@erinata I'm glad I could help. This pull request now contains my latest 2 commits from my master branch, so you could try downloading it locally and testing it to make sure that everything works as you expect. If you have any comments or if you want me to remove any unnecessary complexity for it to be a simple template, tell me and I'll gladly work them out.

@mkosler, @erinata After I installed pygments using the following command in the command line:

pip install pygments

I wrote a script that used markdown2 as the following:

markdown2.markdown(markdownText, extras=["fenced-code-blocks"])

markdownText contained some markdown along with a code block fenced with ```:

# Header 1

* listitem1
* listitem2

a random paragraph with `inline code` embedded in it

```python
import string

# comment1
# comment2
# comment3

name = raw_input("Enter your name: ")
print "Hello " + name

for xr in xrange(20, 0, -3):
print "%d " % xr,
```

I ran this on the native python interpreter and it generated a highlighted html based on GFM

When I tried to do the same using MarkdownBuild and after a couple of hours of annoying debugging I figured out that the python interpreter that came along with sublimetext can't access pygments and import the necessary submodules found in it, that's why using the extra in markdown2 in my last commit doesn't yield any highlighted code, the code is just surrounded with <pre><code> tags and no highlighting occurs.

I tried putting pygments as a sub-module in MarkdownBuild but I stumbled upon some annoying import errors for the lexers implemented in pygments.

Pardon my clumsiness, but I'm not experienced in developing complex plugins in sublimetext that rely on external modules. If you have any suggestions on how to allow the python interpreter that comes along with sublimetext to view modules/eggs installed with the native interpreter, that would allow me to enable syntax highlighting for MarkdownBuild using Markdown2 and Pygments

@erinata I'm glad I could help. This pull request now contains my latest 2 commits from my master branch, so you could try downloading it locally and testing it to make sure that everything works as you expect. If you have any comments or if you want me to remove any unnecessary complexity for it to be a simple template, tell me and I'll gladly work them out.

@mkosler, @erinata After I installed pygments using the following command in the command line:

pip install pygments

I wrote a script that used markdown2 as the following:

markdown2.markdown(markdownText, extras=["fenced-code-blocks"])

markdownText contained some markdown along with a code block fenced with ```:

# Header 1

* listitem1
* listitem2

a random paragraph with `inline code` embedded in it

```python
import string

# comment1
# comment2
# comment3

name = raw_input("Enter your name: ")
print "Hello " + name

for xr in xrange(20, 0, -3):
print "%d " % xr,
```

I ran this on the native python interpreter and it generated a highlighted html based on GFM

When I tried to do the same using MarkdownBuild and after a couple of hours of annoying debugging I figured out that the python interpreter that came along with sublimetext can't access pygments and import the necessary submodules found in it, that's why using the extra in markdown2 in my last commit doesn't yield any highlighted code, the code is just surrounded with <pre><code> tags and no highlighting occurs.

I tried putting pygments as a sub-module in MarkdownBuild but I stumbled upon some annoying import errors for the lexers implemented in pygments.

Pardon my clumsiness, but I'm not experienced in developing complex plugins in sublimetext that rely on external modules. If you have any suggestions on how to allow the python interpreter that comes along with sublimetext to view modules/eggs installed with the native interpreter, that would allow me to enable syntax highlighting for MarkdownBuild using Markdown2 and Pygments

@amrElroumy

This comment has been minimized.

Show comment Hide comment
@amrElroumy

amrElroumy Jun 23, 2012

@erinata @mkosler I think I got my hands on the issue; the integrated python interpreter doesn't traverse the whole tree of submodules that come with pygments and as a result many submodules weren't compiled. This resulted in the annoying import errors.

In order to force the interpreter to compile the necessary submodules, I added pygments as a submodule and modified init.py of markdown2_python to force the interpreter to explore necessary modules:

try:
    import pygments.formatters.html
    from pygments.styles import default
    from pygments.lexers import *
except:
    print "Failed to import pygments' necessary modules"

You could check the new modifications in this branch. It is working fine with my installation of sublimetext, if you don't mind could you test it as well to make sure that I can safely merge to the main branch?

@erinata @mkosler I think I got my hands on the issue; the integrated python interpreter doesn't traverse the whole tree of submodules that come with pygments and as a result many submodules weren't compiled. This resulted in the annoying import errors.

In order to force the interpreter to compile the necessary submodules, I added pygments as a submodule and modified init.py of markdown2_python to force the interpreter to explore necessary modules:

try:
    import pygments.formatters.html
    from pygments.styles import default
    from pygments.lexers import *
except:
    print "Failed to import pygments' necessary modules"

You could check the new modifications in this branch. It is working fine with my installation of sublimetext, if you don't mind could you test it as well to make sure that I can safely merge to the main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment