Skip to content

Commit

Permalink
Merge branch 'release/2.1.42'
Browse files Browse the repository at this point in the history
* release/2.1.42:
  2.1.42
  fix list ordering, remove wrapping
  • Loading branch information
ttscoff committed Dec 21, 2023
2 parents b65139f + 42eea32 commit b8f1ca7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
45 changes: 23 additions & 22 deletions lib/mdless/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def insert_footnotes(input)
notes = line.to_enum(:scan, /\[\^(?<ref>\d+)\]/).map { Regexp.last_match }
if notes.count.positive?
footnotes = notes.map { |n| color_footnote_def(n['ref'].to_i) }.join("\n")
"#{line}\n\n#{footnotes}\n\n"
"#{line}\n\n#{footnotes}\n\n\n"
else
line
end
Expand All @@ -604,14 +604,12 @@ def list_item(text, list_type)
end
end

def indent_lines(input, spaces)
def indent_lines(input)
return nil if input.nil?

indent = spaces.scan(/ /).count

lines = input.split(/\n/)
line1 = lines.shift
pre = spaces + " "
pre = ' '

body = lines.map { |l| "#{pre}#{l.rstrip}" }.join("\n")
"#{line1}\n#{body}"
Expand All @@ -621,21 +619,21 @@ def color_list_item(indent, content, type, counter)
out = case type
when :unordered
[
indent,
' ' * indent,
color('list bullet'),
MDLess.theme['list']['ul_char'].strip,
' ',
color('list color'),
indent_lines(content, indent).strip,
indent_lines(content).strip,
xc
].join
when :ordered
[
indent,
' ' * indent,
color('list number'),
"#{counter}. ",
color('list color'),
indent_lines(content, indent).strip,
indent_lines(content).strip,
xc
].join
end
Expand Down Expand Up @@ -687,21 +685,24 @@ def normalize_indentation(line)
def fix_items(content, last_indent = 0, levels = [0])
content.gsub(%r{^(?<indent> *)<<listitem(?<id>\d+)-(?<type>(?:un)?ordered)>>(?<content>.*?)<</listitem\k<id>>>}m) do
m = Regexp.last_match
indent = 0
if indent == last_indent
levels[indent] ||= 0
levels[indent] += 1
elsif indent < last_indent
levels[last_indent] = 0
levels[indent] += 1
last_indent = indent
else
levels[indent] = 1
last_indent = indent

indent = m['indent'].length
if m['type'].to_sym == :ordered
if indent == last_indent
levels[indent] ||= 0
levels[indent] += 1
elsif indent < last_indent
levels[last_indent] = 0
levels[indent] += 1
last_indent = indent
else
levels[indent] = 1
last_indent = indent
end
end

content = m['content'] =~/<<listitem/ ? fix_items(m['content'], indent, levels) : m['content']
color_list_item(" " * indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
color_list_item(indent, uncolor_grafs(content), m['type'].to_sym, levels[indent])
end
end

Expand Down Expand Up @@ -832,7 +833,7 @@ def mmd_metadata_replace(input)
end

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

def preprocess(input)
Expand Down
18 changes: 11 additions & 7 deletions lib/mdless/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,17 @@ def page(text, &callback)
end

def printout
if MDLess.options[:taskpaper]
out = @output
else
out = @output.rstrip.split(/\n/).map do |p|
p.wrap(MDLess.cols, color('text'))
end.join("\n")
end
out = @output

# out = if MDLess.options[:taskpaper]
# @output
# else
# # TODO: Figure out a word wrap that accounts for indentation
# @output
# # out = @output.rstrip.split(/\n/).map do |p|
# # p.wrap(MDLess.cols, color('text'))
# # end.join("\n")
# end

unless out.size&.positive?
MDLess.log.warn 'No results'
Expand Down
2 changes: 1 addition & 1 deletion lib/mdless/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module CLIMarkdown
VERSION = '2.1.41'
VERSION = '2.1.42'
end

0 comments on commit b8f1ca7

Please sign in to comment.