A => Pipfile +12 -0
@@ 0,0 1,12 @@
+[[source]]
+name = "pypi"
+url = "https://pypi.org/simple"
+verify_ssl = true
+
+[dev-packages]
+
+[packages]
+pygments = "*"
+
+[requires]
+python_version = "3.6"
A => Pipfile.lock +29 -0
@@ 0,0 1,29 @@
+{
+ "_meta": {
+ "hash": {
+ "sha256": "4fef9e909141947fb573b0345f2129099de0f89c3f36a5b8164a15fcc0fea9e8"
+ },
+ "pipfile-spec": 6,
+ "requires": {
+ "python_version": "3.6"
+ },
+ "sources": [
+ {
+ "name": "pypi",
+ "url": "https://pypi.org/simple",
+ "verify_ssl": true
+ }
+ ]
+ },
+ "default": {
+ "pygments": {
+ "hashes": [
+ "sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127",
+ "sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297"
+ ],
+ "index": "pypi",
+ "version": "==2.4.2"
+ }
+ },
+ "develop": {}
+}
A => pyvenv.cfg +3 -0
@@ 0,0 1,3 @@
+home = /Users/matt/.pyenv/versions/3.6.1/bin
+include-system-site-packages = false
+version = 3.6.1
A => setup.py +33 -0
@@ 0,0 1,33 @@
+from setuptools import setup
+
+
+setup(
+ name='Liquid Highlight',
+ version='1.0.0',
+ author='Matthew Schinckel',
+ author_email='matt@schinckel.net',
+ description="Preprocess liquid template highlight blocks in markdown files.",
+ # long_description=open('README.rst').read(),
+ packages=['liquid_highlight'],
+ url='https://bitbucket.org/schinckel/liquid-hightlight',
+ entry_points={
+ 'console_scripts': [
+ 'liquid_highlight = liquid_highlight.__main__:main',
+ ]
+ },
+ install_requires=[
+ 'pygments'
+ ],
+ python_requires=">3.6",
+ license='MIT',
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: End Users/Desktop',
+ 'License :: OSI Approved :: MIT License',
+ 'Operating System :: MacOS :: MacOS X',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.6',
+ 'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ ]
+)
A => src/liquid_highlight/__init__.py +0 -0
A => src/liquid_highlight/__main__.py +6 -0
@@ 0,0 1,6 @@
+import sys
+
+from .highlight import highlight_all
+
+def main():
+ sys.stdout.write(highlight_all(sys.stdin.read()))
No newline at end of file
A => src/liquid_highlight/highlight.py +24 -0
@@ 0,0 1,24 @@
+import re
+
+from pygments.lexers import get_lexer_by_name
+import pygments
+from pygments.formatters.html import HtmlFormatter
+
+
+BLOCK = re.compile(
+ r'{% highlight (?P<language>.*?) %}\n(?P<code>.*?)\n{% endhighlight %}',
+ re.DOTALL
+)
+
+def highlight_block(match):
+ data = match.groupdict()
+ formatter = HtmlFormatter(
+ noclasses=True,
+ linenos='linenos' in data
+ )
+ lexer = get_lexer_by_name(data['language'], stripall=True)
+ return pygments.highlight(data['code'], lexer, formatter)
+
+
+def highlight_all(data):
+ return BLOCK.sub(highlight_block, data)
No newline at end of file