Class: Markdownator::Converters::Pptx
- Defined in:
- lib/markdownator/converters/pptx.rb
Overview
Converts a PowerPoint .pptx deck into Markdown: a ‘## Slide N` heading per slide followed by its text (one line per paragraph).
Constant Summary collapse
- SLIDE_PATTERN =
%r{\Appt/slides/slide(\d+)\.xml\z}.freeze
Instance Method Summary collapse
Instance Method Details
#accepts?(_io, stream_info) ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/markdownator/converters/pptx.rb', line 10 def accepts?(_io, stream_info) matches?( stream_info, extensions: %w[pptx], mimetypes: %w[application/vnd.openxmlformats-officedocument.presentationml.presentation] ) end |
#convert(io, _stream_info, **_options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/markdownator/converters/pptx.rb', line 18 def convert(io, _stream_info, **) Markdownator.require_optional("zip", feature: "PPTX conversion") Markdownator.require_optional("nokogiri", feature: "PPTX conversion") sections = [] ::Zip::File.open_buffer(io) do |zip| = zip.entries.select { |e| e.name.match?(SLIDE_PATTERN) } .sort_by! { |e| e.name[SLIDE_PATTERN, 1].to_i } .each_with_index do |entry, index| sections << (entry.get_input_stream.read, index + 1) end end Result.new(markdown: sections.join("\n\n")) end |