Skip to content

Version 0.7

Compare
Choose a tag to compare
@miyuchina miyuchina released this 11 Jun 00:18
· 238 commits to master since this release

Warning: this is a release that breaks backwards compatibility in non-trivial ways (hopefully for the last time!) Read the full release notes if you are updating from a previous version.

Features:

  • all tests passing in CommonMark test suite (finally! 🎉)
  • allow specifying span token precedence levels;
  • new and shiny span_tokenizer.tokenize.

Fixed:

  • well, all the CommonMark test cases..
  • ASTRenderer crashes on tables with headers (#48, thanks @timfox456!)

Where I break backwards compatibility:

Previously span-level tokens need to have their children attribute manually specified. This is no longer the case, as the children attribute will automatically be set based on the class variable parse_group, which correspond to the regex match group in which child tokens might occur.

As an example, previously GithubWiki is implemented as this:

from mistletoe.span_token import SpanToken, tokenize_inner
import re

class GithubWiki(SpanToken):
    pattern = re.compile(r'...')
    def __init__(self, match_obj):
        super().__init__(match_obj) 
        # alternatively, self.children = tokenize_inner(match_obj.group(1))
        self.target = match_obj.group(2)

Now we can write:

from mistletoe.span_token import SpanToken
import re

class GithubWiki(SpanToken):
    pattern = re.compile(r'...')
    parse_inner = True  # default value, can be omitted
    parse_group = 1  # default value, can be omitted
    precedence = 5  # default value, can be omitted
    def __init__(self, match_obj):
        self.target = match_obj.group(2)

If we have a span token that does not need further parsing, we can write:

class Foo(SpanToken):
    pattern = re.compile(r'(foo)')
    parse_inner = False
    def __init__(self, match_obj):
        self.content = match_obj.group(1)

See the readme for more details.