##// END OF EJS Templates
HighlightMagics: merge default languages with the user config languages...
Pablo de Oliveira -
Show More
@@ -36,13 +36,17 b' class HighlightMagicsPreprocessor(Preprocessor):'
36 """
36 """
37
37
38 # list of magic language extensions and their associated pygment lexers
38 # list of magic language extensions and their associated pygment lexers
39 languages = Dict(
39 default_languages = Dict(
40 default_value={
40 default_value={
41 '%%R': 'r',
41 '%%R': 'r',
42 '%%bash': 'bash',
42 '%%bash': 'bash',
43 '%%octave': 'octave',
43 '%%octave': 'octave',
44 '%%perl': 'perl',
44 '%%perl': 'perl',
45 '%%ruby': 'ruby'},
45 '%%ruby': 'ruby'},
46 config=False)
47
48 # user defined language extensions
49 languages = Dict(
46 config=True,
50 config=True,
47 help=("Syntax highlighting for magic's extension languages. "
51 help=("Syntax highlighting for magic's extension languages. "
48 "Each item associates a language magic extension such as %%R, "
52 "Each item associates a language magic extension such as %%R, "
@@ -53,9 +57,12 b' class HighlightMagicsPreprocessor(Preprocessor):'
53
57
54 super(HighlightMagicsPreprocessor, self).__init__(config=config, **kw)
58 super(HighlightMagicsPreprocessor, self).__init__(config=config, **kw)
55
59
60 # Update the default languages dict with the user configured ones
61 self.default_languages.update(self.languages)
62
56 # build a regular expression to catch language extensions and choose
63 # build a regular expression to catch language extensions and choose
57 # an adequate pygments lexer
64 # an adequate pygments lexer
58 any_language = "|".join(self.languages.keys())
65 any_language = "|".join(self.default_languages.keys())
59 self.re_magic_language = re.compile(
66 self.re_magic_language = re.compile(
60 r'^\s*({0})\s+'.format(any_language))
67 r'^\s*({0})\s+'.format(any_language))
61
68
@@ -76,8 +83,8 b' class HighlightMagicsPreprocessor(Preprocessor):'
76 if m:
83 if m:
77 # By construction of the re, the matched language must be in the
84 # By construction of the re, the matched language must be in the
78 # languages dictionnary
85 # languages dictionnary
79 assert(m.group(1) in self.languages)
86 assert(m.group(1) in self.default_languages)
80 return self.languages[m.group(1)]
87 return self.default_languages[m.group(1)]
81 else:
88 else:
82 return None
89 return None
83
90
General Comments 0
You need to be logged in to leave comments. Login now