diff --git a/README.md b/README.md index 93941b3f9562f9f953f638cb3d15df811dd6d644..492099aab339b556fc30ee21890ee852f9c9342c 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,10 @@ pandoc: latex: pdf: '--latex-engine=xelatex' epub: '--epub-chapter-level=2' - + lang: + ar: + all: '-V mainfont="Amiri"' + pdf: '--include-in-header=_layouts/rtl.tex' ``` * `markdown: pandoc` will instruct jekyll to use the pandoc html @@ -93,6 +96,11 @@ regular jekyll site build. * `full_file` generates a single file containing all articles, sectioned by their main category (the first one defined if many). +* `lang` is a hash where you can define per-language flags. If you have + a `lang` attribute in your site config, this plugin will add the + `-V lang=XX` flag and any language-specific flag you want. You can + define language flags for `all` formats or for specific formats. + **IMPORTANT**: As of version 0.1.0 the syntax of the config changed. Please upgrade your `_config.yml` accordingly. diff --git a/lib/jekyll-pandoc-multiple-formats/converter.rb b/lib/jekyll-pandoc-multiple-formats/converter.rb index 7123226227b8ffee4b4089642e3b03e32c391ada..76e0badac7663c5c6d4770a6890f8315d2c45312 100644 --- a/lib/jekyll-pandoc-multiple-formats/converter.rb +++ b/lib/jekyll-pandoc-multiple-formats/converter.rb @@ -45,11 +45,16 @@ module JekyllPandocMultipleFormats base.class_eval do # Just return html5 def convert(content) - flags = "#{@config['pandoc']['flags']} #{@config['pandoc']['site_flags']}" + lang = @config.dig('lang') + flags = [] + flags << @config.dig('pandoc', 'flags') + flags << @config.dig('pandoc', 'site_flags') + flags << @config.dig('pandoc', 'lang', lang, 'all') output = '' Dir::chdir(@config['source']) do - Open3::popen3("pandoc -t html5 #{flags}") do |stdin, stdout, stderr, thread| + cmd = "pandoc -t html5 #{flags.compact.join(' ')}" + Open3::popen3(cmd) do |stdin, stdout, stderr, thread| stdin.puts content stdin.close diff --git a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb index a670807656d713fb5f82ccd24a6ad55265a9e759..aefcbd6f42af60b7ee8ec93dd025aa04b4af1aab 100644 --- a/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb +++ b/lib/jekyll-pandoc-multiple-formats/pandoc_file.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2012-2015 Nicolás Reynolds <fauno@endefensadelsl.org> +# Copyright (c) 2012-2018 Nicolás Reynolds <fauno@endefensadelsl.org> # 2012-2013 Mauricio Pasquier Juan <mpj@endefensadelsl.org> # 2013 Brian Candler <b.candler@pobox.com> # @@ -253,13 +253,27 @@ module Jekyll @flags << @config['full_flags'] end - @flags.join ' ' + if site_lang? + @flags << "-V lang=#{site_lang}" + @flags << @config.dig('lang', site_lang, 'all') + @flags << @config.dig('lang', site_lang, @format) + end + + @flags.compact.join ' ' end def command 'pandoc ' << flags end + def site_lang + @site.config.dig('lang') + end + + def site_lang? + !site_lang.nil? + end + def full? @extra[:full] end