diff options
author | Ulysse Buonomo <buonomo.ulysse@gmail.com> | 2022-02-10 03:31:06 +0100 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-02-12 15:06:06 +0900 |
commit | 5348a34504a67597e3a3ed98a3020dfd762241ad (patch) | |
tree | 7f9f69344798fa039d3f382974f92d26f3369aa3 /lib/rdoc/markdown.rb | |
parent | 08137c5dd99354225874abc95280188738030794 (diff) |
[ruby/rdoc] Relative loading for easier development (https://github.com/ruby/rdoc/pull/821)
This patch makes sure we only load relative code. Hence when coding or
testing rdoc, we'll be sure to always be using the correct code.
Discussion started at https://github.com/ruby/rdoc/pull/817.
Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>
https://github.com/ruby/rdoc/commit/aa41bd48eb
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Diffstat (limited to 'lib/rdoc/markdown.rb')
-rw-r--r-- | lib/rdoc/markdown.rb | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb index c10ad2fb14..25a7217d3c 100644 --- a/lib/rdoc/markdown.rb +++ b/lib/rdoc/markdown.rb @@ -199,6 +199,7 @@ class RDoc::Markdown @result = nil @failed_rule = nil @failing_rule_offset = -1 + @line_offsets = nil setup_foreign_grammar end @@ -215,17 +216,32 @@ class RDoc::Markdown 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 + + string.each_line do |line| + cur_line += 1 + cur_offset += line.size + return cur_line if cur_offset >= target + end - -1 + -1 + end end def lines @@ -533,11 +549,11 @@ class RDoc::Markdown - require 'rdoc' - require 'rdoc/markup/to_joined_paragraph' - require 'rdoc/markdown/entities' + require_relative '../rdoc' + require_relative 'markup/to_joined_paragraph' + require_relative 'markdown/entities' - require 'rdoc/markdown/literals' + require_relative 'markdown/literals' ## # Supported extensions |