Notation
The same characters mean different things to different writers. * is a scene
break in a novel and emphasis in a technical text; 漢字((かんじ)) is ruby on a
novel site and a footnote in MejiroPDF. A single grammar would mangle one of
them, so you choose the notation, once, for the whole book:
// Web novels:
new Document($info, notation: Notation::novel());
// Manuscripts shared with MejiroPDF:
new Document($info, notation: Notation::mejiro());
// Notation::plain(), the default: nothing is markup.
new Document($info);
The default is plain(), so nothing is reinterpreted unless you ask.
Notations never mix: each reads its own constructs and passes everything else
through as text.
Notation::novel() — web-novel sites
| Write | Becomes |
|---|---|
|吾輩《わがはい》 or |吾輩《わがはい》 | ruby on the text after the bar |
【MejiroEPUB】(めじろ) | ruby on anything in the brackets, kanji or not |
見当(けんとう) 見当((けんとう)) 見当((けんとう)) | ruby on the run of kanji before the brackets (implicit ruby) |
《《静かに》》 | emphasis dots |
Nothing else is markup: *, ~, ^, [, \ and kaomoji such as \(^o^)/
come out exactly as typed.
Implicit ruby applies when the brackets hold only hiragana or katakana and
follow a run of kanji. It misfires on a parenthetical written as one —
東京(とうきょう) becomes ruby even if the writer meant brackets. That is how
web-novel sites themselves behave on screen, and an EPUB that disagreed with the
site's own pages would be the worse surprise. If your writers do not use
implicit ruby, turn it off:
Notation::novel(implicitRuby: false);
Notation::mejiro() — MejiroPDF's syntax
For manuscripts you also typeset with MejiroPDF — technical writing, textbooks. The pattern is MejiroPDF's own, character for character, and is tested against MejiroPDF's tokenizer case by case.
| Write | Becomes |
|---|---|
**太字** / *斜体* | <strong> / <em> |
~~取消~~ / ==蛍光== | <s> / <mark> |
|漢字《かんじ》 / {東京|とうきょう} | ruby |
《《傍点》》 or [傍点]{.bouten} | emphasis dots |
^24^ or [24]{.tcy} | tate-chu-yoko |
[MejiroPDF](https://mejiropdf.com) | a link (http, https and mailto only) |
((注の本文)) | a footnote |
[小見出し]{.subhead} | makes the whole line a subheading (<h3>), wherever on the line it is |
[続く]{.keepnext} | asks the reader to keep the whole line with the next one |
[字]{.bold .italic .underline .strikethrough} | the same as the marks above; several words nest, the later one inside |
[字]{color=#C00 bg=#FFFFEE} | text and background colour (#rgb or #rrggbb) |
\* | a literal * — any character after \ |
Constructs nest as they do in MejiroPDF: **[link](https://…)** is a bold link.
What EPUB does not carry
Some MejiroPDF features do not belong in a reflowable book. They are dropped with the text kept, and each kind of problem is logged as a warning once per book through your PSR-3 logger:
| Written | Why it is dropped |
|---|---|
size=20pt | a fixed size would override the reader's own size setting |
.dropcap | reading systems support it too unevenly to rely on |
| an unknown attribute word | there is nothing to write |
color=red (a name, not a hex value) | only #rgb / #rrggbb are accepted |
[x](javascript:…), a relative path, file: | only http, https and mailto become links; the rest is written as typed |
Notation::plain() — nothing is markup
Every character is text. For logs, imported material, anything without markup.
Building a paragraph from parts
When your text is already structured — ruby in separate database columns, say — build the paragraph instead of writing notation into a string. Parts are never reinterpreted, whatever the document's notation:
use MejiroEPUB\Text\Paragraph;
$book->section('第一話', [
Paragraph::of()
->text(' ')
->ruby('東京', 'とうきょう')
->text('で')
->emphasis('静かに')
->text('待った。')
->tcy('12')
->text('時。')
->footnote('注の本文'),
Paragraph::blank(),
' 次の段落は記法として読まれる。',
]);
Escaping is the library's job
Pass text as you stored it. <, & and quotes are escaped, characters XML
does not allow are removed, broken UTF-8 is repaired (and logged), and link
targets and colours are validated before they reach an attribute. There is no
way for body text to inject markup.