Skip to content

Commit b95f8c4

Browse files
committed
fix list ordering, remove wrapping
- FIXED: Numeric list ordering was broken by an earlier change - IMPROVED: Giving up on word wrapping until I find a better solution
1 parent 70e62c6 commit b95f8c4

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

lib/mdless/console.rb

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def insert_footnotes(input)
582582
notes = line.to_enum(:scan, /\[\^(?<ref>\d+)\]/).map { Regexp.last_match }
583583
if notes.count.positive?
584584
footnotes = notes.map { |n| color_footnote_def(n['ref'].to_i) }.join("\n")
585-
"#{line}\n\n#{footnotes}\n\n"
585+
"#{line}\n\n#{footnotes}\n\n\n"
586586
else
587587
line
588588
end
@@ -604,14 +604,12 @@ def list_item(text, list_type)
604604
end
605605
end
606606

607-
def indent_lines(input, spaces)
607+
def indent_lines(input)
608608
return nil if input.nil?
609609

610-
indent = spaces.scan(/ /).count
611-
612610
lines = input.split(/\n/)
613611
line1 = lines.shift
614-
pre = spaces + " "
612+
pre = ' '
615613

616614
body = lines.map { |l| "#{pre}#{l.rstrip}" }.join("\n")
617615
"#{line1}\n#{body}"
@@ -621,21 +619,21 @@ def color_list_item(indent, content, type, counter)
621619
out = case type
622620
when :unordered
623621
[
624-
indent,
622+
' ' * indent,
625623
color('list bullet'),
626624
MDLess.theme['list']['ul_char'].strip,
627625
' ',
628626
color('list color'),
629-
indent_lines(content, indent).strip,
627+
indent_lines(content).strip,
630628
xc
631629
].join
632630
when :ordered
633631
[
634-
indent,
632+
' ' * indent,
635633
color('list number'),
636634
"#{counter}. ",
637635
color('list color'),
638-
indent_lines(content, indent).strip,
636+
indent_lines(content).strip,
639637
xc
640638
].join
641639
end
@@ -687,21 +685,24 @@ def normalize_indentation(line)
687685
def fix_items(content, last_indent = 0, levels = [0])
688686
content.gsub(%r{^(?<indent> *)<<listitem(?<id>\d+)-(?<type>(?:un)?ordered)>>(?<content>.*?)<</listitem\k<id>>>}m) do
689687
m = Regexp.last_match
690-
indent = 0
691-
if indent == last_indent
692-
levels[indent] ||= 0
693-
levels[indent] += 1
694-
elsif indent < last_indent
695-
levels[last_indent] = 0
696-
levels[indent] += 1
697-
last_indent = indent
698-
else
699-
levels[indent] = 1
700-
last_indent = indent
688+
689+
indent = m['indent'].length
690+
if m['type'].to_sym == :ordered
691+
if indent == last_indent
692+
levels[indent] ||= 0
693+
levels[indent] += 1
694+
elsif indent < last_indent
695+
levels[last_indent] = 0
696+
levels[indent] += 1
697+
last_indent = indent
698+
else
699+
levels[indent] = 1
700+
last_indent = indent
701+
end
701702
end
702703

703704
content = m['content'] =~/<<listitem/ ? fix_items(m['content'], indent, levels) : m['content']
704-
color_list_item(" " * indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
705+
color_list_item(indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
705706
end
706707
end
707708

@@ -832,7 +833,7 @@ def mmd_metadata_replace(input)
832833
end
833834

834835
def fix_image_attributes(input)
835-
input.gsub(/^( {0,3}\[[^^].*?\]: *\S+) +([^"].*?)$/, '\1')
836+
input.gsub(/^( {0,3}\[[^^*>].*?\]: *\S+) +([^"].*?)$/, '\1')
836837
end
837838

838839
def preprocess(input)

lib/mdless/converter.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,17 @@ def page(text, &callback)
584584
end
585585

586586
def printout
587-
if MDLess.options[:taskpaper]
588-
out = @output
589-
else
590-
out = @output.rstrip.split(/\n/).map do |p|
591-
p.wrap(MDLess.cols, color('text'))
592-
end.join("\n")
593-
end
587+
out = @output
588+
589+
# out = if MDLess.options[:taskpaper]
590+
# @output
591+
# else
592+
# # TODO: Figure out a word wrap that accounts for indentation
593+
# @output
594+
# # out = @output.rstrip.split(/\n/).map do |p|
595+
# # p.wrap(MDLess.cols, color('text'))
596+
# # end.join("\n")
597+
# end
594598

595599
unless out.size&.positive?
596600
MDLess.log.warn 'No results'

0 commit comments

Comments
 (0)