Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix syntax highlighting of INI language #2217

Merged
merged 9 commits into from Sep 15, 2022
13 changes: 11 additions & 2 deletions pygments/lexers/configs.py
Expand Up @@ -45,12 +45,21 @@ class IniLexer(RegexLexer):
'root': [
(r'\s+', Whitespace),
(r'[;#].*', Comment.Single),
(r'\[.*?\]$', Keyword),
(r'(.*?)([ \t]*)(=)([ \t]*)([^\t\n]*)',
(r'(\[.*?\])([ \t]*)$', bygroups(Keyword, Whitespace)),
(r'(.*?)([  \t]*)([=:])([ \t]*)([^;#\n]*)(\\)(\s+)',
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String, Text, Whitespace),
"value"),
(r'(.*?)([ \t]*)([=:])([  \t]*)([^ ;#\n]*(?: +[^ ;#\n]+)*)',
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)),
# standalone option, supported by some INI parsers
(r'(.+?)$', Name.Attribute),
],
'value': [ # line continuation
(r'\s+', Whitespace),
(r'(\s*)(.*)(\\)([ \t]*)',
bygroups(Whitespace, String, Text, Whitespace)),
(r'.*$', String, "#pop"),
],
}

def analyse_text(text):
Expand Down
14 changes: 11 additions & 3 deletions tests/examplefiles/ini/test.ini
@@ -1,10 +1,18 @@
[section]
[section1]

foo = bar
continued = foo
foo = bar ; inline comment
continued = foo # inline comment with \
# line continuation
baz
conttwo =
foo
; comment
# comment

[section2]

my_array = Asia, Africa, 'North America', South America, \
Antarctica, Europe, Australia

implicit_boolean
foo = bar
31 changes: 30 additions & 1 deletion tests/examplefiles/ini/test.ini.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.