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

دليل الوصفات · الفصل 3 · العناوين وصفحات الافتتاح

عناوين الحكايات بالأعداد الترتيبية: الليلة الأولى…

قالب مستوى يكتب كل ليلة كلمةَ «الليلة» وعددًا ترتيبيًا مؤنثًا، الليلة الأولى، الثانية، الثالثة، فلا يتضمّن Markdown أي رقم.

في هذه الصفحة
المُخرَج
Canvas · PDF
المستوى
متوسط
Postext
اختُبرت مع Postext 1.65.0
تتطلب ≥ 1.25.0 · postext-pdf ≥ 1.25.0
الترخيص
حُدّثت في 10 أكتوبر 2026
الشيفرة MIT · النص MIT

ص ٢–٣ · 2–3 من 10

  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 170 × 240 مم
  • عمود واحد
  • Amiri 13/26
  • Aref Ruqaa
  • Noto Kufi Arabic
  • 10 صفحات
  • المستوى
  • Postext 1.65.0
  • أُخرجت في 129 ms
  • أسطر الشيفرة: 158

باختصار

مطلع «ألف ليلة وليلة»، حيث يتصدّر كلَّ ليلة رقمُها مكتوبًا بالحروف العربية، «الليلة الأولى»، «الليلة الثانية»، بصيغة المؤنث التي تطابق كلمة «ليلة».

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

عشر صفحات من أول ألف ليلة وليلة: صفحة نصف عنوان، ثم «حكاية التاجر والعفريت»، أول حكاية ترويها شهرزاد، وتمتد على ثلاث ليالٍ. تنفتح كل ليلة بعبارة هنداوي «فلما كانت» بكوفي صغير فوق رقمها بخط رقعة أخضر، الليلة الأولى، الليلة الثانية، الليلة الثالثة، مكتوبًا بالحروف كما تطبعه الكتب. ولا شيء من هذه الأرقام في Markdown: مستوى العنوان يعدّ الليالي ويكتب كل عدد ترتيبيًا مؤنثًا يطابق «ليلة». تنفتح الحكاية تحت رأس زخرفي محدود بالذهبي، ولحكايات الشيوخ الثلاثة عناوينها الصغيرة الخاصة، وفي الترويسات اسم الكتاب والحكاية. والنص من طبعة مؤسسة هنداوي لسنة 2022، برخصة CC BY 4.0.

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

  • كيف أرقّم الفصول بالأعداد الترتيبية العربية كتابةً، مثل الليلة الأولى؟

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

script.js · الأسطر 34–54في الشيفرة الكاملة
// In the Markdown a night is a level-2 heading with no number: ## الليلة
// The level's template writes الليلة and the counter as a feminine ordinal, which agrees
// with the noun: الليلة الأولى، الليلة الثانية، الليلة الثالثة … الليلة الحادية بعد الألف.
// numberPosition 'replace' makes that number the whole title, so the heading, the PDF
// bookmarks and the alt text read الليلة الثانية. Hindawi's formula is a fixed design text.
const nights = {
  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
  marginTop: pt(LEAD), marginBottom: pt(LEAD / 2),
  advancedDesign: { enabled: true, minHeight: mm(18), slot: { elements: [
    { kind: 'text', id: 'formula', content: 'فلما كانت', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8), align: 'center', color: col('muted'), placement: top(0) },
    { kind: 'text', id: 'night', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(21), lineHeight: 1.2, align: 'center', color: col('accent'),
      placement: top(4.5) },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...top(16), size: { width: mm(16) } } },
  ] } },
};
// A tale does not count: an unnumbered heading leaves the deeper counters alone, so the
// nights run on from one tale to the next instead of starting again at الأولى.
const tale = { numbered: false, runningChapter: true };

المكونات

تستخدم أيضًا
فصول بلا أرقام
الخطوط
Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1)
الأصول
لا شيء: كل صورة مرسومة بالشيفرة

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

#1 · ليالٍ تُعَدّ بالحروف

الشيفرة هي الجواب المختصر أعلاه. الليلة عنوان من المستوى الثاني، ## الليلة، وnumberingTemplate الخاص بالمستوى هو 'الليلة {2:ordinal-feminine}': يكتب المُعدِّل -feminine الأولى، الثانية، الحادية عشرة، الحادية بعد الألف (الأعداد الترتيبية والأصلية بالحروف، الأعداد المكتوبة بالحروف). ومع numberPosition: 'replace' يصير الرقم عنوانَ العنوان كله: يُسقَط ما يكتبه Markdown بعد ##، ويُقرأ العنوان وعلامات PDF المرجعية والنص البديل «الليلة الثانية». يطبع التصميم ذلك العنوان، {titleText}، كبيرًا، وعبارة هنداوي «فلما كانت»، وهي نص ثابت، صغيرة فوقه. وتستعمل عناوين الحكايات نمطًا بـnumbered: false: المستوى الأول المرقّم كان سيعيد عدّ الليالي مع كل حكاية، أما غير المرقّم فيترك العدّادات الأعمق على حالها، فتتوالى الليالي على امتداد الكتاب.

الصفحة 5: الليلة الثانية، رقمها مكتوب بالحروف بالقالب ومطبوع عنوانًا كاملًا.

#2 · رأس زخرفي لكل حكاية

script.js · الأسطر 58–75في الشيفرة الكاملة
const rule = (id, y, thickness) => ({ kind: 'rule', id, direction: 'horizontal',
  thickness: pt(thickness), color: col('gold'),
  placement: { ...top(y), size: { width: 'fill' } } });
const opener = {
  enabled: true, minHeight: mm(50),
  slot: { elements: [
    { kind: 'box', id: 'band', reserve: false, style: { backgroundColor: col('tint') },
      placement: { ...top(4), size: { width: 'fill', height: mm(30) } } },
    rule('band-top', 4, 1.2), rule('band-foot', 34, 0.5),
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8.5), align: 'center', color: col('muted'), placement: top(7.5) },
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(30), lineHeight: 1.15, align: 'center', color: col('accent'),
      placement: top(13) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', fontFamily: NASKH, italic: true,
      fontSize: pt(9.5), align: 'center', color: col('muted'), placement: top(39) },
  ] },
};

العنوان من المستوى الأول شريط ملوّن بين خطين ذهبيين، فوقه عنوان الحكاية بخط الرقعة، وعنوان تمهيدي وسطر لاتيني مأخوذان من سمات العنوان، {kicker="…" latin="…"}. والسطر اللاتيني هو الجزء الوحيد من صفحة الافتتاح الذي يتغير مع الطبعة.

#3 · ترويسات تأتي مع الحكاية

script.js · الأسطر 79–93في الشيفرة الكاملة
// Running heads stay on the sheet's sides: in a book bound on the right the verso (even)
// is the right-hand page, so its outer edge, where the folio goes, is the right one.
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content,
  parity, pages: 'body', fontFamily: KUFI, fontWeight: 500, fontSize: pt(8.5),
  color: col('muted'), placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(12) } },
  ...extra });
const taleHeads = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-right', -OUTER, { color: col('accent') }),
  head('verso-book', '{title}', 'even', 'top-right', -(OUTER + 10)),
  head('recto-tale', '{chapterTitle}', 'odd', 'top-left', OUTER + 10),
  head('recto-folio', '{pageNumber}', 'odd', 'top-left', OUTER, { color: col('accent') }),
] };
const footer = { elements: [head('drop-folio', '{pageNumber}', 'all', 'bottom', 0, {
  pages: 'opener', color: col('accent'),
  placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-12) } } })] };

تنتمي الترويسات إلى نمط العنوان tale، فتأتي كل حكاية بترويساتها؛ ولا ترويسة لصفحة نصف العنوان. على الصفحة الزوجية عنوان الكتاب، وعلى الفردية {chapterTitle}، أي الحكاية. وفي كتاب مجلّد على اليمين تكون الصفحة الزوجية هي اليمنى، فيذهب رقمها إلى أعلى اليمين (ترتيب الصفحات والتجليد على اليمين).

#4 · صفحة نصف عنوان بخط الرقعة

script.js · الأسطر 97–115في الشيفرة الكاملة
const at = (y) => ({ anchor: { to: 'page', edge: 'top' }, offset: { y: mm(y) } });
const line = (id, content, y, style) => ({ kind: 'text', id, content, align: 'center',
  overflow: 'wrap', color: col('ink'), placement: at(y), ...style });
const titlePage = {
  id: 'title', span: 'page', numbered: false, runningChapter: false,
  breakBefore: { enabled: true, parity: 'any' }, header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'rule', id: 'over', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...at(62), size: { width: mm(40) } } },
    line('book', '{titleText}', 70, { fontFamily: RUQAA, fontWeight: 700, fontSize: pt(54),
      lineHeight: 1.25, color: col('accent') }),
    { kind: 'rule', id: 'under', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),
      placement: { ...at(100), size: { width: mm(40) } } },
    line('volume', '{attr.kicker}', 106, { fontFamily: KUFI, fontWeight: 500, fontSize: pt(11),
      color: col('accent') }),
    line('latin', '{attr.latin}', 150, { fontFamily: NASKH, fontSize: pt(9.5), italic: true,
      color: col('muted') }),
  ] } },
};

صفحة نصف العنوان نمط عنوان بـspan: 'page' وnumbered: false وترويسة وتذييل فارغين، فلا تدخل في العدّ وليست لها ترويسة.

الوصفة كاملة

Sandbox
// ═══ Postext Cookbook · Nº 112 · Night headings in Arabic ordinal words ═══════════
// https://postext.dev/en/cookbook/nights-ordinal-headings
// Code: MIT · Text: Alf layla wa-layla, Hindawi Foundation 2022 (CC BY 4.0) · Pictures: none
// Fonts: Amiri, Aref Ruqaa, Noto Kufi Arabic (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, withLoadedFonts, renderPageToCanvas } from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

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

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text, a deep green for the titles and a gold hairline, on a cream paper.
const palette = {
  ink: '#1c1a17', // text: a warm near-black
  accent: '#1f564c', // titles, night headings, folios
  gold: '#a8833a', // the rules under the nights and around the headpiece
  tint: '#ebe3cc', // the headpiece band
  muted: '#5e594f', // running heads, kickers, the note on the text
  paper: '#faf6ec', // a cream paper
};
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' } },
];
const NASKH = 'Amiri'; // the text and the sub-tale titles
const RUQAA = 'Aref Ruqaa'; // display: the book, the tale, the nights
const KUFI = 'Noto Kufi Arabic'; // labels: kickers, running heads, folios
const [SIZE, LEAD] = [13, 26]; // pt: 2 × the size: a ḍamma over a hamza clears the line above
const [OUTER, TOP] = [18, 22]; // mm: a 17 × 24 cm book
const top = (y) => ({ anchor: { to: 'container', edge: 'top' }, offset: { y: mm(y) } });

// #region answer: the night's number in feminine ordinal words, from a level template
// In the Markdown a night is a level-2 heading with no number: ## الليلة
// The level's template writes الليلة and the counter as a feminine ordinal, which agrees
// with the noun: الليلة الأولى، الليلة الثانية، الليلة الثالثة … الليلة الحادية بعد الألف.
// numberPosition 'replace' makes that number the whole title, so the heading, the PDF
// bookmarks and the alt text read الليلة الثانية. Hindawi's formula is a fixed design text.
const nights = {
  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
  marginTop: pt(LEAD), marginBottom: pt(LEAD / 2),
  advancedDesign: { enabled: true, minHeight: mm(18), slot: { elements: [
    { kind: 'text', id: 'formula', content: 'فلما كانت', fontFamily: KUFI, fontWeight: 500,
      fontSize: pt(8), align: 'center', color: col('muted'), placement: top(0) },
    { kind: 'text', id: 'night', content: '{titleText}', fontFamily: RUQAA, fontWeight: 700,
      fontSize: pt(21), lineHeight: 1.2, align: 'center', color: col('accent'),
      placement: top(4.5) },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6), color: col('gold'),

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

تنويعات

#ابدأ من الليلة الحادية بعد الألف

يضبط {startAt=1001} على عنوان ليلةٍ عدّادَها، فيكتب القالب «الليلة الحادية بعد الألف» (سمات العناوين).

-## الليلة
+## الليلة {startAt=1001}

#اكتب المئات على طريقة بولاق

يكتب -classical «مائة» بدل «مئة»، فتُقرأ الليلة المئتان «الليلة المائتان».

-  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine-classical}', numberPosition: 'replace',

#رقّم الفصول بالمذكّر

بلا مُعدِّل يكون الترتيبي مذكّرًا، لاسم مثل «الفصل»: الفصل الأول، الفصل الثاني.

-  level: 2, numberingTemplate: 'الليلة {2:ordinal-feminine}', numberPosition: 'replace',
+  level: 2, numberingTemplate: 'الفصل {2:ordinal}', numberPosition: 'replace',

أخطاء شائعة

خطأ شائع

اوسم الكتاب العربي بـ 'ar'، لا بـ LANG

نسختا الوصفة هما en وes، لكن المثال العربي عربي في كلتيهما: `locale: LANG` سيجعله من اليسار إلى اليمين، ويجلّده على اليسار، ويرقّم صفحاته 1 2 3، ويسمّي أشكاله Figure أو Figura. ومنذ postext 1.30 صار الوسم أيضًا اللغة التي يُشكَّل بها النص (يُقاس ويُرسم ويُضمَّن بها)، فتحت وسم إنجليزي أو إسباني لا يرسم خط مثل Markazi Text الأشكال العربية لعلامتَي التنصيص « » وللنقطة، وتنكسر الأسطر في مواضع أخرى. اكتب الوسم بنفسك: 'ar' (الأرقام العربية المشرقية، عُرف المشرق)، أو منطقة مثل 'ar-EG' أو 'ar-SA'، أو 'ar-MA' أو 'ar-DZ' أو 'ar-TN' لنسخة مغاربية بالأرقام الأوروبية. أما الصفحة اللاتينية التي تقتبس العربية فقط فتحتفظ بلغتها. النص من اليمين إلى اليسار →

خطأ شائع

الخطوط العربية تحتاج إلى ملفها arabic، عبر الكتلة arabic

يقدّم Fontsource الخطوط Amiri وNoto Naskh Arabic وScheherazade New في ملف لكل مجموعة فرعية، والحروف العربية في ملف arabic. لا يجلب loadFonts إلا latin (وlatin-ext)، فيأتي النص العربي على الشاشة من خط النظام ويُقاس خطأً، ويسلّم fontsourceProvider ملف latin ذاك إلى PDF، فيطبع مربعات فارغة. اذكر كتلة الأدوات arabic، واستدعِ loadArabicFonts(FONTS, markdown) بعد loadFonts، مع ذكر كل وزن تضع به الصفحاتُ نصًا عربيًا في FONTS، وأعطِ renderToPdf القيمة fontProvider: arabicPdfProvider. الخطوط العربية →

الحقوق

الوصفة
Ignacio Ferro
النص
  • The Merchant and the Jinni, nights 1 to 3 of Alf layla wa-layla, from the Hindawi Foundation edition (2022, vol. 1), with its vowels and punctuation · Hindawi Foundation · CC BY 4.0
  • The kickers in Arabic, the note on the text and the colophon · Postext Cookbook · أصلي
الخطوط
Amiri (SIL OFL 1.1) · Aref Ruqaa (SIL OFL 1.1) · Noto Kufi Arabic (SIL OFL 1.1)
الشيفرة
MIT، مثل Postext
SandboxPDF