Class: Markdown::Merge::Cleanse::ListMarkerDuplication
- Inherits:
-
Object
- Object
- Markdown::Merge::Cleanse::ListMarkerDuplication
- Defined in:
- lib/markdown/merge/cleanse/list_marker_duplication.rb
Overview
Repairs templating corruption where an ordered-list marker was prefixed onto an existing unordered-list marker, producing lines like:
1. - item
2. * item
The repair keeps the original inner bullet marker and removes the synthetic ordered marker.
Constant Summary collapse
- DUPLICATED_MARKER =
/\A(?<indent>\s*)(?<number>\d+)\.\s+(?<bullet>[-*+])(?<tail>(?:\s+.*)?\s*)\z/
Instance Attribute Summary collapse
- #issues ⇒ Object readonly
- #source ⇒ Object readonly
Instance Method Summary collapse
- #fix ⇒ Object
-
#initialize(source) ⇒ ListMarkerDuplication
constructor
A new instance of ListMarkerDuplication.
- #issue_count ⇒ Object
- #malformed? ⇒ Boolean
Constructor Details
#initialize(source) ⇒ ListMarkerDuplication
Returns a new instance of ListMarkerDuplication.
19 20 21 22 23 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 19 def initialize(source) @source = source.to_s @issues = [] analyze end |
Instance Attribute Details
#issues ⇒ Object (readonly)
17 18 19 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 17 def issues @issues end |
#source ⇒ Object (readonly)
17 18 19 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 17 def source @source end |
Instance Method Details
#fix ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 33 def fix return source unless malformed? source.each_line.with_index(1).map do |line, line_number| duplicated_marker_line?(line) ? repaired_line(line, line_number) : line end.join end |
#issue_count ⇒ Object
29 30 31 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 29 def issue_count issues.length end |
#malformed? ⇒ Boolean
25 26 27 |
# File 'lib/markdown/merge/cleanse/list_marker_duplication.rb', line 25 def malformed? issues.any? end |