Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
GEM
remote: http://rubygems.org/
specs:
json (1.8.3)
metaclass (0.0.4)
minitest (5.8.4)
minitest (5.8.5)
mocha (1.1.0)
metaclass (~> 0.0.1)
rake (11.1.2)
rdoc (4.2.2)
json (~> 1.4)
rake (12.0.0)
rdoc (5.0.0)

PLATFORMS
ruby
Expand All @@ -20,4 +18,4 @@ DEPENDENCIES
rdoc

BUNDLED WITH
1.12.2
1.12.5
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ the correct header and footer are added.
PandocRuby.new("# Some title", :standalone).to_rtf
```

My default only whitelisted options (those known to Pandoc) are passed on to
Pandoc. You can send all options to Pandoc by using the `:ignore_whitelist`
option.

## Note on Patches/Pull Requests

* Fork the project.
Expand Down
26 changes: 25 additions & 1 deletion lib/pandoc-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ class PandocRuby
# All of the available Writers.
WRITERS = STRING_WRITERS.merge(BINARY_WRITERS)

# Options understood by pandoc, taken from http://pandoc.org/MANUAL.html.
# Ignore all other options passed to pandoc, unless overriden.
AVAILABLE_OPTIONS = Set.new %w(from read to write output data-dir strict
parse-raw smart old-dashes base-header-level indented-code-classes filter
normalize preserve-tabs tab-stop track-changes file-scope extract-media
standalone template metadata variable print-default-template
print-default-data-file no-wrap wrap columns toc table-of-contents toc-depth
no-highlight highlight-style include-in-header include-before-body
include-after-body self-contained offline html5 html-q-tags ascii
reference-links reference-location atx-headers chapters top-level-division
number-sections number-offsetS no-tex-ligatures listings incremental
slide-level section-divs default-image-extension email-obfuscation id-prefix
title-prefix css reference-odt reference-docx epub-stylesheet
epub-cover-image epub-metadata epub-embed-font epub-chapter-level
latex-engine latex-engine-opt bibliography csl citation-abbreviations natbib
biblatex latexmathml asciimathml mathml mimetex webtex jsmath mathjax katex
katex-stylesheet gladtex trace dump-args ignore-args verbose bash-completion
list-input-formats list-output-formats list-extensions
list-highlight-languages list-highlight-styles)
ALIAS_OPTIONS = Set.new %w(f r t w o R S F p s M V D H B A 5 N i T c m)
ALLOWED_OPTIONS = AVAILABLE_OPTIONS + ALIAS_OPTIONS

# To use run the pandoc command with a custom executable path, the path
# to the pandoc executable can be set here.
def self.pandoc_path=(path)
Expand Down Expand Up @@ -243,11 +265,13 @@ def prepare_options(opts = [])
# Takes a flag and optional argument, uses it to set any relevant options
# used by the library, and returns string with the option formatted as a
# command line options. If the option has an argument, it is also included.
# Only whitelisted options are sent to pandoc, unless overridden.
def create_option(flag, argument = nil)
return '' unless flag
flag = flag.to_s
set_pandoc_ruby_options(flag, argument)
return '' if flag == 'timeout' # pandoc doesn't accept timeouts yet
return '' unless ALLOWED_OPTIONS.include?(flag.gsub('_', '-')) ||
@options.find { |o| o == :ignore_whitelist }
if !argument.nil?
"#{format_flag(flag)} #{argument}"
else
Expand Down
8 changes: 7 additions & 1 deletion test/test_pandoc_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@
assert converter.convert
end

it 'ignores options not whitelisted' do
converter = PandocRuby.new('# hello', 'badopt')
converter.expects(:execute).with('pandoc').returns(true)
assert converter.convert
end

it 'raises RuntimeError from pandoc executable error' do
assert_raises(RuntimeError) do
PandocRuby.new('# hello', 'badopt').to_html5
PandocRuby.new('# hello', 'badopt', :ignore_whitelist).to_html5
end
end

Expand Down