neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
839 stars 152 forks source link

AttributeError on markdownify #245

Closed Pyvonix closed 1 year ago

Pyvonix commented 1 year ago

Hi team,

I get an issue using your library that I did not meet before. I share with you a really simple use case and the full stack trace:

In [1]: from markdownx.utils import markdownify

In [2]: markdownify('**Yay** GitHub')          # Example in markdown wiki
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [2], line 1
----> 1 markdownify('**Hello** GitHub')

File ~/.virtualenvs/venv/lib/python3.10/site-packages/markdownx/utils.py:22, in markdownify(content)
     13 def markdownify(content):
     14     """
     15     Trans-compiles Markdown text to HTML.
     16 
   (...)
     20     :rtype: str
     21     """
---> 22     md = markdown(
     23         text=content,
     24         extensions=MARKDOWNX_MARKDOWN_EXTENSIONS,
     25         extension_configs=MARKDOWNX_MARKDOWN_EXTENSION_CONFIGS
     26     )
     27     return md

File ~/.virtualenvs/venv/lib/python3.10/site-packages/markdown/core.py:387, in markdown(text, **kwargs)
    372 """Convert a markdown string to HTML and return HTML as a unicode string.
    373 
    374 This is a shortcut function for `Markdown` class to cover the most
   (...)
    384 
    385 """
    386 md = Markdown(**kwargs)
--> 387 return md.convert(text)

File ~/.virtualenvs/venv/lib/python3.10/site-packages/markdown/core.py:268, in Markdown.convert(self, source)
    266 # Run the tree-processors
    267 for treeprocessor in self.treeprocessors:
--> 268     newRoot = treeprocessor.run(root)
    269     if newRoot is not None:
    270         root = newRoot

File ~/.virtualenvs/venv/lib/python3.9/site-packages/markdown/treeprocessors.py:367, in InlineProcessor.run(self, tree, ancestors)
    364 text = child.text
    365 child.text = None
    366 lst = self.__processPlaceholders(
--> 367     self.__handleInline(text), child
    368 )
    369 for item in lst:
    370     self.parent_map[item[0]] = child

File ~/.virtualenvs/venv/lib/python3.10/site-packages/markdown/treeprocessors.py:127, in InlineProcessor.__handleInline(self, data, patternIndex)
    125 count = len(self.inlinePatterns)
    126 while patternIndex < count:
--> 127     data, matched, startIndex = self.__applyPattern(
    128         self.inlinePatterns[patternIndex], data, patternIndex, startIndex
    129     )
    130     if not matched:
    131         patternIndex += 1

File ~/.virtualenvs/venv/lib/python3.10/site-packages/markdown/treeprocessors.py:258, in InlineProcessor.__applyPattern(self, pattern, data, patternIndex, startIndex)
    242 """
    243 Check if the line fits the pattern, create the necessary
    244 elements, add it to stashed_nodes.
   (...)
    254 
    255 """
    256 new_style = isinstance(pattern, inlinepatterns.InlineProcessor)
--> 258 for exclude in pattern.ANCESTOR_EXCLUDES:
    259     if exclude.lower() in self.ancestors:
    260         return data, False, 0

AttributeError: 'str' object has no attribute 'ANCESTOR_EXCLUDES'

Version: Python 3.10.8+ Markdown 3.4.1 + django-markdownx 4.0.0b1 Test in other environment with Python 3.9.2 + Markdown 3.3.6 + django-markdownx 4.0.0b1 and get the same error.

Hoping to get a response and a patch from you. Thanks for your great extension.

Pyvonix commented 1 year ago

Never mind.

After deeper analysis, the python-markdown syntax have change to "load" custom widget/tag in version 3.4 with breaking change. It's not possible to use anymore the .add, we should consider use .register. But migrating from one to the other isn't as simple as changing one method for another, and some custom widget/tag crash when they are loaded through MARKDOWNX_MARKDOWN_EXTENSIONS.

Be aware to read the updated documentation or Python-Markdown 3.4 release notes.

Closing.