Repository navigation
[Data Liberation] Add EPub to Blocks converter - #2097
Conversation
On the surface this seems nice, then folks could program against a common interface. I'd like to have a good understanding of what the common interface would be and how it would be used. An example might be the selectors work that could be used to navigate documents this common interface. Would the tag processor also implement this interface? Is the tag processor expected to be the base class for many of these other processors? I also wonder if there are enough subtle differences that the common interface would be cumbersome without much tangible benefit. Again from the selectors work, when matching the ID selector, it needs to know if the document is in quirks mode to determine whether the match is case sensitive or insensitive. That's a purely HTML concept. Maybe XML documents are documents that are never in quirks mode, but it's something to think about. |
|
@sirreal all good points! Maybe we'd need a separate XHTML processor to integrate the selectors work, then, and the common interface would apply to XHTML and HTML, not XML and HTML. |
|
Selectors are a great interface for navigating trees, they're a great fit for XML. I just wanted to mention a quirk (😉) I noticed with selectors matching the HTML Processor. I'd love for something like |
Description TBD Use WP_XML_Reader for EPubs, support simple DOCTYPE declarations in XML Parse EPubs as XHTML
58def6c to
ee381d4
Compare
Adds
WP_EPub_Entity_Readerto parse EPub files into WordPress posts and post meta:A part of #1894
Implementation details
EPub are ZIP files containing content represented as XHTML. They may include other assets, too, e.g., CSS, images, table of contents, metadata, etc.
This PR glues together WP_Zip_Filesystem with WP_HTML_To_Blocks to find all the XHTML files in the zip and convert them to block markup.
Since XHTML uses XML syntax that cannot be parsed via
WP_HTML_Processor, we useWP_XML_Processorinstead. To support XHTML, this PR adds support for parsing simple<!DOCTYPE html>declarations in WP_XML_Processor.This PR also enables swapping
WP_HTML_ProcessorforWP_XML_ProcessorinWP_HTML_To_Blocksby adding aWP_XML_Processor::expects_closer()method. It doesn't have exactly the same semantics as theWP_HTML_Processorone, but it's close enough.Remaining work
Right now, we're guessing the location of all the XML files. It works for the test example above, but to support all the epub files out there, we'd need to:
META-INF/container.xmlconfig file to get the root file path.Open questions
WP_Markup_Processorinterface to represent a subset of methods shared between the HTML processor and the XML processor?class WP_XHTML_Processor extends WP_XML_Processorto align the semantics ofexpects_closer()and other overlapping methods?OEBPSandEPUBdirectories inside the epub file? Or can XHTML be stored under another path? How would we know?cc @ellatrix @dmsnell @zaerl @brandonpayton @sirreal