class Decidim::Proposals::DocToMarkdown
This class parses a participatory text document in markdown and produces Proposals
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 MarkdownToProposals
does is to implement callbacks for the blocks which it is interested in performing some actions.
Constants
- ACCEPTED_MIME_TYPES
Accepted mime types keys: are used for dynamic help text on admin form. values: are used to validate the file format of imported document.
- DOCX_MIME_TYPE
- MARKDOWN_MIME_TYPE
- ODT_MIME_TYPE
- TEXT_PLAIN_MIME_TYPE
sometimes markdown documents are classified as text/plain
Public Class Methods
new(doc, mime_type)
click to toggle source
Public: Initializes the serializer with a proposal.
# File lib/decidim/proposals/doc_to_markdown.rb, line 31 def initialize(doc, mime_type) @doc = doc @transformer = case mime_type # when MARKDOWN_MIME_TYPE # no transformer required when ODT_MIME_TYPE # convert libreoffice odt to markdown OdtToMarkdown.new(doc) when DOCX_MIME_TYPE # convert word 2013 docx to markdown DocxToMarkdown.new(doc) end end
Public Instance Methods
to_md()
click to toggle source
# File lib/decidim/proposals/doc_to_markdown.rb, line 45 def to_md @transformer ? @transformer.to_md : @doc end