Skip to content

Commit

Permalink
Reorder options
Browse files Browse the repository at this point in the history
- IMPROVED: Re-order command line options for more readable help output (`mdless -h`)
  • Loading branch information
ttscoff committed Nov 26, 2023
1 parent d04fcdf commit 0490fc3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 52 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ The pager used is determined by system configuration in this order of preference
-h, --help Display this screen
-i, --images=TYPE Include [local|remote (both)|none] images in output (requires chafa or imgcat, default none).
-I, --all-images Include local and remote images in output (requires imgcat or chafa)
--syntax Syntax highlight code blocks
--links=FORMAT Link style ([inline, reference, paragraph], default inline, "paragraph" will position reference links after each paragraph)
-l, --list List headers in document and exit
-p, --[no-]pager Formatted output to pager (default on)
-P Disable pager (same as --no-pager)
Expand All @@ -71,6 +69,14 @@ The pager used is determined by system configuration in this order of preference
-v, --version Display version number
-w, --width=COLUMNS Column width to format for (default: terminal width)
--[no-]inline_footnotes Display footnotes immediately after the paragraph that references them
--[no-]intra-emphasis Parse emphasis inside of words (e.g. Mark_down_)
--[no-]lax-spacing Allow lax spacing
--links=FORMAT Link style ([inline, reference, paragraph], default inline,
"paragraph" will position reference links after each paragraph)
--[no-]syntax Syntax highlight code blocks
--taskpaper=OPTION Highlight TaskPaper format (true|false|auto)
--update_config Update the configuration file with new keys and current command line options
--[no-]wiki-links Highlight [[wiki links]]

## Configuration

Expand Down
113 changes: 63 additions & 50 deletions lib/mdless/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def initialize(args)
@log.warn('images turned on but imgcat/chafa not found')
end
end

opts.on('-I', '--all-images', 'Include local and remote images in output (requires imgcat or chafa)') do
if exec_available('imgcat') || exec_available('chafa') # && ENV['TERM_PROGRAM'] == 'iTerm.app'
@options[:local_images] = true
Expand All @@ -70,51 +71,6 @@ def initialize(args)
end
end

@options[:syntax_higlight] ||= false
opts.on('--syntax', 'Syntax highlight code blocks') do |p|
@options[:syntax_higlight] = p
end

@options[:update_config] ||= false
opts.on('--update_config', 'Update the configuration file with new keys and current command line options') do
@options[:update_config] = true
end

@options[:taskpaper] ||= false
opts.on('--taskpaper=OPTION', 'Highlight TaskPaper format (true|false|auto)') do |tp|
@options[:taskpaper] = case tp
when /^[ty1]/
true
when /^a/
:auto
else
false
end
end

@options[:links] ||= :inline
opts.on('--links=FORMAT',
'Link style ([inline, reference, paragraph], default inline, "paragraph" will position reference links after each paragraph)') do |fmt|
@options[:links] = case fmt
when /^:?r/i
:reference
when /^:?p/i
:paragraph
else
:inline
end
end

@options[:lax_spacing] ||= true
opts.on('--[no-]lax-spacing', 'Allow lax spacing') do |opt|
@options[:lax_spacing] = opt
end

@options[:intra_emphasis] ||= true
opts.on('--[no-]intra-emphasis', 'Parse emphasis inside of words (e.g. Mark_down_)') do |opt|
@options[:intra_emphasis] = opt
end

@options[:list] ||= false
opts.on('-l', '--list', 'List headers in document and exit') do
@options[:list] = true
Expand Down Expand Up @@ -146,11 +102,6 @@ def initialize(args)
@options[:at_tags] = true
end

@options[:wiki_links] ||= false
opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
@options[:wiki_links] = opt
end

opts.on('-v', '--version', 'Display version number') do
puts version
exit
Expand All @@ -166,6 +117,68 @@ def initialize(args)
'Display footnotes immediately after the paragraph that references them') do |p|
@options[:inline_footnotes] = p
end

@options[:intra_emphasis] ||= true
opts.on('--[no-]intra-emphasis', 'Parse emphasis inside of words (e.g. Mark_down_)') do |opt|
@options[:intra_emphasis] = opt
end

@options[:lax_spacing] ||= true
opts.on('--[no-]lax-spacing', 'Allow lax spacing') do |opt|
@options[:lax_spacing] = opt
end

@options[:links] ||= :inline
opts.on('--links=FORMAT',
'Link style ([inline, reference, paragraph], default inline,
"paragraph" will position reference links after each paragraph)') do |fmt|
@options[:links] = case fmt
when /^:?r/i
:reference
when /^:?p/i
:paragraph
else
:inline
end
end

@options[:syntax_higlight] ||= false
opts.on('--[no-]syntax', 'Syntax highlight code blocks') do |p|
@options[:syntax_higlight] = p
end

@options[:taskpaper] = if @options[:taskpaper]
case @options[:taskpaper].to_s
when /^[ty1]/
true
when /^a/
:auto
else
false
end
else
false
end
opts.on('--taskpaper=OPTION', 'Highlight TaskPaper format (true|false|auto)') do |tp|
@options[:taskpaper] = case tp
when /^[ty1]/
true
when /^a/
:auto
else
false
end
end

@options[:update_config] ||= false
opts.on('--update_config', 'Update the configuration file with new keys and current command line options') do
@options[:update_config] = true
end

@options[:wiki_links] ||= false
opts.on('--[no-]wiki-links', 'Highlight [[wiki links]]') do |opt|
@options[:wiki_links] = opt
end
end

begin
Expand Down

0 comments on commit 0490fc3

Please sign in to comment.