from markdown.extensions import Extension
from markdown_i18n.parser import I18NTreeProcessor


class I18NExtension(Extension):

    def __init__(self, **kwargs):
        self.config = {
            'i18n_lang': ['en_US', 'Locale'],
            'i18n_dir': ['', 'Path to get the translations and']
        }
        self.toc_found = False
        self.md = None
        super(I18NExtension, self).__init__(**kwargs)

    def extendMarkdown(self, md):
        md.registerExtension(self)
        md.treeprocessors.register(
            I18NTreeProcessor(md, self), 'i18n', 200)
        self.md = md

    def reset(self):
        if not self.toc_found and 'toc' in self.md.treeprocessors:
            #self.md.treeprocessors.link('i18n', '<toc')
            self.toc_found = True

@@ -354,16 +354,42 @@
  = None%0A
+        self.priority = 1%0A
         
@@ -434,16 +434,16 @@
 kwargs)%0A
-
 %0A    def
@@ -593,11 +593,21 @@
 n', 
-200
+self.priority
 )%0A  
@@ -730,9 +730,8 @@
     
-#
 self
@@ -753,19 +753,69 @@
 ors.
-link('i18n'
+add(%0A                'i18n', I18NTreeProcessor(self.md, self)
 , '%3C

Fix link previous to TOC and Fix priority