From 01baf8fd891e70e247bea343c08923cbd16182eb Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 12 Mar 2024 02:15:25 -0600 Subject: [PATCH] fixes for nested-list-marker-indent option --- lib/kramdown-asciidoc/cli.rb | 2 +- lib/kramdown-asciidoc/converter.rb | 4 ++-- spec/cli_spec.rb | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/kramdown-asciidoc/cli.rb b/lib/kramdown-asciidoc/cli.rb index 78d0b3b..4fcf672 100644 --- a/lib/kramdown-asciidoc/cli.rb +++ b/lib/kramdown-asciidoc/cli.rb @@ -75,7 +75,7 @@ def parse args options[:auto_links] = auto_links end - opts.on '--nested-list-marker-indent', 'Set how many spaces to indent nested list markers per indent level (default: 1)' do |nested_list_marker_indent| + opts.on '--nested-list-marker-indent=NUMBER', ::Integer, 'Set how many spaces to indent nested list markers per indent level (default: 1)' do |nested_list_marker_indent| options[:nested_list_marker_indent] = nested_list_marker_indent end diff --git a/lib/kramdown-asciidoc/converter.rb b/lib/kramdown-asciidoc/converter.rb index a13676d..f20013f 100644 --- a/lib/kramdown-asciidoc/converter.rb +++ b/lib/kramdown-asciidoc/converter.rb @@ -92,7 +92,7 @@ def initialize root, opts @ids_seen = {} @footnote_ids = ::Set.new @auto_links = opts.fetch :auto_links, true - @nested_list_marker_indent = opts[:nested_list_marker_indent] || 1 + @nested_list_marker_indent = [opts[:nested_list_marker_indent] || 1, 0].max @diagram_languages = opts[:diagram_languages] || %w(plantuml mermaid) @heading_offset = opts[:heading_offset] || 0 @imagesdir = opts[:imagesdir] || @attributes['imagesdir'] @@ -339,7 +339,7 @@ def convert_li el, opts remaining = children primary_lines = ['{blank}'] end - primary_lines.unshift %(#{indent > 0 ? ' ' * indent * @nested_list_marker_indent : ''}#{marker * level} #{primary_lines.shift}) + primary_lines.unshift %(#{indent > 0 ? ' ' * (indent * @nested_list_marker_indent) : ''}#{marker * level} #{primary_lines.shift}) writer.add_lines primary_lines return if remaining.empty? if remaining.find {|n| (type = n.type) == :blank ? nil : ((BLOCK_TYPES.include? type) ? true : break) } diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index fe03f16..83a417f 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -204,28 +204,28 @@ it 'does not indent ul list markers with --nested-list-marker-indent set to 0' do the_source_file = scenario_file 'ul/nested-0-indent.md' expected = File.read (scenario_file 'ul/nested-0-indent.adoc'), mode: 'rb' - (expect subject.run %W(-o - #{the_source_file})).to eql 0 + (expect subject.run %W(-o - --nested-list-marker-indent=0 #{the_source_file})).to eql 0 (expect $stdout.string).to eql expected end it 'does not indent ol list markers with --nested-list-marker-indent set to 0' do the_source_file = scenario_file 'ol/nested-0-indent.md' expected = File.read (scenario_file 'ol/nested-0-indent.adoc'), mode: 'rb' - (expect subject.run %W(-o - #{the_source_file})).to eql 0 + (expect subject.run %W(-o - --nested-list-marker-indent=0 #{the_source_file})).to eql 0 (expect $stdout.string).to eql expected end it 'does indent ul list markers according to --nested-list-marker-indent configuration' do the_source_file = scenario_file 'ul/nested-3-indent.md' expected = File.read (scenario_file 'ul/nested-3-indent.adoc'), mode: 'rb' - (expect subject.run %W(-o - #{the_source_file})).to eql 0 + (expect subject.run %W(-o - --nested-list-marker-indent=3 #{the_source_file})).to eql 0 (expect $stdout.string).to eql expected end it 'does indent ol list markers according to --nested-list-marker-indent configuration' do the_source_file = scenario_file 'ol/nested-3-indent.md' expected = File.read (scenario_file 'ol/nested-3-indent.adoc'), mode: 'rb' - (expect subject.run %W(-o - #{the_source_file})).to eql 0 + (expect subject.run %W(-o - --nested-list-marker-indent=3 #{the_source_file})).to eql 0 (expect $stdout.string).to eql expected end