Skip to main content

Module export

Module export 

Source
Expand description

The export export: renders one of the manifest’s [[exporters]] formats from the story, and returns the file’s bytes.

An exporter whose manifest entry sets images = true gets the files of the images the story shows in Request::images, and with cover = true as well, the project’s cover. In markdown, an image is ![image](hammer://image/<id>), which crate::images reads; in prose, a line holding only an image is a block {"type": "image", "id": 5, "name": "Map"}, which prose_image_id reads. An image inside a line, or one whose file Hammer could not read, is its name as text, never a block.

ⓘ
let request: hammer::export::Request = hammer::input_json()?;
for scene in request.chapters.iter().flat_map(|chapter| &chapter.scenes) {
    for id in hammer::images::find_ids(scene) {
        if let Some(image) = request.image(id) { /* image.content holds the file */ }
    }
}

An exporter whose manifest entry sets output = "archive" returns an Archive instead: files that Hammer zips, in order, into the one export file, whose extension and mime the manifest still gives (zip and application/zip). An image Hammer sent is named by its id, and Hammer writes its bytes, so the reply carries none.

ⓘ
let mut archive = hammer::export::Archive::new();
archive.text("story.md", story)?;
for image in &request.images {
    archive.image(&format!("images/{}.{}", image.id, image.extension), image)?;
}
archive.to_json()

Structs§

Archive
What the export export returns, as Archive::to_json, for a format whose manifest entry sets output = "archive": files Hammer zips in the order they were added.
Chapter
A chapter’s scenes: as markdown in scenes, or, for a format whose manifest entry sets input = "prose", in prose as Hammer’s parsed blocks, one list of blocks per scene.
Image
A project image and its file: image.get’s crate::ops::ImageContent with mime_type added.
Request

Traits§

ArchiveImage
What Archive::image names an image of Request::images by: its id, or the Image itself.

Functions§

prose_image_id
The id of a prose image block, {"type": "image", "id": 5, "name": "Map"}; none for any other block.