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

Restore support for highlighting XML-encoded plists #1026

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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