lepture / mistune-contrib

Contribution for mistune.
BSD 3-Clause "New" or "Revised" License
40 stars 17 forks source link

Examples or tutorial ? #5

Open depado opened 9 years ago

depado commented 9 years ago

Hi,

I find the documentation in the docstrings overly complicated and I can't seem to understand what's going on. I want to use the math/mathjax syntax in my markdown. Could you provide some example on how to achieve that ?

I already have a custom renderer for syntax highlighting, and I'd like to keep it that way :

class HighlightRenderer(mistune.Renderer):

    def block_code(self, code, lang=None):
        if not lang:
            lang = 'text'
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except:
            lexer = get_lexer_by_name('text', stripall=True)
        formatter = HtmlFormatter()
        return "{open_block}{formatted}{close_block}".format(
            open_block="<div class='code-highlight'>" if lang != 'text' else '',
            formatted=highlight(code, lexer, formatter),
            close_block="</div>" if lang != 'text' else ''
        )

    def table(self, header, body):
        return "<table class='table table-bordered table-hover'>" + header + body + "</table>"

Thanks a lot.

guyskk commented 8 years ago

I just meet problem with meta extension, I wrote like this:

Title: A Metadata DEMO
Author: Hsiaoming Yang

# Be Pythonic

xxx

but the result is:

>>> meta.parse(txt)[0]                                                 
{'Author': 'Hsiaoming Yang\n# Be Pythonic', 'Title': 'A Metadata DEMO'}
>>>         

then I wrote like this:

---
Title: A Metadata DEMO
Author: Hsiaoming Yang
---

# Be Pythonic

xxx

but the result is:

>>> meta.parse(txt)[0]                                                 
{}
>>>         

I wrote like this:

Title: A Metadata DEMO
Author: Hsiaoming Yang
---

# Be Pythonic

xxx

it works:

>>> meta.parse(txt)[0]
{'Author': 'Hsiaoming Yang', 'Title': 'A Metadata DEMO'}         
>>>      

The syntax confusing, and didn't has any documents. Maybe it's a bug!

depado commented 8 years ago

If you found a way to use it, maybe you could write up a small tutorial on how you did things. I wrote an article on the MathJax problem : http://depado.markdownblog.com/2015-09-29-mistune-parser-syntax-highlighter-mathjax-support-and-centered-images

yxy commented 7 years ago

@guyskk just to read the source, and you will know how it works.

guyskk commented 7 years ago

@yxy #7

yxy commented 7 years ago

@guyskk yeah, import yaml makes more scalable, but introduce another dependency also make more complicated. reminds me this jok: Someone ask a programer that he wants a banana, and the programer gives him a forest.

So, all I want is just a simple meta key-value info, here is what I try to do #13 , just to simply this solution.