Sha256: 53ea2c6d1f93f63a55164a7b80caba2ff4de2d423e57fb6422c53e05b12c1f41
Contents?: true
Size: 1.23 KB
Versions: 6
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true require "doc2text" require "tempfile" module Decidim module EnhancedTextwork # This class parses a participatory text document in markdown and # produces Paragraphs in the form of sections and articles. # # This implementation uses Redcarpet Base renderer. # Redcarpet::Render::Base performs a callback for every block it finds, what MarkdownToParagraphs # does is to implement callbacks for the blocks which it is interested in performing some actions. # class OdtToMarkdown # Public: Initializes the serializer with a paragraph. def initialize(doc) @doc = doc end def to_md doc_file = doc_to_tmp_file md_file = transform_to_md_file(doc_file) md_file.read end #----------------------------------------------------- private #----------------------------------------------------- def doc_to_tmp_file file = Tempfile.new("doc-to-markdown-odt", encoding: "ascii-8bit") file.write(@doc) file end def transform_to_md_file(doc_file) md_file = Tempfile.new Doc2Text::Odt::Document.parse_and_save doc_file, md_file md_file end end end end
Version data entries
6 entries across 6 versions & 1 rubygems