lib/coconductor/vendorer.rb in coconductor-0.8.2 vs lib/coconductor/vendorer.rb in coconductor-0.8.3

- old
+ new

@@ -1,18 +1,20 @@ require 'fileutils' require 'open-uri' require 'toml' require 'reverse_markdown' require 'logger' +require 'wikicloth' +require 'twitter-text' # Used in development to vendor codes of conduct module Coconductor class Vendorer attr_reader :family, :repo attr_writer :ref, :raw_content - OPTIONS = %i[filename url repo replacements html source_path].freeze + OPTIONS = %i[filename url repo replacements html source_path wiki].freeze INVALID_CHARS = ["\u202D", "\u202C", "\u200E", "\u200F"].freeze UPPERCASE_WORD_REGEX = /(?:[A-Z]{3,}+ ?)+[A-Z_]+/ UNMARKED_FIELD_REGEX = /(?<= |^)#{UPPERCASE_WORD_REGEX}(?= |\.|,)/ def initialize(family, options = {}) @@ -101,11 +103,11 @@ URI.open(url).read if url end def content_normalized content = raw_content.dup.gsub(Regexp.union(INVALID_CHARS), '') - content = ReverseMarkdown.convert content if html? + content = to_markdown(content) replacements.each { |from, to| content.gsub!(from, to) } content = normalize_implicit_fields(content) content.gsub!(/ ?{% .* %} ?/, '') content.squeeze(' ').strip end @@ -115,10 +117,21 @@ m.tr(' ', '_') end content.gsub(UNMARKED_FIELD_REGEX) { |m| "[#{m}]" } end + def to_markdown(content) + options = { data: content, noedit: true, fast: false } + content = WikiCloth::Parser.new(options).to_html if wiki? + content = ReverseMarkdown.convert content if html? || wiki? + content + end + def html? @html == true + end + + def wiki? + @wiki == true end end end