Skip to content

Commit

Permalink
pass flags according to site lang
Browse files Browse the repository at this point in the history
  • Loading branch information
fauno committed Feb 17, 2018
1 parent 73f7e50 commit e03735a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
9 changes: 7 additions & 2 deletions lib/jekyll-pandoc-multiple-formats/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 16 additions & 2 deletions lib/jekyll-pandoc-multiple-formats/pandoc_file.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2012-2015 Nicolás Reynolds <[email protected]>
# Copyright (c) 2012-2018 Nicolás Reynolds <[email protected]>
# 2012-2013 Mauricio Pasquier Juan <[email protected]>
# 2013 Brian Candler <[email protected]>
#
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e03735a

Please sign in to comment.