Class: Markdownator::Converters::Pptx

Inherits:
Base
  • Object
show all
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

Returns:

  • (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, **_options)
  Markdownator.require_optional("zip", feature: "PPTX conversion")
  Markdownator.require_optional("nokogiri", feature: "PPTX conversion")

  sections = []
  ::Zip::File.open_buffer(io) do |zip|
    slides = zip.entries.select { |e| e.name.match?(SLIDE_PATTERN) }
    slides.sort_by! { |e| e.name[SLIDE_PATTERN, 1].to_i }
    slides.each_with_index do |entry, index|
      sections << render_slide(entry.get_input_stream.read, index + 1)
    end
  end
  Result.new(markdown: sections.join("\n\n"))
end