Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #119 add option to control how far to indent nested list markers #120

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[

== Unreleased

=== Added

* 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

=== Fixed

* Convert language tag on source block to lowercase (#106)
Expand Down
2 changes: 2 additions & 0 deletions lib/kramdown-asciidoc/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module AsciiDoc
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
# @option opts [Integer] :nested_list_marker_indent (1) how many spaces to indent nested list markers per indent level.
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;
Expand Down Expand Up @@ -85,6 +86,7 @@ def self.convert markdown, opts = {}
# @option opts [Symbol] :wrap (:preserve) the line wrapping behavior to apply (:preserve, :ventilate, or :none).
# @option opts [Integer] :heading_offset (0) the heading offset to apply to heading levels.
# @option opts [Boolean] :auto_links (true) whether to allow raw URLs to be recognized as links.
# @option opts [Integer] :nested_list_marker_indent (1) how many spaces to indent nested list markers per indent level.
# @option opts [Hash] :attributes ({}) additional AsciiDoc attributes to add to header of output document; reserved
# attributes, like stem, may be overridden; some attributes may impact conversion, such as idprefix and idseparator
# @option opts [String] :imagesdir (nil) the prefix to remove from image references found in the Markdown document;
Expand Down
4 changes: 4 additions & 0 deletions lib/kramdown-asciidoc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def parse args
options[:auto_links] = auto_links
end

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

opts.on '-h', '--help', 'Display this help text and exit' do
$stdout.write opts.help
return 0
Expand Down
3 changes: 2 additions & 1 deletion lib/kramdown-asciidoc/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +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, 0].max
@diagram_languages = opts[:diagram_languages] || %w(plantuml mermaid)
@heading_offset = opts[:heading_offset] || 0
@imagesdir = opts[:imagesdir] || @attributes['imagesdir']
Expand Down Expand Up @@ -338,7 +339,7 @@ def convert_li el, opts
remaining = children
primary_lines = ['{blank}']
end
primary_lines.unshift %(#{indent > 0 ? ' ' * 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) }
Expand Down
28 changes: 28 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,34 @@
(expect $stdout.string).to eql expected
end

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 - --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 - --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 - --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 - --nested-list-marker-indent=3 #{the_source_file})).to eql 0
(expect $stdout.string).to eql expected
end

it 'shifts headings by offset when --heading-offset is used' do
the_source_file = scenario_file 'heading/offset.md'
expected = File.read (scenario_file 'heading/offset.adoc'), mode: 'rb'
Expand Down
11 changes: 11 additions & 0 deletions spec/scenarios/ol/nested-0-indent.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
. bread
.. french country
.. sourdough
.. multigrain
. milk
.. 2%
... whole
.. skim
. eggs
.. brown
.. white
11 changes: 11 additions & 0 deletions spec/scenarios/ol/nested-0-indent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1. bread
1. french country
2. sourdough
3. multigrain
2. milk
1. 2%
1. whole
2. skim
3. eggs
1. brown
2. white
1 change: 1 addition & 0 deletions spec/scenarios/ol/nested-0-indent.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:nested_list_marker_indent: 0
11 changes: 11 additions & 0 deletions spec/scenarios/ol/nested-3-indent.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
. bread
.. french country
.. sourdough
.. multigrain
. milk
.. 2%
... whole
.. skim
. eggs
.. brown
.. white
11 changes: 11 additions & 0 deletions spec/scenarios/ol/nested-3-indent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1. bread
1. french country
2. sourdough
3. multigrain
2. milk
1. 2%
1. whole
2. skim
3. eggs
1. brown
2. white
1 change: 1 addition & 0 deletions spec/scenarios/ol/nested-3-indent.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:nested_list_marker_indent: 3
11 changes: 11 additions & 0 deletions spec/scenarios/ul/nested-0-indent.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* bread
** french country
** sourdough
** multigrain
* milk
** 2%
*** whole
** skim
* eggs
** brown
** white
11 changes: 11 additions & 0 deletions spec/scenarios/ul/nested-0-indent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- bread
- french country
- sourdough
- multigrain
- milk
- 2%
- whole
- skim
- eggs
- brown
- white
1 change: 1 addition & 0 deletions spec/scenarios/ul/nested-0-indent.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:nested_list_marker_indent: 0
11 changes: 11 additions & 0 deletions spec/scenarios/ul/nested-3-indent.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* bread
** french country
** sourdough
** multigrain
* milk
** 2%
*** whole
** skim
* eggs
** brown
** white
11 changes: 11 additions & 0 deletions spec/scenarios/ul/nested-3-indent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- bread
- french country
- sourdough
- multigrain
- milk
- 2%
- whole
- skim
- eggs
- brown
- white
1 change: 1 addition & 0 deletions spec/scenarios/ul/nested-3-indent.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:nested_list_marker_indent: 3