Sha256: 40f79161a88f01308f4e3aeec2810204c9a90bd36ca29f9c8935fbb616cfda3a

Contents?: true

Size: 1.58 KB

Versions: 23

Compression:

Stored size: 1.58 KB

Contents

#!/usr/bin/env ruby
# Usage: commonmarker [--html-renderer] [--list-extensions] [--extension=EXTENSION] [FILE..]
# Convert one or more CommonMark files to HTML and write to standard output.
# If no FILE argument is provided, text will be read from STDIN.
# With --html-renderer, use the HtmlRenderer renderer rather than the native C
# renderer.
# With --extension=EXTENSION, EXTENSION will be used for parsing, and HTML
# output unless --html-renderer is specified.
if ARGV.include?('--help') or ARGV.include?('-h')
  File.read(__FILE__).split("\n").grep(/^# /).each do |line|
    puts line[2..-1]
  end
  exit 0
end

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w( .. lib ))
require 'commonmarker'

if ARGV.include?('--version') or ARGV.include?('-v')
  puts "commonmarker #{CommonMarker::VERSION}"
  exit 0
end

root = File.expand_path('../../', __FILE__)
$:.unshift File.expand_path('lib', root)

extensions = CommonMarker.extensions
active_extensions = []

renderer = nil
ARGV.delete_if do |arg|
  if arg =~ /^--html-renderer$/
    renderer = true
    true
  elsif arg =~ /^--list-extensions$/
    puts extensions
    exit 0
  elsif arg =~ /^--extension=(.+)$/
    if extensions.include?($1)
      active_extensions << $1.intern
    else
      STDERR.puts "extension #$1 not found"
      exit 1
    end
    true
  else
    false
  end
end

doc = CommonMarker.render_doc(ARGF.read, :DEFAULT, active_extensions)

if renderer
  renderer = CommonMarker::HtmlRenderer.new(extensions: active_extensions)
  STDOUT.write(renderer.render(doc))
else
  STDOUT.write(doc.to_html(:DEFAULT, active_extensions))
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
commonmarker-0.18.2 bin/commonmarker
commonmarker-0.18.1 bin/commonmarker
commonmarker-0.18.0 bin/commonmarker
commonmarker-0.17.13 bin/commonmarker
commonmarker-0.17.12 bin/commonmarker
commonmarker-0.17.11 bin/commonmarker
commonmarker-0.17.10 bin/commonmarker
tdiary-5.0.8 vendor/bundle/gems/commonmarker-0.17.9/bin/commonmarker
commonmarker-0.17.9 bin/commonmarker
commonmarker-0.17.8 bin/commonmarker
commonmarker-0.17.7.1 bin/commonmarker
commonmarker-0.17.7 bin/commonmarker
commonmarker-0.17.6 bin/commonmarker
commonmarker-0.17.5 bin/commonmarker
commonmarker-0.17.4 bin/commonmarker
commonmarker-0.17.2 bin/commonmarker
commonmarker-0.17.1 bin/commonmarker
commonmarker-0.17.0 bin/commonmarker
commonmarker-0.16.8 bin/commonmarker
commonmarker-0.16.7 bin/commonmarker