mistletoe v0.7 Release Notes

Release Date: 2018-06-11 // over 3 years ago
  • 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\_innerimport reclass 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 SpanTokenimport reclass 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 omitteddef \_\_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 = Falsedef \_\_init\_\_(self, match\_obj): self.content = match\_obj.group(1)
    

    ๐Ÿ‘€ See the readme for more details.