Class: Marcdouane::Rules::ConsistentHeaderStyle
- Defined in:
- lib/marcdouane/rules/consistent_header_style.rb
Overview
Ensure that headers style is consistent: either the '#'-prefix style or the '=' underscore style, but not both.
Constant Summary collapse
- ERROR_MESSAGE =
"Use a unique, consistent header style"
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
Methods inherited from Rule
#error!, #identifier, #initialize, #line_number_from_byte_range
Constructor Details
This class inherits a constructor from Marcdouane::Rules::Rule
Instance Method Details
#check! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/marcdouane/rules/consistent_header_style.rb', line 10 def check! reference_style = nil # we need to dup otherwise seeking directly into the # @markdown.source confuses Inkmark and subsequent headers # will have nil byte ranges source = @markdown.source.lines.dup @markdown.on(:heading) do |header| line_number = line_number_from_byte_range(header.byte_range) style = source[line_number].start_with?("#") ? :normal : :underline reference_style ||= style error!(line_number) if reference_style != style end @markdown.walk end |