Skip to content

Commit 3e0e3e7

Browse files
committed
add option to control how far to indent nested list markers
1 parent 222d5ae commit 3e0e3e7

17 files changed

+132
-1
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
77

88
== Unreleased
99

10+
=== Added
11+
12+
* Add :nested_list_marker_indent API option and --nested-list-marker-indent CLI option to control how many spaces to indent nested list markers per indent level
13+
1014
=== Fixed
1115

1216
* Convert language tag on source block to lowercase (#106)

lib/kramdown-asciidoc/api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module AsciiDoc
2727
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
2828
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
2929
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
30+
# @option opts [Integer] :nested_list_marker_indent (1) how many spaces to indent nested list markers per indent level.
3031
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
3132
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
3233
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;
@@ -85,6 +86,7 @@ def self.convert markdown, opts = {}
8586
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
8687
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
8788
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
89+
# @option opts [Integer] :nested_list_marker_indent (1) how many spaces to indent nested list markers per indent level.
8890
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
8991
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
9092
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;

lib/kramdown-asciidoc/cli.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def parse args
7575
options[:auto_links] = auto_links
7676
end
7777

78+
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|
79+
options[:nested_list_marker_indent] = nested_list_marker_indent
80+
end
81+
7882
opts.on '-h', '--help', 'Display this help text and exit' do
7983
$stdout.write opts.help
8084
return 0

lib/kramdown-asciidoc/converter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def initialize root, opts
9292
@ids_seen = {}
9393
@footnote_ids = ::Set.new
9494
@auto_links = opts.fetch :auto_links, true
95+
@nested_list_marker_indent = [opts[:nested_list_marker_indent] || 1, 0].max
9596
@diagram_languages = opts[:diagram_languages] || %w(plantuml mermaid)
9697
@heading_offset = opts[:heading_offset] || 0
9798
@imagesdir = opts[:imagesdir] || @attributes['imagesdir']
@@ -338,7 +339,7 @@ def convert_li el, opts
338339
remaining = children
339340
primary_lines = ['{blank}']
340341
end
341-
primary_lines.unshift %(#{indent > 0 ? ' ' * indent : ''}#{marker * level} #{primary_lines.shift})
342+
primary_lines.unshift %(#{indent > 0 ? ' ' * (indent * @nested_list_marker_indent) : ''}#{marker * level} #{primary_lines.shift})
342343
writer.add_lines primary_lines
343344
return if remaining.empty?
344345
if remaining.find {|n| (type = n.type) == :blank ? nil : ((BLOCK_TYPES.include? type) ? true : break) }

spec/cli_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@
201201
(expect $stdout.string).to eql expected
202202
end
203203

204+
it 'does not indent ul list markers with --nested-list-marker-indent set to 0' do
205+
the_source_file = scenario_file 'ul/nested-0-indent.md'
206+
expected = File.read (scenario_file 'ul/nested-0-indent.adoc'), mode: 'rb'
207+
(expect subject.run %W(-o - --nested-list-marker-indent=0 #{the_source_file})).to eql 0
208+
(expect $stdout.string).to eql expected
209+
end
210+
211+
it 'does not indent ol list markers with --nested-list-marker-indent set to 0' do
212+
the_source_file = scenario_file 'ol/nested-0-indent.md'
213+
expected = File.read (scenario_file 'ol/nested-0-indent.adoc'), mode: 'rb'
214+
(expect subject.run %W(-o - --nested-list-marker-indent=0 #{the_source_file})).to eql 0
215+
(expect $stdout.string).to eql expected
216+
end
217+
218+
it 'does indent ul list markers according to --nested-list-marker-indent configuration' do
219+
the_source_file = scenario_file 'ul/nested-3-indent.md'
220+
expected = File.read (scenario_file 'ul/nested-3-indent.adoc'), mode: 'rb'
221+
(expect subject.run %W(-o - --nested-list-marker-indent=3 #{the_source_file})).to eql 0
222+
(expect $stdout.string).to eql expected
223+
end
224+
225+
it 'does indent ol list markers according to --nested-list-marker-indent configuration' do
226+
the_source_file = scenario_file 'ol/nested-3-indent.md'
227+
expected = File.read (scenario_file 'ol/nested-3-indent.adoc'), mode: 'rb'
228+
(expect subject.run %W(-o - --nested-list-marker-indent=3 #{the_source_file})).to eql 0
229+
(expect $stdout.string).to eql expected
230+
end
231+
204232
it 'shifts headings by offset when --heading-offset is used' do
205233
the_source_file = scenario_file 'heading/offset.md'
206234
expected = File.read (scenario_file 'heading/offset.adoc'), mode: 'rb'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
. bread
2+
.. french country
3+
.. sourdough
4+
.. multigrain
5+
. milk
6+
.. 2%
7+
... whole
8+
.. skim
9+
. eggs
10+
.. brown
11+
.. white
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1. bread
2+
1. french country
3+
2. sourdough
4+
3. multigrain
5+
2. milk
6+
1. 2%
7+
1. whole
8+
2. skim
9+
3. eggs
10+
1. brown
11+
2. white
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:nested_list_marker_indent: 0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
. bread
2+
.. french country
3+
.. sourdough
4+
.. multigrain
5+
. milk
6+
.. 2%
7+
... whole
8+
.. skim
9+
. eggs
10+
.. brown
11+
.. white
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1. bread
2+
1. french country
3+
2. sourdough
4+
3. multigrain
5+
2. milk
6+
1. 2%
7+
1. whole
8+
2. skim
9+
3. eggs
10+
1. brown
11+
2. white

0 commit comments

Comments
 (0)