Skip to content
API

CLI quickstart

Install

Terminal window
cargo install --git https://github.com/zachhannum/fleuron fleuron-cli
fleuron fixtures/corpus/pride-and-prejudice.md -c fixtures/styled.css -o book.pdf
fleuron: fixtures/corpus/pride-and-prejudice.md → book.pdf: 445 pages
Chapter 1t is a truth universally acknowledged, that a single man inIpossession of a good fortune, must be in want of a wife.However little known the feelings or views of such a manmay be on his first entering a neighbourhood, this truth is sowell fixed in the minds of the surrounding families, that he isconsidered the rightful property of some one or other of theirdaughters."My dear Mr. Bennet," said his lady to him one day, "have youheard that Netherfield Park is let at last?"Mr. Bennet replied that he had not."But it is," returned she; "for Mrs. Long has just been here,and she told me all about it."Mr. Bennet made no answer."Do you not want to know who has taken it?" cried his wifeimpatiently."You want to tell me, and I have no objection to hearing it."This was invitation enough."Why, my dear, you must know, Mrs. Long says thatNetherfield is taken by a young man of large fortune from thenorth of England; that he came down on Monday in a chaise andfour to see the place, and was so much delighted with it, that heagreed with Mr. Morris immediately; that he is to take possession1
page 1
Page 1 of book.pdf, from the manuscript and the stylesheet the command above read. Edit the manuscript here and it is set again.

Multi-file books

Multiple markdown files can be passed to the CLI. The engine combines all of the files into a single output.

Terminal window
fleuron front.md ch01.md ch02.md ch03.md -o book.pdf

The tree records each file’s name, so a diagnostic points at the file the trouble is in.

Book metadata

One markdown file is a whole book, so its frontmatter is the book’s. Several are chapters, and a chapter’s frontmatter describes the chapter: its title: names that section, and the book is left unnamed. That leaves the work’s own title and author to the command line:

Terminal window
fleuron ch01.md ch02.md ch03.md -o book.pdf \
--title "The Levant Papers" --author "E. Marsh"

A flag outranks frontmatter where the two overlap, so you can retitle a single file without editing it.

Where sections begin

A section is what the fragmenter opens a page on, so where sections begin decides the page count before any styling does. --split names the rule:

Terminal window
fleuron manuscript.md -o book.pdf --split 2

A heading at level 2 or shallower opens a section, which suits a manuscript that sets parts with # and chapters with ##. The default is --split 1. --split none opens no section at a heading at all, so in a vault of one chapter per file the file is the section.

--dialect sets which markdown is being read: fleuron, commonmark, gfm or obsidian. fleuron is the default: CommonMark, a frontmatter block and attribute lines. Under commonmark a brace run is prose. See the markdown mapping for what each construct becomes and which of them warn.

Adding your own styling

Stylesheets cascade in the order the command line gives them, over the built-in sheet rather than instead of it:

Terminal window
fleuron manuscript.md -o book.pdf -c house.css -c series.css

So house.css sets the press’s defaults and series.css overrides the handful of things this series does differently. Author CSS outranks the built-in sheet whatever the specificity of the built-in rule, so you never have to out-specify a default you are replacing.

@page {
size: 5.5in 8.5in;
margin: 48pt 40pt 56pt 60pt;
@bottom-center { content: counter(page); font-size: 8pt; }
}
book { font-size: 12pt; line-height: 1.5; }
h1, h2, h3 { font-size: 20pt; }

The CSS subset is everything the engine supports. Anything else becomes a warning on stderr naming the line and column, and the PDF is written regardless.

Fonts

@font-face urls are resolved as paths: first against the directory of the stylesheet that asked for them, then against the working directory.

@font-face {
font-family: "House Serif";
src: url("faces/house.ttf");
}

A face that resolves nowhere warns and the text falls back. See fonts.

Writing an EPUB

If the output path ends in .epub, the CLI writes a reflowable EPUB rather than a PDF. The following example writes the fixture book as an EPUB, with the fixture stylesheet:

Terminal window
fleuron fixtures/gulliver-excerpt.md -o book.epub -c fixtures/styled.css
fleuron: fixtures/gulliver-excerpt.md → book.epub: 1 document

The summary counts documents rather than pages. There is one document for each section. The reading system on the device makes the pages. The other flags work the same as for a PDF.

The stylesheet goes into the EPUB, less the CSS that describes pages. Fleuron leaves out that CSS with no warning, because the PDF uses it. CSS in an EPUB lists that CSS. EPUB covers what the EPUB holds.

Reading the tree back

To see what the frontend made of a manuscript, which heading opened a section, or where a construct degraded, dump the content tree instead of laying it out:

Terminal window
fleuron manuscript.md --dump-tree

It goes to stdout, and the same manuscript dumps the same bytes every time.

What it prints

The summary line goes to stderr, so fleuron manuscript.md -o /dev/stdout is still a PDF on stdout. Warnings follow it, one per line, and then a count. The reference has the exit codes.