Skip to content

Commit

Permalink
Support on the command line plaintext and commonmark formats
Browse files Browse the repository at this point in the history
Command line arguments `--to=commonmark` and
`--to=plaintext` are now supported
  • Loading branch information
digitalmoksha committed Aug 26, 2021
1 parent f939598 commit 5f92e5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bin/commonmarker
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def parse_options
exit
end

opts.on('-tFORMAT', '--to=FORMAT', String, 'Specify output format (html, xml)') do |value|
opts.on('-tFORMAT', '--to=FORMAT', String, 'Specify output FORMAT') do |value|
value = value.to_sym
options.output_format = value if format_options.include?(value)
end
Expand Down Expand Up @@ -108,4 +108,8 @@ when :html
end
when :xml
$stdout.write(doc.to_xml(options.active_render_options))
when :commonmark
$stdout.write(doc.to_commonmark(options.active_render_options))
when :plaintext
$stdout.write(doc.to_plaintext(options.active_render_options))
end
2 changes: 1 addition & 1 deletion lib/commonmarker/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Config
UNSAFE: (1 << 17),
FOOTNOTES: (1 << 13)
}.freeze,
format: %i[html xml].freeze
format: %i[html xml commonmark plaintext].freeze
}.freeze

def self.process_options(option, type)
Expand Down
12 changes: 11 additions & 1 deletion test/test_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ def test_understands_multiple_extensions
%w[<table> <tr> <th> a </th> <td> c </td>].each { |html| assert_includes out, html }
end

def test_understands_format
def test_understands_xml_format
out = make_bin('strong.md', '--to=xml')
assert_includes out, '<?xml version="1.0" encoding="UTF-8"?>'
assert_includes out, '<text xml:space="preserve">strong</text>'
end

def test_understands_commonmark_format
out = make_bin('strong.md', '--to=commonmark')
assert_equal('I am **strong**', out)
end

def test_understands_plaintext_format
out = make_bin('strong.md', '--to=plaintext')
assert_equal('I am strong', out)
end
end

0 comments on commit 5f92e5c

Please sign in to comment.