Skip to content

Commit

Permalink
Restore support for highlighting XML-encoded plists (#1026)
Browse files Browse the repository at this point in the history
The XML lexer can now read *.plists, and a disambiguation has been added for
*.plist files since now both the Plist and XML lexers can handle them.

The reason this change was made is that the current Plist lexer handles (and
mangles) property lists that are XML-based. Property lists can be encoded as
binary, ASCII, or XML, with most files being XML-encoded.
  • Loading branch information
Footpad authored and pyrmont committed May 29, 2019
1 parent fa1ef1c commit 087fd80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/rouge/guessers/disambiguation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def match?(filename)

Cpp
end

disambiguate '*.plist' do
next XML if matches?(/\A<\?xml\b/)

Plist
end
end
end
end
2 changes: 1 addition & 1 deletion lib/rouge/lexers/xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class XML < RegexLexer
title "XML"
desc %q(<desc for="this-lexer">XML</desc>)
tag 'xml'
filenames *%w(*.xml *.xsl *.rss *.xslt *.xsd *.wsdl *.svg)
filenames *%w(*.xml *.xsl *.rss *.xslt *.xsd *.wsdl *.svg *.plist)
mimetypes *%w(
text/xml
application/xml
Expand Down
6 changes: 6 additions & 0 deletions spec/lexers/plist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

it 'guesses by filename' do
assert_guess :filename => 'foo.pbxproj'
assert_guess :filename => 'foo.plist', :source => 'foo'
end

it 'guesses by mimetype' do
assert_guess :mimetype => 'text/x-plist'
assert_guess :mimetype => 'application/x-plist'
end

it 'does not guess XML-encoded plists' do
deny_guess :filename => 'foo.plist', :mimetype => 'application/xml'
deny_guess :filename => 'foo.plist', :source => '<?xml version="1.0" encoding="UTF-8">'
end
end
end
2 changes: 2 additions & 0 deletions spec/lexers/xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
assert_guess :filename => 'foo.xsd'
assert_guess :filename => 'foo.wsdl'
assert_guess :filename => 'foo.svg'
assert_guess :filename => 'foo.plist', :source => '<?xml version="1.0" encoding="utf-8"?>'
deny_guess :filename => 'foo.plist', :source => 'foo'
end

it 'guesses by mimetype' do
Expand Down

0 comments on commit 087fd80

Please sign in to comment.