extra.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """
  2. Extra.
  3. pymdown.extra
  4. A wrapper that emulate PHP Markdown Extra.
  5. Re-packages Python Markdowns 'extra' extensions,
  6. but substitutes a few extensions with PyMdown extensions:
  7. - fenced_code --> superfences
  8. - smartstrong --> betterem
  9. MIT license.
  10. Copyright (c) 2015 - 2017 Isaac Muse <isaacmuse@gmail.com>
  11. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  12. documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  13. the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  14. and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  15. The above copyright notice and this permission notice shall be included in all copies or substantial portions
  16. of the Software.
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  18. TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  20. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE.
  22. """
  23. from markdown import Extension
  24. extra_extensions = [
  25. 'pymdownx.betterem',
  26. 'pymdownx.superfences',
  27. 'markdown.extensions.footnotes',
  28. 'markdown.extensions.attr_list',
  29. 'markdown.extensions.def_list',
  30. 'markdown.extensions.tables',
  31. 'markdown.extensions.abbr',
  32. 'markdown.extensions.md_in_html'
  33. ]
  34. extra_extension_configs = {}
  35. class ExtraExtension(Extension):
  36. """Add various extensions to Markdown class."""
  37. def __init__(self, *args, **kwargs):
  38. """Initialize."""
  39. self.config = kwargs.pop('configs', {})
  40. self.config.update(extra_extension_configs)
  41. self.config.update(kwargs)
  42. def extendMarkdown(self, md):
  43. """Register extension instances."""
  44. md.registerExtensions(extra_extensions, self.config)
  45. def makeExtension(*args, **kwargs):
  46. """Return extension."""
  47. return ExtraExtension(*args, **kwargs)