Skip to content

Commit 5074c13

Browse files
committed
Tweak log entry markdown
* add 3 levels to headings * prefix commit log to labels to make unique IDs
1 parent 11eefb2 commit 5074c13

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lib/rdoc/parser/changelog.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,29 @@ def create_entries entries
229229
out = []
230230
entries.each do |entry, (author, date, body)|
231231
title = RDoc::Markup::Heading.new(3, "#{date} #{author}")
232+
title.extend(Aref)
233+
title.aref = "label-#{entry}"
232234
out << title
233-
out.concat RDoc::Markdown.parse(body).parts
235+
out.concat parse_log_entry(body, entry)
234236
end
235237
out
236238
end
239+
240+
def parse_log_entry(content, sha)
241+
RDoc::Markdown.parse(content).parts.each do |body|
242+
case body
243+
when RDoc::Markup::Heading
244+
body.level += 3
245+
label = body.aref.sub(/\Alabel-/, "label-#{sha}-")
246+
body.extend(Aref)
247+
body.aref = label
248+
end
249+
end
250+
end
251+
252+
module Aref
253+
attr_accessor :aref
254+
end
237255
end
238256
end
239257

test/rdoc/test_rdoc_parser_changelog.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,29 @@ def test_scan_git
340340
Date: 2021-01-20 01:58:26 +0900
341341
342342
* 2021-01-20 [ci skip]
343+
344+
commit de5f8a92d5001799bedb3b1a271a2d9b23c6c8fb
345+
Author: Masataka Pocke Kuwabara <kuwabara@pocke.me>
346+
Date: 2021-01-01 14:25:08 +0900
347+
348+
Make args info for RubyVM::AST to available on endless method without parens
349+
350+
Problem
351+
===
352+
353+
Arguments information is missing for endless method without parens.
354+
For example:
355+
356+
```ruby
357+
# ok
358+
```
359+
360+
It causes an error if a program expects `args` node exists.
361+
362+
Solution
363+
===
364+
365+
Call `new_args` on this case.
343366
ChangeLog
344367

345368
parser.scan
@@ -354,7 +377,18 @@ def test_scan_git
354377
head(2, '2021-01-20'),
355378
blank_line,
356379
head(3, '2021-01-20 01:58:26 +0900 git <svn-admin@ruby-lang.org>'),
357-
list(:BULLET, item(nil, para('2021-01-20 [ci skip]'))))
380+
list(:BULLET, item(nil, para('2021-01-20 [ci skip]'))),
381+
head(2, '2021-01-01'),
382+
blank_line,
383+
head(3, '2021-01-01 14:25:08 +0900 Masataka Pocke Kuwabara <kuwabara@pocke.me>'),
384+
para('Make args info for RubyVM::AST to available on endless method without parens'),
385+
head(4, 'Problem'),
386+
para("Arguments information is missing for endless method without parens.\n" +
387+
"For example:"),
388+
verb("# ok\n").tap {|v| v.format = :ruby},
389+
para('It causes an error if a program expects <code>args</code> node exists.'),
390+
head(4, 'Solution'),
391+
para('Call <code>new_args</code> on this case.'))
358392

359393
expected.file = @top_level
360394

0 commit comments

Comments
 (0)