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

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

دفتر القارئ: ملاحظات على ما يحدده من نص

حدّد مقطعًا من كتاب مدرسي واكتب عليه ملاحظة: تتلوّن الكلمات، وتظهر راية مرقّمة في الهامش، ويجمع دفترٌ الملاحظات كلها في قائمة.

في هذه الصفحة
المُخرَج
Canvas
المستوى
متوسط
Postext
اختُبرت مع Postext 1.103.1
تتطلب ≥ 1.103.0
الترخيص
حُدّثت في 4 ديسمبر 2026
الشيفرة MIT · النص CC BY 4.0
تطبيق الدراسة عند فتحه: ثلاث ملاحظات على الفصل 4، كل مقطع ملوّن وله راية مرقّمة في الهامش الخارجي، والدفتر يسردها بكلماتها وصفحاتها.
تطبيق الدراسة عند فتحه: ثلاث ملاحظات على الفصل 4، كل مقطع ملوّن وله راية مرقّمة في الهامش الخارجي، والدفتر يسردها بكلماتها وصفحاتها.
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 170 × 240 مم
  • عمود واحد
  • Source Serif 4 10.5/15
  • Source Sans 3
  • صفحتان
  • المستوى
  • Postext 1.103.1
  • أُخرجت في 57 ms
  • أسطر الشيفرة: 224

باختصار

كتاب تاريخ في تطبيق للدراسة. تحدّد بضع كلمات فتنفتح تحتها بطاقة لكتابة ملاحظة. تأخذ الكلمات لونًا خفيفًا وتسمية مرقّمة في الهامش. وإلى جانب الكتاب قائمة بكل الملاحظات، تفتح أيًّا منها فوق الصفحة.

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

فصل من كتاب تاريخ مدرسي، When books became cheap («حين صارت الكتب رخيصة»)، في تطبيق للدراسة. تحدّد طالبة مقطعًا فتنفتح تحته بطاقة فيها الكلمات مقتبسة ومربع للكتابة. عند الحفظ يتلوّن المقطع وتظهر راية مرقّمة في الهامش الخارجي العريض. الراية، أو الكلمات الملوّنة، تفتح الملاحظة فوق الصفحة مع زرّين لتعديلها أو حذفها. والدفتر على اليمين يسرد الملاحظات كلها بترتيب القراءة، مع الكلمات التي تتناولها وصفحتها: ورقة المراجعة التي يجمعها الطالب وهو يقرأ. تبقى الملاحظات على جهاز الطالب في صورة مراسٍ، فتبقيها الطبعة المصحَّحة من الكتاب على كلماتها.

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

  • كيف أتيح للقرّاء كتابة ملاحظة على فقرة يحدّدونها وعرض ملاحظاتهم في قائمة؟

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

script.js · الأسطر 137–158في الشيفرة الكاملة
const view = createViewer($('viewer'), {
  document: doc, markdown, zoom: 'fit-width', maxZoom: 0.85, labels: L.viewer,
  marks: { noteSide: 'end' }, // the flags in the wide outer margin
});
let card = null; // what the card over the page shows: { range } to write, { id } to read
view.on('select', ({ range }) => {
  const same = card?.range && card.range.start === range?.start && card.range.end === range?.end;
  if (range && range.end > range.start && !same) compose({ range });
});
view.on('annotationclick', ({ id }) => read(id));
function addNote(range, body) {
  notes = [...notes, { id: nextId(), body, range }];
  save();
  render();
}
function render() {
  notes.sort((a, b) => a.range.start - b.range.start);
  view.setAnnotations(notes.map(({ id, range }, i) => ({
    id, kind: 'note', range, label: String(i + 1), color: INK,
  })));
  renderNotebook();
}

المكونات

الخطوط
Source Serif 4, Source Sans 3 (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

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

#1 · احفظ كل ملاحظة مع مرساة

script.js · الأسطر 112–133في الشيفرة الكاملة
const KEY = `${RECIPE}:${LANG}`;
const quote = (text) => {
  const start = markdown.indexOf(text);
  return { start, end: start + text.length };
};
const seed = t({
  en: [['the skins of some two hundred calves', 'A Bible cost a herd of calves. Compare with a house today.'],
    ['used again', 'Movable type: the letters are reused, not the page.'],
    ['Printing also fixed the text.', 'Key idea for the essay: printing made every copy the same.']],
  es: [['la piel de unos doscientos terneros', 'Una Biblia costaba un rebaño de terneros. Compararlo con una casa hoy.'],
    ['se volvían a usar', 'Tipos móviles: se reutilizan las letras, no la página.'],
    ['La imprenta también fijó el texto.', 'Idea clave para el trabajo: la imprenta hizo iguales todos los ejemplares.']],
}).map(([text, body], i) => ({ id: `n${i + 1}`, body, anchor: textAnchor(markdown, quote(text)) }));
const kept = JSON.parse(localStorage.getItem(KEY) ?? 'null') ?? seed;
let notes = kept.flatMap((n) => {
  const found = resolveAnchor(markdown, n.anchor);
  return found.status === 'exact' || found.status === 'moved'
    ? [{ ...n, range: { start: found.start, end: found.end } }] : [];
});
const nextId = () => `n${1 + Math.max(0, ...notes.map((n) => Number(n.id.slice(1)) || 0))}`;
const save = () => localStorage.setItem(KEY, JSON.stringify(
  notes.map(({ id, body, range }) => ({ id, body, anchor: textAnchor(markdown, range) }))));

يحفظ التطبيق الملاحظة نصَّها مع مرساة للمقطع (textAnchor): النطاق والكلمات وشيئًا من السياق على كل جانب. عند الفتح تجد resolveAnchor كل مقطع في الطبعة الموجودة. تصحيح من الناشر قبل صفحة يزيح المواضع؛ فتعود المرساة إلى الكلمات، ولا يضيع إلا مقطع حُذف.

#2 · حوّل التحديد إلى علامة ملاحظة

الشيفرة هي الجواب المختصر أعلاه. يُبلغ العارض عن التحديد المكتمل نطاقًا من Markdown، فيفتح التطبيق بطاقته له. والملاحظة المحفوظة علامة note: تلوّن كلماتها وتضع راية في الهامش، وnoteSide: 'end' يرسل الرايات كلها إلى الهامش الخارجي. التسميات هي أرقام الملاحظات بترتيب القراءة، فالملاحظة المكتوبة في أول الفصل ترفع الأرقام التي تليها، كما في الكتاب المطبوع.

#3 · افتح البطاقة تحت الكلمات

script.js · الأسطر 162–215في الشيفرة الكاملة
function compose({ range, id }) {
  card = { range, id };
  $('card').dataset.mode = 'write';
  $('quote').textContent = plain(range);
  $('body').value = id ? notes.find((n) => n.id === id).body : '';
  show();
  $('body').focus({ preventScroll: true });
}
function read(id) {
  const note = notes.find((n) => n.id === id);
  card = { id, range: note.range };
  $('card').dataset.mode = 'read';
  $('number').textContent = `${L.note} ${notes.indexOf(note) + 1}`;
  $('quote').textContent = plain(note.range);
  $('text').textContent = note.body;
  show();
}
function show() {
  $('card').hidden = false;
  place();
  for (const item of $('list').children) item.setAttribute('aria-current', String(item.dataset.id === card.id));
}
function hide() {
  card = null;
  $('card').hidden = true;
  view.setSelection(null);
  for (const item of $('list').children) item.removeAttribute('aria-current');
}
// Under the last line of the words: page px turned into the window's px.
function place() {
  if (!card) return;
  const last = view.rangeRects(card.range).at(-1);
  const at = last && view.pageToClient(last.pageIndex, last.rect.x, last.rect.y + last.rect.height);
  if (at) Object.assign($('card').style, { left: `${at.x}px`, top: `${at.y + 10}px` });
}
$('save').addEventListener('click', () => {
  const body = $('body').value.trim();
  if (body && card.id) notes = notes.map((n) => (n.id === card.id ? { ...n, body } : n));
  else if (body) return void (addNote(card.range, body), hide());
  save();
  render();
  hide();
});
$('cancel').addEventListener('click', hide);
$('edit').addEventListener('click', () => compose(card));
$('remove').addEventListener('click', () => {
  notes = notes.filter((n) => n.id !== card.id);
  save();
  render();
  hide();
});
view.on('zoomchange', place);
view.element.addEventListener('scroll', place, { capture: true, passive: true });
addEventListener('keydown', (e) => e.key === 'Escape' && hide());

بطاقة واحدة تخدم الحالتين: الكتابة، بالكلمات المقتبسة ومربع النص وزر الحفظ؛ والقراءة، بالملاحظة وزرّي التعديل والحذف. تعطي rangeRects السطر الأخير من المقطع بوحدات بكسل الصفحة، وتحوّله pageToClient إلى بكسل النافذة، فتستقر البطاقة تحت الكلمات بأي تكبير وتتبعها عند التمرير.

#4 · أبقِ الدفتر بجانب الصفحات

script.js · الأسطر 219–233في الشيفرة الكاملة
function renderNotebook() {
  $('count').textContent = L.count(notes.length);
  $('list').replaceChildren(...notes.map(({ id, body, range }, i) => {
    const item = document.createElement('button');
    item.type = 'button';
    item.dataset.id = id;
    item.innerHTML = '<span class="n"></span><q></q><p></p><small></small>';
    item.querySelector('.n').textContent = i + 1;
    item.querySelector('q').textContent = plain(range);
    item.querySelector('p').textContent = body;
    item.querySelector('small').textContent = L.page(view.rangeRects(range)[0].pageIndex + 1);
    item.addEventListener('click', () => { view.revealAnnotation(id); read(id); });
    return item;
  }));
}

الدفتر هو السجلات نفسها بترتيب القراءة. الضغط على مدخل يأتي بكلماته إلى العرض عبر revealAnnotation ويفتح بطاقته، ويبقى المدخل مميَّزًا ما دامت البطاقة مفتوحة.

الوصفة كاملة

// ═══ Postext Cookbook · Nº 224 · A reader's notebook ═════════════════════════════════
// https://postext.dev/en/cookbook/reader-notebook
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Source Serif 4, Source Sans 3 (SIL OFL 1.1) · Needs postext ≥ 1.103.0
//
// A history textbook in a study app. Select a passage and write a note on it: the passage
// is tinted and a numbered flag goes in the margin. A flag opens its note over the page,
// and the notebook beside the pages lists every note with the words it is about. The notes
// are kept on this device as anchors, so a corrected edition of the book keeps them.
import { buildDocumentWithFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { textAnchor, resolveAnchor } from 'https://esm.sh/postext/annotate';
import { createViewer } from 'https://esm.sh/postext-viewer';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'reader-notebook';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
  ink: '#1f2328', // text
  accent: '#24527a', // ink blue: chapter number, headings, folio
  muted: '#68707a', // running head
};
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 textbook page with a wide outer margin, where the reader's flags go
const config = {
  locale: t({ en: 'en-gb', es: 'es' }),
  colorPalette,
  page: { sizePreset: 'custom', width: mm(170), height: mm(240), dpi: 150,
    margins: { top: mm(22), bottom: mm(24), left: mm(20), right: mm(48) } },
  layout: { layoutType: 'single' },
  bodyText: { fontFamily: 'Source Serif 4', fontSize: pt(10.5), lineHeight: pt(15),
    color: col('ink'), boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
    textAlign: 'left', firstLineIndent: mm(5), indentAfterHeading: false,
    hyphenation: { enabled: true }, avoidWidows: true, avoidOrphans: true, avoidRunts: true },
  headings: { fontFamily: 'Source Sans 3', color: col('accent'), fontWeight: 700, levels: [
    { level: 1, fontSize: pt(22), lineHeight: pt(26), marginTop: pt(0), marginBottom: pt(15) },
    { level: 2, fontSize: pt(11), lineHeight: pt(15), marginTop: pt(15), marginBottom: pt(4) },
  ] },
  header: { elements: [
    { kind: 'text', id: 'head', content: '{title}', fontFamily: 'Source Sans 3', fontSize: pt(7.5),
      fontWeight: 700, letterSpacing: pt(1.2), textTransform: 'uppercase', color: col('muted'),

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

تنويعات

#ظلّل أولًا واكتب لاحقًا

كثير من القراء يعلّمون مقطعًا ثم يعودون إليه. تحفظ قلم تظليل للقارئ: مقطع ولون تظليلات ملوّنة على المراسي نفسها؛ ويمكن للملاحظة أن تبدأ تظليلًا.

#صدّر الدفتر بصيغة Markdown

تحفظ المراسي كلمات كل مقطع، فيُكتب الدفتر ورقةَ مراجعة في بضعة أسطر.

const sheet = notes.map(({ range, body }) => `> ${plain(range)}\n\n${body}`).join('\n\n');

الحقوق

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