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