Skip to content
Snippets Groups Projects
Commit 0e4749d7 authored by fauno's avatar fauno
Browse files

convert from other formats

parent 28167871
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ require_relative 'jekyll/pandoc/generators/category'
require_relative 'jekyll/pandoc/generators/site'
require_relative 'jekyll/pandoc/generators/imposition'
require_relative 'jekyll/pandoc/generators/binder'
require_relative 'jekyll/pandoc/converter'
# We modify the configuration post read, and not after init, because
# Jekyll resets twice and any modification to config will invalidate the
......
# frozen_string_literal: true
require 'jekyll/converter'
require_relative 'paru_helper'
module Jekyll
module Pandoc
module Converter
# Input formats supported by Pandoc that make sense to convert
# into HTML.
#
# @return [Array]
# @param ext [String]
# @return [Boolean]
def matches(ext)
".#{self.class::EXT}" == ext.downcase
end
# Convert into HTML
#
# @return [String]
def output_ext(_)
'.html'
end
# @param content [String]
# @return [String]
def convert(content)
parser << content
end
private
# Generates a parser from config
#
# @return [Paru::Pandoc]
def parser
@parser ||= ParuHelper.from(from: self.class::EXT, to: 'html5', metadata: 'title=Jekyll',
**@config['pandoc'].options[:html5])
end
end
end
end
%w[creole docbook docx dokuwiki haddock ipnyb jira mediawiki man muse odt org rst t2t textile tikiwiki twiki
vimwiki].each do |format|
converter = Class.new(Jekyll::Converter)
converter.class_exec(format) do |f|
const_set :EXT, f
include Jekyll::Pandoc::Converter
safe true
end
Object.const_set format.capitalize, converter
end
......@@ -36,7 +36,8 @@ module Jekyll
f.write content
end
ParuHelper.from(from: 'markdown', to: type, **site.config['pandoc'].options[type], **extra) << content
ParuHelper.from(from: document.extname.sub('.', ''), to: type, **site.config['pandoc'].options[type],
**extra) << content
end
# Don't convert Markdown to HTML, but do convert everything else
......@@ -44,7 +45,7 @@ module Jekyll
# @return [array]
def converters
@converters ||= super.reject do |c|
c.instance_of? Jekyll::Converters::Markdown
c.instance_of?(Jekyll::Converters::Markdown) || c.instance_of?(Jekyll::Pandoc::Converter)
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment