From 6ded9db39463372e5205a36bea72d6de516ece69 Mon Sep 17 00:00:00 2001 From: Christian Hammond Date: Fri, 4 Nov 2016 16:57:38 -0700 Subject: Add support for partials and path segments for Handlebars. This introduces support for some missing features to the Handlebars lexer: Partials and path segments. Partials mostly appeared to work before, but the `>` in `{{> ... }}` would appear as a syntax error, as could other components of the partial. This change introduces support for: * Standard partials: `{{> partialName}}` * Partials with parameters: `{{> partialName varname="value"}}` * Ddynamic partials: `{{> (partialFunc)}}` * Ddynamic partials with lookups: `{{> (lookup ../path "partialName")}}` * Partial blocks: `{{> @partial-block}}` * Inline partials: `{{#*inline}}..{{/inline}}` It also introduces support for path segments, which can reference content in the current context or in a parent context. For instance, `this.name`, `this/name`, `./name`, `../name`, `this/name`, etc. These are all now tracked as variables. --- pygments/plugin.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 pygments/plugin.py (limited to 'pygments/plugin.py') diff --git a/pygments/plugin.py b/pygments/plugin.py new file mode 100644 index 00000000..b1f17449 --- /dev/null +++ b/pygments/plugin.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +""" + pygments.plugin + ~~~~~~~~~~~~~~~ + + Pygments setuptools plugin interface. The methods defined + here also work if setuptools isn't installed but they just + return nothing. + + lexer plugins:: + + [pygments.lexers] + yourlexer = yourmodule:YourLexer + + formatter plugins:: + + [pygments.formatters] + yourformatter = yourformatter:YourFormatter + /.ext = yourformatter:YourFormatter + + As you can see, you can define extensions for the formatter + with a leading slash. + + syntax plugins:: + + [pygments.styles] + yourstyle = yourstyle:YourStyle + + filter plugin:: + + [pygments.filter] + yourfilter = yourfilter:YourFilter + + + :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" +LEXER_ENTRY_POINT = 'pygments.lexers' +FORMATTER_ENTRY_POINT = 'pygments.formatters' +STYLE_ENTRY_POINT = 'pygments.styles' +FILTER_ENTRY_POINT = 'pygments.filters' + +def iter_entry_points(group_name): + try: + import pkg_resources + except ImportError: + return [] + + return pkg_resources.iter_entry_points(group_name) + +def find_plugin_lexers(): + for entrypoint in iter_entry_points(LEXER_ENTRY_POINT): + yield entrypoint.load() + + +def find_plugin_formatters(): + for entrypoint in iter_entry_points(FORMATTER_ENTRY_POINT): + yield entrypoint.name, entrypoint.load() + + +def find_plugin_styles(): + for entrypoint in iter_entry_points(STYLE_ENTRY_POINT): + yield entrypoint.name, entrypoint.load() + + +def find_plugin_filters(): + for entrypoint in iter_entry_points(FILTER_ENTRY_POINT): + yield entrypoint.name, entrypoint.load() -- cgit v1.2.1 From 00126a1401eefcf0280384d9bf59783e81db41ed Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 22 Jan 2017 18:38:11 +0100 Subject: Copyright update. --- pygments/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pygments/plugin.py') diff --git a/pygments/plugin.py b/pygments/plugin.py index b1f17449..7987d646 100644 --- a/pygments/plugin.py +++ b/pygments/plugin.py @@ -32,7 +32,7 @@ yourfilter = yourfilter:YourFilter - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ LEXER_ENTRY_POINT = 'pygments.lexers' -- cgit v1.2.1 From 5b8414636e8654c447b4e0204e204e86afd76faa Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 25 Jan 2017 07:58:50 +0100 Subject: PR#662: catch IOError from pkg_resources import --- pygments/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'pygments/plugin.py') diff --git a/pygments/plugin.py b/pygments/plugin.py index 7987d646..08d9b5b4 100644 --- a/pygments/plugin.py +++ b/pygments/plugin.py @@ -40,14 +40,16 @@ FORMATTER_ENTRY_POINT = 'pygments.formatters' STYLE_ENTRY_POINT = 'pygments.styles' FILTER_ENTRY_POINT = 'pygments.filters' + def iter_entry_points(group_name): try: import pkg_resources - except ImportError: + except (ImportError, IOError): return [] return pkg_resources.iter_entry_points(group_name) + def find_plugin_lexers(): for entrypoint in iter_entry_points(LEXER_ENTRY_POINT): yield entrypoint.load() -- cgit v1.2.1