Skip to content

Commit

Permalink
change Reader#replace_next_line to return true
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Mar 18, 2018
1 parent 9d7c327 commit 5df232b
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions lib/asciidoctor/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ def unshift_lines lines_to_restore
#
# replacement - The String line to put in place of the next line (i.e., the line at the cursor).
#
# Returns nothing.
# Returns true.
def replace_next_line replacement
shift
unshift replacement
nil
true
end
# deprecated
alias replace_line replace_next_line
Expand Down Expand Up @@ -836,11 +836,10 @@ def preprocess_include_directive raw_target, raw_attributes
elsif @document.safe >= SafeMode::SECURE
# FIXME we don't want to use a link macro if we are in a verbatim context
replace_next_line %(link:#{target}[])
true
elsif (abs_maxdepth = @maxdepth[:abs]) > 0
if @include_stack.size >= abs_maxdepth
warn %(asciidoctor: ERROR: #{line_info}: maximum include depth of #{@maxdepth[:rel]} exceeded)
return false
return
end
if ::RUBY_ENGINE_OPAL && ::JAVASCRIPT_IO_MODULE == 'xmlhttprequest'
# NOTE when the IO module is xmlhttprequest, the only way to check if the file exists is to catch a 404 response
Expand All @@ -850,8 +849,7 @@ def preprocess_include_directive raw_target, raw_attributes
inc_path = relpath = p_target
elsif Helpers.uriish? p_target
unless (@path_resolver.descends_from? p_target, base_dir) || (@document.attributes.key? 'allow-uri-read')
replace_next_line %(link:#{target}[])
return true
return replace_next_line %(link:#{target}[])
end
inc_path = relpath = p_target
elsif @path_resolver.absolute_path? p_target
Expand All @@ -876,14 +874,10 @@ def preprocess_include_directive raw_target, raw_attributes
inc_path = %(#{ctx_dir}/#{p_target})
relpath = offset ? (inc_path.slice offset, inc_path.length) : p_target
else
replace_next_line %(link:#{target}[])
return true
return replace_next_line %(link:#{target}[])
end
elsif Helpers.uriish? target
unless @document.attributes.key? 'allow-uri-read'
replace_next_line %(link:#{target}[])
return true
end
return replace_next_line %(link:#{target}[]) unless @document.attributes.key? 'allow-uri-read'

target_type = :uri
inc_path = relpath = target
Expand All @@ -901,8 +895,7 @@ def preprocess_include_directive raw_target, raw_attributes
inc_path = @document.normalize_system_path target, @dir, nil, :target_name => 'include file'
unless ::File.file? inc_path
warn %(asciidoctor: WARNING: #{line_info}: include file not found: #{inc_path})
replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
return true
return replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
end
# NOTE relpath is the path relative to the root document (or base_dir, if set)
# QUESTION should we move relative_path method to Document
Expand Down Expand Up @@ -974,8 +967,7 @@ def preprocess_include_directive raw_target, raw_attributes
end
rescue
warn %(asciidoctor: WARNING: #{line_info}: include #{target_type} not readable: #{inc_path})
replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
return true
return replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
end
shift
# FIXME not accounting for skipped lines in reader line numbering
Expand Down Expand Up @@ -1034,8 +1026,7 @@ def preprocess_include_directive raw_target, raw_attributes
end
rescue
warn %(asciidoctor: WARNING: #{line_info}: include #{target_type} not readable: #{inc_path})
replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
return true
return replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
end
unless (missing_tags = inc_tags.keys.to_a - tags_used.to_a).empty?
warn %(asciidoctor: WARNING: #{line_info}: tag#{missing_tags.size > 1 ? 's' : nil} '#{missing_tags * ','}' not found in include #{target_type}: #{inc_path})
Expand All @@ -1051,8 +1042,7 @@ def preprocess_include_directive raw_target, raw_attributes
push_include inc_content, inc_path, relpath, 1, attributes
rescue
warn %(asciidoctor: WARNING: #{line_info}: include #{target_type} not readable: #{inc_path})
replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
return true
return replace_next_line %(Unresolved directive in #{@path} - include::#{target}[#{raw_attributes}])
end
end
true
Expand Down

0 comments on commit 5df232b

Please sign in to comment.