diff options
Diffstat (limited to 'nikola/plugins/compile/markdown')
| -rw-r--r-- | nikola/plugins/compile/markdown/__init__.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/markdown/mdx_gist.py | 15 | ||||
| -rw-r--r-- | nikola/plugins/compile/markdown/mdx_nikola.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/markdown/mdx_podcast.py | 5 |
4 files changed, 21 insertions, 12 deletions
diff --git a/nikola/plugins/compile/markdown/__init__.py b/nikola/plugins/compile/markdown/__init__.py index 46b2e6e..31a57d9 100644 --- a/nikola/plugins/compile/markdown/__init__.py +++ b/nikola/plugins/compile/markdown/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2021 Roberto Alsina and others. +# Copyright © 2012-2022 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -33,13 +33,20 @@ import threading from nikola import shortcodes as sc from nikola.plugin_categories import PageCompiler -from nikola.utils import makedirs, req_missing, write_metadata, LocaleBorg, map_metadata +from nikola.utils import makedirs, req_missing, write_metadata, LocaleBorg, map_metadata, NikolaPygmentsHTML try: from markdown import Markdown except ImportError: Markdown = None +# Override Pygments formatter for Markdown. +try: + import markdown.extensions.codehilite + markdown.extensions.codehilite.get_formatter_by_name = lambda _, **args: NikolaPygmentsHTML(**args) +except ImportError: + pass + class ThreadLocalMarkdown(threading.local): """Convert Markdown to HTML using per-thread Markdown objects. diff --git a/nikola/plugins/compile/markdown/mdx_gist.py b/nikola/plugins/compile/markdown/mdx_gist.py index f6ce20a..fc24d34 100644 --- a/nikola/plugins/compile/markdown/mdx_gist.py +++ b/nikola/plugins/compile/markdown/mdx_gist.py @@ -76,19 +76,19 @@ Error Case: non-existent file: """ import requests +import xml.etree.ElementTree as etree from nikola.plugin_categories import MarkdownExtension from nikola.utils import get_logger try: from markdown.extensions import Extension - from markdown.inlinepatterns import Pattern + from markdown.inlinepatterns import InlineProcessor from markdown.util import AtomicString - from markdown.util import etree except ImportError: # No need to catch this, if you try to use this without Markdown, # the markdown compiler will fail first - Extension = Pattern = object + Extension = InlineProcessor = AtomicString = object LOGGER = get_logger('compile_markdown.mdx_gist') @@ -112,12 +112,12 @@ class GistFetchException(Exception): status_code, url) -class GistPattern(Pattern): +class GistPattern(InlineProcessor): """InlinePattern for footnote markers in a document's body text.""" def __init__(self, pattern, configs): """Initialize the pattern.""" - Pattern.__init__(self, pattern) + InlineProcessor.__init__(self, pattern) def get_raw_gist_with_filename(self, gist_id, filename): """Get raw gist text for a filename.""" @@ -139,8 +139,9 @@ class GistPattern(Pattern): return resp.text - def handleMatch(self, m): + def handleMatch(self, m, _): """Handle pattern match.""" + # The third arg is "data", wider context around the match; we don't need it. gist_id = m.group('gist_id') gist_file = m.group('filename') @@ -170,7 +171,7 @@ class GistPattern(Pattern): warning_comment = etree.Comment(' WARNING: {0} '.format(e.message)) noscript_elem.append(warning_comment) - return gist_elem + return (gist_elem, m.start(0), m.end(0)) class GistExtension(MarkdownExtension, Extension): diff --git a/nikola/plugins/compile/markdown/mdx_nikola.py b/nikola/plugins/compile/markdown/mdx_nikola.py index 255ea86..af30956 100644 --- a/nikola/plugins/compile/markdown/mdx_nikola.py +++ b/nikola/plugins/compile/markdown/mdx_nikola.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2021 Roberto Alsina and others. +# Copyright © 2012-2022 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/compile/markdown/mdx_podcast.py b/nikola/plugins/compile/markdown/mdx_podcast.py index 647ee1f..e003f40 100644 --- a/nikola/plugins/compile/markdown/mdx_podcast.py +++ b/nikola/plugins/compile/markdown/mdx_podcast.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright © 2013-2021 Michael Rabbitt, Roberto Alsina and others. +# Copyright © 2013-2022 Michael Rabbitt, Roberto Alsina and others. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the @@ -36,11 +36,12 @@ Basic Example: <p><audio controls=""><source src="https://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p> """ +import xml.etree.ElementTree as etree + from nikola.plugin_categories import MarkdownExtension try: from markdown.extensions import Extension from markdown.inlinepatterns import Pattern - from markdown.util import etree except ImportError: # No need to catch this, if you try to use this without Markdown, # the markdown compiler will fail first |
