Skip to content

Commit

Permalink
Adds lenient Python syntax highlighters
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Feb 12, 2016
1 parent 0b35978 commit d84c3b9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pip-delete-this-directory.txt
_build/
make.bat
Makefile
sphinx/

# Macintosh Desktop Services Store files
.DS_Store
Expand Down
38 changes: 38 additions & 0 deletions coconut/highlighter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python

#-----------------------------------------------------------------------------------------------------------------------
# INFO:
#-----------------------------------------------------------------------------------------------------------------------

"""
Author: Evan Hubinger
License: Apache 2.0
Description: Syntax highlighting for Coconut code.
"""

#-----------------------------------------------------------------------------------------------------------------------
# IMPORTS:
#----------------------gme------------------------------------------------------------------------------------------------

from __future__ import print_function, absolute_import, unicode_literals, division

from .root import *
import pygments

#-----------------------------------------------------------------------------------------------------------------------
# LEXER:
#-----------------------------------------------------------------------------------------------------------------------

class pylexer(pygments.lexers.python.PythonLexer):
"""Lenient Python syntax highlighter."""
def add_filter(*args, **kwargs):
"""Disables the raiseonerror filter."""
if len(args) >= 1 and args[0] == "raiseonerror":
super(pylexer, self).add_filter(*args, **kwargs)

class pyconlexer(pygments.lexers.python.PythonConsoleLexer):
"""Lenient Python console syntax highlighter."""
def add_filter(*args, **kwargs):
"""Disables the raiseonerror filter."""
if len(args) >= 1 and args[0] == "raiseonerror":
super(pyconlexer, self).add_filter(*args, **kwargs)
2 changes: 2 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@
".md": CommonMarkParser
}
source_suffix = [".rst", ".md"]

extensions = ["coconut"]
3 changes: 2 additions & 1 deletion conf_reqs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sphinx
recommonmark
sphinx_bootstrap_theme
-e git+https://github.com/evhub/sphinx.git@rtfd#egg=Sphinx
coconut
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@
install_requires = [
"pyparsing==2.0.7"
],
entry_points = {"console_scripts": [
"coconut = coconut.__main__:main"
]}
entry_points = {
"console_scripts": [
"coconut = coconut.__main__:main"
],
"pygments.lexers": [
"force_python = coconut.highlighter:pylexer",
"force_pycon = coconut.highlighter:pyconlexer"
]
}
)

0 comments on commit d84c3b9

Please sign in to comment.