diff --git a/lib/rdoc/markdown/literals.rb b/lib/rdoc/markdown/literals.rb index 943c2d268a..4c36672de7 100644 --- a/lib/rdoc/markdown/literals.rb +++ b/lib/rdoc/markdown/literals.rb @@ -29,6 +29,7 @@ class RDoc::Markdown::Literals @result = nil @failed_rule = nil @failing_rule_offset = -1 + @line_offsets = nil setup_foreign_grammar end @@ -45,17 +46,32 @@ class RDoc::Markdown::Literals target + 1 end - def current_line(target=pos) - cur_offset = 0 - cur_line = 0 + if [].respond_to? :bsearch_index + def current_line(target=pos) + unless @line_offsets + @line_offsets = [] + total = 0 + string.each_line do |line| + total += line.size + @line_offsets << total + end + end - string.each_line do |line| - cur_line += 1 - cur_offset += line.size - return cur_line if cur_offset >= target + @line_offsets.bsearch_index {|x| x >= target } + 1 || -1 end + else + def current_line(target=pos) + cur_offset = 0 + cur_line = 0 - -1 + string.each_line do |line| + cur_line += 1 + cur_offset += line.size + return cur_line if cur_offset >= target + end + + -1 + end end def lines diff --git a/lib/rdoc/rd/block_parser.rb b/lib/rdoc/rd/block_parser.rb index 462ba869a2..eb7d46925b 100644 --- a/lib/rdoc/rd/block_parser.rb +++ b/lib/rdoc/rd/block_parser.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # # DO NOT MODIFY!!!! -# This file is automatically generated by Racc 1.5.2 +# This file is automatically generated by Racc 1.6.0 # from Racc grammar file "". # diff --git a/lib/rdoc/rd/inline_parser.rb b/lib/rdoc/rd/inline_parser.rb index 8f4c2c31ef..c1da35a109 100644 --- a/lib/rdoc/rd/inline_parser.rb +++ b/lib/rdoc/rd/inline_parser.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # # DO NOT MODIFY!!!! -# This file is automatically generated by Racc 1.5.2 +# This file is automatically generated by Racc 1.6.0 # from Racc grammar file "". #