انتقل إلى المحتوى الرئيسي
الوصفة رقم 220

دليل الوصفات · الفصل 13 · الدمج مع أنظمة إدارة المحتوى

علامات بصيغة SVG فوق صور الصفحات، لتقرير

تضع layoutAnnotations وannotationsSvg علامات المصحّح فوق صور صفحات عادية، دون عارض: تقرير بروفات يرسله نظام إدارة المحتوى بالبريد أو يطبعه.

في هذه الصفحة
المستوى
متوسط
Postext
اختُبرت مع Postext 1.103.1
تتطلب ≥ 1.103.0
الترخيص
حُدّثت في 4 ديسمبر 2026
الشيفرة MIT · النص CC BY 4.0
تقرير بروفة مصنوع من صور صفحات PNG والعلامات فوقها بصيغة SVG: استبدال، وتظليل مع استفسار، وكلمة مشطوبة، وملاحظة، وإدراج، مُدرجة تحت الصفحات.
تقرير بروفة مصنوع من صور صفحات PNG والعلامات فوقها بصيغة SVG: استبدال، وتظليل مع استفسار، وكلمة مشطوبة، وملاحظة، وإدراج، مُدرجة تحت الصفحات.
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 125 × 180 مم
  • عمود واحد
  • Newsreader 9.5/13.5
  • Archivo
  • صفحتان
  • المستوى
  • Postext 1.103.1
  • أُخرجت في 57 ms
  • أسطر الشيفرة: 139

باختصار

صفحتان من نشرة للتاريخ المحلي معروضتان صورتين عاديتين، وفوقهما تصحيحات محرّر: عبارة مستبدَلة، وكلمة مشطوبة، واسم مظلَّل، وملاحظة في الهامش، وإضافة.

ما الذي ستنضده

تقرير بروفات لنشرة التاريخ المحلي في Harwick، دون عارض: صفحتا مقال عن خط ترام أُغلق، كل واحدة صورة PNG، وفوق كل صورة العلامات التي تركها المصحّح. عبارة مشطوبة ومستبدَلة، وكلمة محذوفة، واسم مظلَّل للتحقق منه، ورقم عربة عليه ملاحظة في الهامش، وإضافة. تحت الصفحتين قائمة مرقّمة تذكر كل علامة مع صفحتها وكلماتها. يبني نظام إدارة المحتوى صفحة HTML نفسها على خادمه ويرسلها بالبريد الإلكتروني، أو يطبعها ملف PDF بالتعليقات.

تجيب هذه الوصفة عن

  • كيف أضع علامات على صور الصفحات لتقرير أو رسالة بريد إلكتروني، دون عارض؟

الجواب المختصر

script.js · الأسطر 138–149في الشيفرة الكاملة
const shapes = layoutAnnotations(doc, marks, { fontFamily: 'Archivo' });
const sheets = doc.pages.map((page, pageIndex) => {
  const figure = document.createElement('figure');
  const image = new Image(); // a PNG, as a page cache or `postext images` would keep it
  image.src = renderPage(page, doc, { scale: 2 }).toDataURL('image/png');
  image.alt = t({ en: `Page ${pageIndex + 1}`, es: `Página ${pageIndex + 1}` });
  // The SVG has the page's size in page px and a viewBox: it scales with the image.
  figure.innerHTML = annotationsSvg(shapes, page, { pageIndex });
  figure.prepend(image);
  return figure;
});
document.getElementById('sheets').replaceChildren(...sheets);

المكونات

الخطوط
Newsreader, Archivo (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

طريقة التحضير

#1 · انضد الصفحات كما هي في الكتاب

script.js · الأسطر 31–50في الشيفرة الكاملة
const opener = { enabled: true, minHeight: mm(34), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{title}', fontFamily: 'Archivo', fontSize: pt(7),
    fontWeight: 600, letterSpacing: pt(1.4), textTransform: 'uppercase', color: col('accent'),
    placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(4) } } },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Newsreader', fontSize: pt(22),
    lineHeight: 1.1, fontWeight: 600, color: col('ink'), align: 'left', overflow: 'wrap',
    placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(2.5) },
      size: { width: mm(88) } } },
  { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1), color: col('accent'),
    placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(3) },
      size: { width: mm(10) } } },
] } };
const head = { kind: 'text', pages: 'body', fontFamily: 'Archivo', fontSize: pt(6.5),
  fontWeight: 500, letterSpacing: pt(1), textTransform: 'uppercase', color: col('muted') };
const header = { elements: [
  { ...head, id: 'title', content: '{title}', placement: { anchor: { to: 'page', edge: 'top-left' },
    offset: { x: mm(16), y: mm(10) } } },
  { ...head, id: 'folio', content: '{pageNumber}', fontWeight: 600, color: col('accent'),
    placement: { anchor: { to: 'page', edge: 'top-right' }, offset: { x: mm(-16), y: mm(10) } } },
] };

يعرض التقرير الصفحات الحقيقية، فتحتفظ النشرة بتصميمها: افتتاحية قصيرة عنوانها التمهيدي اسم النشرة، وترويسة فيها رقم الصفحة. لا شيء في الإعداد يعرف شيئًا عن العلامات.

#2 · احفظ العلامات نطاقاتٍ من Markdown

script.js · الأسطر 111–134في الشيفرة الكاملة
// Ranges are offsets into the Markdown; `at` finds a phrase that occurs once in the text.
const at = (words) => {
  const start = markdown.indexOf(words);
  return { start, end: start + words.length };
};
const point = (words) => ({ start: at(words).end, end: at(words).end });
const marks = t({
  en: [
    { id: 'm1', kind: 'replace', range: at('two and a half'), text: 'three' },
    { id: 'm2', kind: 'highlight', range: at('Edith Pearce'), comment: 'Spelling: Pierce?' },
    { id: 'm3', kind: 'strike', range: at('early ') },
    { id: 'm4', kind: 'note', range: at('number 9'), label: '1',
      comment: 'The council minutes say car 12.' },
    { id: 'm5', kind: 'insert', range: point('Bridge Street'), text: 'and Mill Lane' },
  ],
  es: [
    { id: 'm1', kind: 'replace', range: at('cuatro kilómetros'), text: 'cinco' },
    { id: 'm2', kind: 'highlight', range: at('Edith Pearce'), comment: '¿Se escribe Pierce?' },
    { id: 'm3', kind: 'strike', range: at('primeros ') },
    { id: 'm4', kind: 'note', range: at('número 9'), label: '1',
      comment: 'Las actas del ayuntamiento dicen coche 12.' },
    { id: 'm5', kind: 'insert', range: point('calle del Puente'), text: 'y del Molino' },
  ],
});

كل علامة سجلّ من سجلات الموقع: معرّف ونوع ونطاق من المواضع في نص Markdown، ومعها النص الجديد للاستبدال أو الإضافة وتسمية الملاحظة. الإضافة تعلّم نقطة، فيبدأ نطاقها وينتهي في الموضع نفسه. الحقل comment ملك الموقع؛ لا تقرؤه layoutAnnotations، والقائمة تحت الصفحات تطبعه.

#3 · ضع فوق كل صورة SVG بالمقاس نفسه

الشيفرة هي الجواب المختصر أعلاه. ترسم renderPage الصفحة بضعف مقاسها، وتحتفظ الصورة بتلك الصورة النقطية؛ وتصلح أي صورة صفحة بالطريقة نفسها، كملف PNG من postext images أو من ذاكرة تخزين الصفحات. تكتب annotationsSvg علامات صفحة واحدة ملفَّ SVG بوحدات px الصفحة ومعه viewBox، فيتغيّر مقاسه مع الصورة حين يملآن الصندوق نفسه. كل علامة عنصر <g data-annotation="m4">، يمكن للقائمة أن تشير إليه وللـ CSS أن ينسّقه. تصف وثائق علامات التعليق كل الأنواع.

الوصفة كاملة

// ═══ Postext Cookbook · Nº 220 · Marks as SVG over page images ═════════════════════════
// https://postext.dev/en/cookbook/marks-as-svg-over-pages
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Newsreader, Archivo (SIL OFL 1.1) · Needs postext ≥ 1.103.0
//
// A proof report with no viewer: each page of a local history bulletin as a plain image, the
// editor's marks laid over it as SVG, and the list of marks under the pages. A content system
// could send the same HTML in an e-mail or print it to a PDF of comments.
import { buildDocumentWithFonts, renderPage, renderPageToCanvas } from 'https://esm.sh/postext';
import { layoutAnnotations, annotationsSvg } from 'https://esm.sh/postext/annotate';

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

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
  ink: '#1d1f22', // text
  accent: '#2d5e57', // a tram-livery green: kicker, rule, folios
  muted: '#676c70', // running heads
};
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
const LEAD = 13.5; // pt of body leading

// #region bulletin: a society bulletin's page, a short opener and a running head
const opener = { enabled: true, minHeight: mm(34), slot: { elements: [
  { kind: 'text', id: 'kicker', content: '{title}', fontFamily: 'Archivo', fontSize: pt(7),
    fontWeight: 600, letterSpacing: pt(1.4), textTransform: 'uppercase', color: col('accent'),
    placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(4) } } },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Newsreader', fontSize: pt(22),
    lineHeight: 1.1, fontWeight: 600, color: col('ink'), align: 'left', overflow: 'wrap',
    placement: { anchor: { to: '#kicker', edge: 'below' }, offset: { y: mm(2.5) },
      size: { width: mm(88) } } },
  { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(1), color: col('accent'),
    placement: { anchor: { to: '#title', edge: 'below' }, offset: { y: mm(3) },
      size: { width: mm(10) } } },
] } };
const head = { kind: 'text', pages: 'body', fontFamily: 'Archivo', fontSize: pt(6.5),
  fontWeight: 500, letterSpacing: pt(1), textTransform: 'uppercase', color: col('muted') };
const header = { elements: [
  { ...head, id: 'title', content: '{title}', placement: { anchor: { to: 'page', edge: 'top-left' },
    offset: { x: mm(16), y: mm(10) } } },
  { ...head, id: 'folio', content: '{pageNumber}', fontWeight: 600, color: col('accent'),

يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

تنويعات

#ادمج كل صفحة في صورة PNG واحدة للبريد

كثير من برامج البريد لا ترسم SVG المضمَّن؛ ارسم العلامات على canvas الصفحة بـ paintAnnotations (استوردها مع annotationsSvg) وأرسل صورة واحدة.

-  image.src = renderPage(page, doc, { scale: 2 }).toDataURL('image/png');
+  const canvas = renderPage(page, doc, { scale: 2 });
+  const ctx = canvas.getContext('2d');
+  paintAnnotations(ctx, shapes, { pageIndex, scale: 2 });
+  image.src = canvas.toDataURL('image/png'); // the page and its marks in one bitmap
-  figure.innerHTML = annotationsSvg(shapes, page, { pageIndex });

#ضع كل الملاحظات في الهامش الخارجي

تذهب راية الملاحظة افتراضيًا إلى الهامش الأقرب؛ أما noteSide: 'end' فترسلها كلها إلى الهامش الأيمن لهذه الصفحة التي تُقرأ من اليسار إلى اليمين.

-const shapes = layoutAnnotations(doc, marks, { fontFamily: 'Archivo' });
+const shapes = layoutAnnotations(doc, marks, { fontFamily: 'Archivo', noteSide: 'end' });

الحقوق

الوصفة
Ignacio Ferro
النص
نص أصلي, CC BY 4.0
الخطوط
Newsreader (SIL OFL 1.1) · Archivo (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext