From 5f92e5c0a4a88a704c98dcec552a09391c07997f Mon Sep 17 00:00:00 2001 From: digitalMoksha Date: Thu, 26 Aug 2021 11:05:38 -0500 Subject: [PATCH] Support on the command line plaintext and commonmark formats Command line arguments `--to=commonmark` and `--to=plaintext` are now supported --- bin/commonmarker | 6 +++++- lib/commonmarker/config.rb | 2 +- test/test_commands.rb | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/commonmarker b/bin/commonmarker index a38488a0..cc561989 100755 --- a/bin/commonmarker +++ b/bin/commonmarker @@ -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 @@ -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 diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index c7f3347b..12bb92c4 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -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) diff --git a/test/test_commands.rb b/test/test_commands.rb index 9038799e..58d582e6 100644 --- a/test/test_commands.rb +++ b/test/test_commands.rb @@ -29,9 +29,19 @@ def test_understands_multiple_extensions %w[].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, '' assert_includes out, 'strong' 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
a c