Skip to content

Commit

Permalink
Fix syntax highlighting of INI language doesn't parse comments presen…
Browse files Browse the repository at this point in the history
…t on same line pygments#2161

Add also support for line continuation in values and comments.
  • Loading branch information
jmzambon committed Aug 27, 2022
1 parent cbc7143 commit 01f3e4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pygments/lexers/configs.py
Expand Up @@ -46,11 +46,16 @@ class IniLexer(RegexLexer):
(r'\s+', Whitespace),
(r'[;#].*', Comment.Single),
(r'\[.*?\]$', Keyword),
(r'(.*?)([ \t]*)(=)([ \t]*)([^\t\n]*)',
(r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*[  \t]\\\n)',
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String), "value"),
(r'(.*?)([  \t]*)(=)([  \t]*)([^;#\n]*)',
bygroups(Name.Attribute, Whitespace, Operator, Whitespace, String)),
# standalone option, supported by some INI parsers
# # standalone option, supported by some INI parsers
(r'(.+?)$', Name.Attribute),
],
'value': [ # line continuation
(r'[^;#=]+(?<!\\)\n', String, "#pop"),
],
}

def analyse_text(text):
Expand Down
12 changes: 9 additions & 3 deletions tests/examplefiles/ini/test.ini
@@ -1,10 +1,16 @@
[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
foo = bar
6 changes: 4 additions & 2 deletions tests/examplefiles/ini/test.ini.output

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

0 comments on commit 01f3e4e

Please sign in to comment.