From e03735adb1650a994ace201c1089d9b175cde10f Mon Sep 17 00:00:00 2001 From: fauno Date: Sat, 17 Feb 2018 15:24:21 -0300 Subject: [PATCH] pass flags according to site lang --- README.md | 10 +++++++++- .../converter.rb | 9 +++++++-- .../pandoc_file.rb | 18 ++++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 93941b3..492099a 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 7123226..76e0bad 100644 --- a/lib/jekyll-pandoc-multiple-formats/converter.rb +++ b/lib/jekyll-pandoc-multiple-formats/converter.rb @@ -45,11 +45,16 @@ def self.included(base) 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 a670807..aefcbd6 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 +# Copyright (c) 2012-2018 Nicolás Reynolds # 2012-2013 Mauricio Pasquier Juan # 2013 Brian Candler # @@ -253,13 +253,27 @@ def flags @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