diff options
Diffstat (limited to 'nikola/plugins/compile')
| -rw-r--r-- | nikola/plugins/compile/__init__.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/html.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/ipynb.py | 2 | ||||
| -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 | ||||
| -rw-r--r-- | nikola/plugins/compile/pandoc.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/php.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/__init__.py | 4 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/chart.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/doc.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/listing.py | 33 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/media.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/post_list.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/soundcloud.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/thumbnail.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/vimeo.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/youtube.py | 15 |
19 files changed, 77 insertions, 32 deletions
diff --git a/nikola/plugins/compile/__init__.py b/nikola/plugins/compile/__init__.py index bea2e3d..c3abcd4 100644 --- a/nikola/plugins/compile/__init__.py +++ b/nikola/plugins/compile/__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 diff --git a/nikola/plugins/compile/html.py b/nikola/plugins/compile/html.py index c69fd6b..ff7d37f 100644 --- a/nikola/plugins/compile/html.py +++ b/nikola/plugins/compile/html.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/ipynb.py b/nikola/plugins/compile/ipynb.py index d60f134..7d6e528 100644 --- a/nikola/plugins/compile/ipynb.py +++ b/nikola/plugins/compile/ipynb.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2013-2021 Damián Avila, Chris Warrick and others. +# Copyright © 2013-2022 Damián Avila, Chris Warrick 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/__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 diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py index 62d3e88..a43c8b0 100644 --- a/nikola/plugins/compile/pandoc.py +++ b/nikola/plugins/compile/pandoc.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/php.py b/nikola/plugins/compile/php.py index 347f222..d4c67dc 100644 --- a/nikola/plugins/compile/php.py +++ b/nikola/plugins/compile/php.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/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py index 082cae0..e5d3998 100644 --- a/nikola/plugins/compile/rest/__init__.py +++ b/nikola/plugins/compile/rest/__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 @@ -264,7 +264,7 @@ def add_node(node, visit_function=None, depart_function=None): """Register a Docutils node class. This function is completely optional. It is a same concept as - `Sphinx add_node function <http://sphinx-doc.org/extdev/appapi.html#sphinx.application.Sphinx.add_node>`_. + `Sphinx add_node function <https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_node>`_. For example:: diff --git a/nikola/plugins/compile/rest/chart.py b/nikola/plugins/compile/rest/chart.py index a950292..15ccee7 100644 --- a/nikola/plugins/compile/rest/chart.py +++ b/nikola/plugins/compile/rest/chart.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/rest/doc.py b/nikola/plugins/compile/rest/doc.py index 05b0ad2..1d88472 100644 --- a/nikola/plugins/compile/rest/doc.py +++ b/nikola/plugins/compile/rest/doc.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/rest/listing.py b/nikola/plugins/compile/rest/listing.py index f669b16..48dbe4c 100644 --- a/nikola/plugins/compile/rest/listing.py +++ b/nikola/plugins/compile/rest/listing.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 @@ -57,7 +57,8 @@ class CodeBlock(Directive): 'name': directives.unchanged, 'number-lines': directives.unchanged, # integer or None 'linenos': directives.unchanged, - 'tab-width': directives.nonnegative_int} + 'tab-width': directives.nonnegative_int, + 'emphasize-lines': directives.unchanged_required} has_content = True def run(self): @@ -103,7 +104,33 @@ class CodeBlock(Directive): else: anchor_ref = 'rest_code_' + uuid.uuid4().hex - formatter = utils.NikolaPygmentsHTML(anchor_ref=anchor_ref, classes=classes, linenos=linenos, linenostart=linenostart) + linespec = self.options.get('emphasize-lines') + if linespec: + try: + nlines = len(self.content) + hl_lines = utils.parselinenos(linespec, nlines) + if any(i >= nlines for i in hl_lines): + raise self.error( + 'line number spec is out of range(1-%d): %r' % + (nlines, self.options['emphasize-lines']) + ) + hl_lines = [x + 1 for x in hl_lines if x < nlines] + except ValueError as err: + raise self.error(err) + else: + hl_lines = None + + extra_kwargs = {} + if hl_lines is not None: + extra_kwargs['hl_lines'] = hl_lines + + formatter = utils.NikolaPygmentsHTML( + anchor_ref=anchor_ref, + classes=classes, + linenos=linenos, + linenostart=linenostart, + **extra_kwargs + ) out = pygments.highlight(code, lexer, formatter) node = nodes.raw('', out, format='html') diff --git a/nikola/plugins/compile/rest/media.py b/nikola/plugins/compile/rest/media.py index eb7a69e..6d0436d 100644 --- a/nikola/plugins/compile/rest/media.py +++ b/nikola/plugins/compile/rest/media.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/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py index d953372..1799790 100644 --- a/nikola/plugins/compile/rest/post_list.py +++ b/nikola/plugins/compile/rest/post_list.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2013-2021 Udo Spallek, Roberto Alsina and others. +# Copyright © 2013-2022 Udo Spallek, 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/rest/soundcloud.py b/nikola/plugins/compile/rest/soundcloud.py index 65d9e6b..87b1483 100644 --- a/nikola/plugins/compile/rest/soundcloud.py +++ b/nikola/plugins/compile/rest/soundcloud.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/rest/thumbnail.py b/nikola/plugins/compile/rest/thumbnail.py index 1cce086..6f10a7f 100644 --- a/nikola/plugins/compile/rest/thumbnail.py +++ b/nikola/plugins/compile/rest/thumbnail.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2014-2021 Pelle Nilsson and others. +# Copyright © 2014-2022 Pelle Nilsson 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/rest/vimeo.py b/nikola/plugins/compile/rest/vimeo.py index 1b1dbcc..b4f89ff 100644 --- a/nikola/plugins/compile/rest/vimeo.py +++ b/nikola/plugins/compile/rest/vimeo.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/rest/youtube.py b/nikola/plugins/compile/rest/youtube.py index 24220e5..de3f2fa 100644 --- a/nikola/plugins/compile/rest/youtube.py +++ b/nikola/plugins/compile/rest/youtube.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 @@ -48,7 +48,7 @@ class Plugin(RestExtension): CODE = """\ <div class="youtube-video{align}"> <iframe width="{width}" height="{height}" -src="https://www.youtube-nocookie.com/embed/{yid}?rel=0&wmode=transparent" +src="https://www.youtube-nocookie.com/embed/{yid}?rel=0&wmode=transparent{start_at}" frameborder="0" allow="encrypted-media" allowfullscreen ></iframe> </div>""" @@ -69,7 +69,8 @@ class Youtube(Directive): option_spec = { "width": directives.unchanged, "height": directives.unchanged, - "align": _align_choice + "align": _align_choice, + "start_at": directives.unchanged } def run(self): @@ -85,6 +86,14 @@ class Youtube(Directive): options['align'] = ' align-' + self.options['align'] else: options['align'] = '' + + start_at = options.get('start_at') + + if start_at: + options['start_at'] = '&start=' + start_at + else: + options['start_at'] = '' + return [nodes.raw('', CODE.format(**options), format='html')] def check_content(self): |
