Skip to content

Commit 9fd147b

Browse files
committed
CND Highlighting extension
1 parent 4c590de commit 9fd147b

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

_exts/phpcr/sphinx/cnd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from phpcr.sphinx.lexer_cnd import CndLexer
2+
3+
def setup(app):
4+
app.add_lexer('cnd', CndLexer())

_exts/phpcr/sphinx/lexer_cnd.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pygments.lexer import RegexLexer
2+
from pygments.token import *
3+
import re
4+
5+
class CndLexer(RegexLexer):
6+
"""
7+
For JCR Compact Namespace and Node Type Definition files.
8+
"""
9+
10+
name = 'Cnd'
11+
aliases = ['cnd']
12+
filenames = ['*.cnd']
13+
14+
tokens = {
15+
'root': [
16+
(r'^<.*?>', Name.Namespace),
17+
(r'^//.*$', Comment),
18+
(r'/\*\*/', Comment.Multiline),
19+
(r'/\*.*?\*/', Comment.Multiline),
20+
(r'\[.*?\]', Name.Entity, 'nodetype'),
21+
(r'\((string|binary|long|double|date|boolean|name|path|reference|weakreference|uri|decimal)\)', Name.Label),
22+
(r'(\[|\(|\)|\])', Name.Tag),
23+
(r'^\+', Keyword.Declaration),
24+
(r'^\-', Keyword.Declaration),
25+
(r'(mandatory|autocreated|protected|version|primary)', Keyword),
26+
(r'(mixin|orderable)', Keyword),
27+
(r'(mandatory|autocreated|protected|multiple|version|primary)', Keyword),
28+
(r'(>|=|<|\*)', Operator),
29+
(r'\'.*?\'', String.Single),
30+
(r',', Punctuation),
31+
(r'\s+', Text),
32+
(r'[\w:]', Text),
33+
],
34+
'nodetype': [
35+
(r'>', Name.Punctuation),
36+
(r'[\w:]', Name.Class),
37+
(r',', Punctuation),
38+
(r' ', Text),
39+
]
40+
}

conf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@
2323
# If your documentation needs a minimal Sphinx version, state it here.
2424
#needs_sphinx = '1.0'
2525

26+
27+
# Add ourxextension directory to the system paths
28+
sys.path.append(os.path.abspath('_exts'))
29+
2630
# Add any Sphinx extension module names here, as strings. They can be extensions
2731
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
28-
extensions = []
32+
extensions = ['phpcr.sphinx.cnd']
2933

3034
# Add any paths that contain templates here, relative to this directory.
3135
templates_path = ['_templates']

0 commit comments

Comments
 (0)