Skip to content

Commit 6b194cc

Browse files
committed
Remove modeline before creating file parser
This makes NEWS and other files look good. This also deletes the modeline from ruby files, but this should be harmless as those parsers don't currently care about the modeline. Fixes #178
1 parent ccd8a71 commit 6b194cc

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

History.rdoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* RDoc no longer attempts to parse binary files. Bug #189 by postmodern,
1919
Bug #190 by Christoffer Lervåg, Bug #195 by Aaron Patterson
2020
* `rdoc --pipe` output now contains <code></code> for markdown compliance.
21+
* RDoc no longer leaves emacs-style modelines in .txt, .md or .rd files.
22+
Bug #178 by Zachary Scott
2123

2224
=== 4.0.0 / 2013-02-24
2325

lib/rdoc/parser.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def self.for top_level, file_name, content, options, stats
218218

219219
return unless parser
220220

221+
content = remove_modeline content
222+
221223
parser.new top_level, file_name, content, options, stats
222224
rescue SystemCallError
223225
nil
@@ -232,6 +234,13 @@ def self.parse_files_matching(regexp)
232234
RDoc::Parser.parsers.unshift [regexp, self]
233235
end
234236

237+
##
238+
# Removes an emacs-style modeline from the first line of the document
239+
240+
def self.remove_modeline content
241+
content.sub(/\A.*-\*-\s*(.*?\S)\s*-\*-.*\r?\n/, '')
242+
end
243+
235244
##
236245
# If there is a <tt>markup: parser_name</tt> comment at the front of the
237246
# file, use it to determine the parser. For example:

test/test_rdoc_parser.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ def test_class_for_forbidden
110110
end
111111
end
112112

113+
def test_class_for_modeline
114+
temp_dir do
115+
content = "# -*- rdoc -*-\n= NEWS\n"
116+
117+
open 'NEWS', 'w' do |io| io.write content end
118+
app = @store.add_file 'NEWS'
119+
120+
parser = @RP.for app, 'NEWS', content, @options, :stats
121+
122+
assert_kind_of RDoc::Parser::Simple, parser
123+
124+
assert_equal "= NEWS\n", parser.content
125+
end
126+
end
127+
113128
def test_can_parse_modeline
114129
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
115130

0 commit comments

Comments
 (0)