Sha256: 341e263500fc27a1773702ab3d517f87d376c7f27fe47e4508475f6d14d77da9

Contents?: true

Size: 1.71 KB

Versions: 23

Compression:

Stored size: 1.71 KB

Contents

#!/usr/bin/env ruby
require 'html/pipeline'

require 'optparse'

# Accept "help", too
.map! { |a| a == 'help' ? '--help' : a }

onParser.new do |opts|
  opts.banner = <<-HELP.gsub(/^    /, '')
    Usage: html-pipeline [-h] [-f]
           html-pipeline [FILTER [FILTER [...]]] < file.md
       cat file.md | html-pipeline [FILTER [FILTER [...]]]
  HELP

 opts.separator 'Options:'

  opts.on('-f', '--filters', 'List the available filters') do
    filters = HTML::Pipeline.constants.grep(/\w+Filter$/)
                            .map { |f| f.to_s.gsub(/Filter$/, '') }

    # Text filter doesn't work, no call method
    filters -= ['Text']

    abort <<-HELP.gsub(/^      /, '')
      Available filters:
        #{filters.join("\n        ")}
    HELP
  end
end.parse!

# Default to a GitHub-ish pipeline
if ARGV.empty?

  filters = [
    HTML::Pipeline::MarkdownFilter,
    HTML::Pipeline::SanitizationFilter,
    HTML::Pipeline::ImageMaxWidthFilter,
    HTML::Pipeline::EmojiFilter,
    HTML::Pipeline::AutolinkFilter,
    HTML::Pipeline::TableOfContentsFilter
  ]

  # Add syntax highlighting if rouge is present
  begin
    require 'rouge'
    filters << HTML::Pipeline::SyntaxHighlightFilter
  rescue LoadError
  end

else

  def filter_named(name)
    case name
    when 'Text'
      raise NameError # Text filter doesn't work, no call method
    end

    HTML::Pipeline.const_get("#{name}Filter")
  rescue NameError => e
    abort "Unknown filter '#{name}'. List filters with the -f option."
  end

  filters = []
  until ARGV.empty?
    name = ARGV.shift
    filters << filter_named(name)
  end

end

context = {
  asset_root: '/assets',
  base_url: '/',
  gfm: true
}

puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output]

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
html-pipeline-2.14.3 bin/html-pipeline
html-pipeline-2.14.2 bin/html-pipeline
html-pipeline-2.14.1 bin/html-pipeline
html-pipeline-2.13.2 bin/html-pipeline
html-pipeline-2.13.1 bin/html-pipeline
html-pipeline-2.14.0 bin/html-pipeline
html-pipeline-2.13.0 bin/html-pipeline
html-pipeline-2.12.3 bin/html-pipeline
html-pipeline-2.12.2 bin/html-pipeline
html-pipeline-2.12.1 bin/html-pipeline
html-pipeline-2.12.0 bin/html-pipeline
html-pipeline-2.11.1 bin/html-pipeline
html-pipeline-2.11.0 bin/html-pipeline
html-pipeline-2.10.0 bin/html-pipeline
html-pipeline-2.9.2 bin/html-pipeline
html-pipeline-2.9.1 bin/html-pipeline
html-pipeline-2.9.0 bin/html-pipeline
html-pipeline-2.8.4 bin/html-pipeline
html-pipeline-2.8.3 bin/html-pipeline
html-pipeline-2.8.2 bin/html-pipeline