本文へスキップ
レシピ番号214

レシピ集 · 第13章 · CMSへの組み込み

校正記号:削除・置換・挿入

編集者の赤字を postext-viewer で組んだ小説のページに描く。削除線、上に書いた差し替え、挿入の記号を Markdown の範囲から置く。

このページの内容
出力
Canvas
レベル
中級
Postext
Postext 1.103.1で検証済み
1.103.0以上が必要
ライセンス
2026年12月4日更新
コードMIT · 本文CC BY 4.0
初校のページ上に五つの訂正を描いたもの:消した語、行の上に書いた差し替え、挿入記号。それぞれ横の一覧に名前が出る。
初校のページ上に五つの訂正を描いたもの:消した語、行の上に書いた差し替え、挿入記号。それぞれ横の一覧に名前が出る。
  • 英語の見本:日本語版はまだありません
  • 仕上がり130 × 200 mm
  • 1段
  • Libre Caslon Text 10/16
  • 1ページ
  • レベル
  • Postext 1.103.1
  • 組版時間60 ms
  • コード107行

かんたんな説明

短編小説の1ページ目に編集者の赤字を入れ、校正ツールのように表示します。消した語、古い語の上に書いた新しい語、語が抜けているところの小さな記号です。横のリストが各修正を並べます。

できあがり

短編小説 Platform Two の冒頭ページに、原稿整理者が初校で入れた赤字を描きます。重複した語と余分な very は赤い線で消してあり、lain と recieved は消したうえで正しい語をすぐ上の小さなラベルに書いてあります。行の下の緑の記号は in が抜けている場所を示します。右のリストには同じ五つの修正が並び、それぞれ今の語句と差し替える語句を示します。ページ上の印を押すか、Tab キーで移って Enter を押すと、その項目が選ばれます。

このレシピが答える質問

  • 組版したページの上に、削除・置換・挿入の校正記号を表示するには?

手短な答え

script.js · 107〜116行コード全体で見る
const view = createViewer(document.getElementById('viewer'), {
  document: doc, markdown, zoom: 'fit-width', labels: L.viewer,
  annotations: edits, // strike, replace (text over the struck words) and insert (a caret)
});
const entries = new Map(edits.map((e) => [e.id, entry(e)]));
const pick = (id) => {
  for (const [key, li] of entries) li.classList.toggle('active', key === id);
};
view.on('annotationclick', ({ id }) => pick(id)); // pointer, Enter or Space
pick('e2');

材料

種類
Libre Caslon Text (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · 行の間に余白を取る

script.js · 30〜51行コード全体で見る
const config = {
  locale: t({ en: 'en-gb', es: 'es' }),
  colorPalette,
  page: { sizePreset: 'custom', width: mm(130), height: mm(200), dpi: 150,
    margins: { top: mm(22), bottom: mm(24), left: mm(18), right: mm(18) } },
  layout: { layoutType: 'single' },
  bodyText: { fontFamily: 'Libre Caslon Text', fontSize: pt(10), lineHeight: pt(16),
    color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
    textAlign: 'justify', firstLineIndent: mm(5), indentAfterHeading: false,
    hyphenation: { enabled: true }, optimalLineBreaking: true,
    avoidWidows: true, avoidOrphans: true, avoidRunts: true },
  headings: { fontFamily: 'Libre Caslon Text', color: col('accent'), fontWeight: 400, levels: [
    { level: 1, fontSize: pt(22), lineHeight: pt(28), italic: true,
      marginTop: pt(16), marginBottom: pt(24) },
  ] },
  header: { elements: [] },
  footer: { elements: [
    { kind: 'text', id: 'folio', content: '{pageNumber}', fontFamily: 'Libre Caslon Text',
      fontSize: pt(9), color: col('accent'), align: 'center',
      placement: { anchor: { to: 'page', edge: 'bottom-center' }, offset: { y: mm(-12) } } },
  ] },
};

置換と挿入のラベルは本文の 0.62 em の大きさで、直す行のすぐ上、行間に立ちます。10 pt の文字に 16 pt の行送りなら余裕があり、ラベルが上の行を隠す部分はわずかです。行送りが詰まっていても、ラベルには紙の色の下地が敷かれるので両方とも読めます。

#2 · 各修正を範囲として保存する

script.js · 81〜95行コード全体で見る
// [kind, a quote that finds the place, the words marked in it, the new text]
// A tool stores the offsets; the pen finds them from quotes so that both editions run.
const edits = t({
  en: [['strike', 'for for forty', 'for '], ['replace', 'had lain her', 'lain', 'laid'],
    ['strike', 'the very last', 'very '], ['replace', 'had recieved a', 'recieved', 'received'],
    ['insert', 'nothing the dark', 'the dark', 'in ']],
  es: [['replace', 'habían dos faroles', 'habían', 'había'],
    ['replace', 'había recivido', 'recivido', 'recibido'], ['insert', 'segura que', 'que', 'de '],
    ['strike', 'todo el el valle', 'el '], ['strike', 'subió arriba', ' arriba']],
}).map(([kind, quote, words, text], i) => {
  const start = markdown.indexOf(quote) + quote.indexOf(words);
  // An insertion marks a point: the range is empty, before the words that follow it.
  const end = kind === 'insert' ? start : start + words.length;
  return { id: `e${i + 1}`, kind, range: { start, end }, text };
});

削除と置換は変える語句に印を付け、置換はさらに新しい text を持ちます。挿入は一点を示すので範囲は空(start === end)で、記号はそのオフセットの行の下に付きます。修正を受け入れるときに applyEdits が受け取るのも、これと同じ記録です。

#3 · 描いて、押されたことを聞く

コードは上の手短な答えです。ビューアーは各行の向きに沿って印を置くので、削除線は文字の中ほどを横切り、置換は語句の上に立ちます。右から左のページや縦組のページでも同じです。annotationclick はポインターで押したときにも、印の上で Enter や Space を押したときにも出ます。各印は「Replacement: laid」という名前のキーボード用ボタンだからです。

レシピの全体

// ═══ Postext Cookbook · Nº 214 · Proofreading marks: strike, replace and insert ══════
// https://postext.dev/en/cookbook/proofreading-marks-on-pages
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Libre Caslon Text (SIL OFL 1.1) · Needs postext ≥ 1.103.0
//
// The first page of a short story with an editor's corrections drawn on it, as a proofing
// tool shows them: struck words, a replacement written over the words it replaces, and a
// caret where a word goes in. The list beside the page is the same corrections; pressing a
// mark, with the pointer or the keyboard, picks its entry.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { createViewer } from 'https://esm.sh/postext-viewer';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'proofreading-marks-on-pages';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
  ink: '#1d1b19', // text
  accent: '#5b4a8a', // a dusk violet: the story's title and the folios
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.accent, model: 'hex' } },
];
// #endregion

// #region page: a short-story page with generous leading, room for the marks between lines
const config = {
  locale: t({ en: 'en-gb', es: 'es' }),
  colorPalette,
  page: { sizePreset: 'custom', width: mm(130), height: mm(200), dpi: 150,
    margins: { top: mm(22), bottom: mm(24), left: mm(18), right: mm(18) } },
  layout: { layoutType: 'single' },
  bodyText: { fontFamily: 'Libre Caslon Text', fontSize: pt(10), lineHeight: pt(16),
    color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
    textAlign: 'justify', firstLineIndent: mm(5), indentAfterHeading: false,
    hyphenation: { enabled: true }, optimalLineBreaking: true,
    avoidWidows: true, avoidOrphans: true, avoidRunts: true },
  headings: { fontFamily: 'Libre Caslon Text', color: col('accent'), fontWeight: 400, levels: [
    { level: 1, fontSize: pt(22), lineHeight: pt(28), italic: true,
      marginTop: pt(16), marginBottom: pt(24) },
  ] },
  header: { elements: [] },
  footer: { elements: [
    { kind: 'text', id: 'folio', content: '{pageNumber}', fontFamily: 'Libre Caslon Text',
      fontSize: pt(9), color: col('accent'), align: 'center',

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#修正をすべて受け入れる

https://esm.sh/postext/annotate から applyEdits を読み込み、修正を Markdown に書き込んで新しい組版を表示します。

 view.on('annotationclick', ({ id }) => pick(id)); // pointer, Enter or Space
+const { markdown: fixed } = applyEdits(markdown, edits.map((e) => ({ ...e.range, text: e.text ?? '' })));
+view.setDocument(await buildDocumentWithFonts({ markdown: fixed }, config, kitFonts(FONTS)), fixed);
+view.setAnnotations([]);

#ラベルを本の書体で組む

印が自分で組む文字は、指定がなければ system-ui です。

   document: doc, markdown, zoom: 'fit-width', labels: L.viewer,
+  marks: { fontFamily: 'Libre Caslon Text' },

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
フォント
Libre Caslon Text (SIL OFL 1.1)