# Λίστες κώδικα και πλήκτρα

> Οδηγός για το κέλυφος με τον κώδικα σε περίφραγμα σε σκούρα πλαίσια, χρωματισμένο ανά token, και τα πλήκτρα ως ετικέτες σε σχήμα πλήκτρου.

- Έκδοση HTML: https://postext.dev/el/cookbook/code-listings-and-keycaps
- Συνταγή Αρ. 048 · Πλαίσια και σημειώσεις · Επίπεδο 2 (Μεσαίο) · Έξοδοι: Canvas
- Είδη: Εγχειρίδια, οδηγοί και έργα αναφοράς
- Απαιτεί postext ≥ 1.25.0 · δοκιμασμένη με 1.65.0 στις 2026-10-31
- Σελίδες: [49](https://postext.dev/cookbook/code-listings-and-keycaps/en/p01.webp?v=5660f3d7), [50](https://postext.dev/cookbook/code-listings-and-keycaps/en/p02.webp?v=5660f3d7), [51](https://postext.dev/cookbook/code-listings-and-keycaps/en/p03.webp?v=5660f3d7)
- Άνοιγμα στο Sandbox: https://postext.dev/el/sandbox#recipe=code-listings-and-keycaps&lang=en (.postext: https://postext.dev/cookbook/code-listings-and-keycaps/en/code-listings-and-keycaps.postext)
- Τελευταία ενημέρωση: 2026-10-10
- Άλλες γλώσσες: [en](https://postext.dev/en/cookbook/code-listings-and-keycaps.md), [es](https://postext.dev/es/cookbook/code-listings-and-keycaps.md), [ca](https://postext.dev/ca/cookbook/code-listings-and-keycaps.md), [de](https://postext.dev/de/cookbook/code-listings-and-keycaps.md), [fr](https://postext.dev/fr/cookbook/code-listings-and-keycaps.md), [it](https://postext.dev/it/cookbook/code-listings-and-keycaps.md), [pt](https://postext.dev/pt/cookbook/code-listings-and-keycaps.md), [zh](https://postext.dev/zh/cookbook/code-listings-and-keycaps.md), [ja](https://postext.dev/ja/cookbook/code-listings-and-keycaps.md), [ar](https://postext.dev/ar/cookbook/code-listings-and-keycaps.md)

## Με λίγα λόγια

Τρεις σελίδες ενός οδηγού για αρχάριους στη γραμμή εντολών του υπολογιστή. Δείχνει πώς στοιχειοθετούνται τα παραδείγματα κώδικα σε σκούρα χρωματιστά πλαίσια και πώς σχεδιάζονται πλήκτρα όπως το Ctrl σαν μικρά κουμπιά μέσα στο κείμενο.

## Τι θα στοιχειοθετήσετε

Τρεις σελίδες από το κεφάλαιο 4 του *The Shell, Gently*, ενός φανταστικού οδηγού τσέπης για τη γραμμή εντολών, σε σελίδα 178 × 229 mm. Το κείμενο είναι Charis SIL με πλήρη στοίχιση σε στήλη 100 mm, με μια στήλη περιθωρίου στην εξωτερική πλευρά για σημειώσεις. Κάθε λίστα κώδικα είναι ένα σχεδόν μαύρο πλαίσιο σε JetBrains Mono που απλώνεται σε αυτή τη στήλη, κάτω από μια καρτέλα με το όνομα του αρχείου ή της συνεδρίας. Οι λέξεις-κλειδιά και οι πληκτρολογημένες εντολές τυπώνονται σε κεχριμπαρένιο, οι συμβολοσειρές σε πράσινο και τα σχόλια σε γκρι. Πλήκτρα όπως το Ctrl και το Tab είναι μικρά περιγραμμένα πλήκτρα μέσα στις γραμμές με πλήρη στοίχιση, και ένα σκονάκι δύο στηλών με συντομεύσεις Ctrl γεμίζει το κάτω μέρος της σελίδας 50. Το Markdown κρατά κανονικά μπλοκ κώδικα σε περίφραγμα, και η μηχανή τα στοιχειοθετεί όπως είναι.

**Αυτή η συνταγή απαντά:**

- Πώς δείχνω λίστες κώδικα και συντομεύσεις πληκτρολογίου;
- Πώς φτιάχνω ετικέτες μέσα στο κείμενο: πλήκτρα, ετικέτες, τράπεζες λέξεων για ασκήσεις;
- Πώς γράφω παύλες διαλόγου, χρονολογίες στην αρχή παραγράφου, τιμές και κυριολεκτικά σύμβολα χωρίς να τα παρερμηνεύει το Markdown;

## Η σύντομη απάντηση

````js
// script.js, γραμμές 26–41
// A ``` fence is a listing set line by line as written: indents, blank lines and the output
// columns of a session are kept. The rest of the fence line (Terminal, backup.sh) is its
// title; with a label set, it goes on the tab.
// The text after a listing goes in :::paragraphs{style="resume"}: flush, as after a heading.
const resume = { id: 'resume', firstLineIndent: ZERO };
const codeStyle = {
  fontFamily: MONO, fontSize: pt(8.6), lineHeight: pt(12.4), color: col('code'),
  background: col('night'), span: 'page', // across the text and the margin
  padding: { top: mm(4), right: mm(5), bottom: mm(4), left: mm(5) },
  marginTop: mm(6), marginBottom: mm(2.5),
  label: { fontFamily: MONO, fontSize: pt(7), fontWeight: 700, color: col('phosphor'),
    background: col('night'), height: mm(5), offset: mm(5), paddingX: mm(3), // the tab
    position: 'top-left' },
  tokens: tokens(), // the colours, below
  inline: { fontSize: em(0.88) }, // `grep` in running text: the code face, no box
};
````

## Υλικά

**Διδάσκει**

- [Μπλοκ κώδικα](https://postext.dev/el/docs/configuration-styles.md#κατάλογοι-κώδικα): Τα μπλοκ ``` στοιχειοθετούνται ως κώδικας: γραμμή προς γραμμή όπως πληκτρολογήθηκαν, μέσα σε πλαίσιο, με χρώματα σύνταξης, αριθμούς γραμμών, επισημασμένες γραμμές και μεγάλες γραμμές που συνεχίζουν στην επόμενη, που στοιχειοθετούνται μικρότερες ή κόβονται.
- [Ετικέτες μέσα στη γραμμή](https://postext.dev/el/docs/configuration-styles.md#στιλ-ετικετών): Στρογγυλεμένα πλαίσια γύρω από λέξεις, που αλλάζουν γραμμή ως ενιαίο σύνολο και δεν τεντώνονται ποτέ: πλήκτρα, ετικέτες, τράπεζες λέξεων, συλλαβές.
- [Πλαίσια σημειώσεων](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων): Ονομασμένα στιλ πλαισίων για σημειώσεις, συμβουλές και προειδοποιήσεις: φόντο, περίγραμμα, ακτίνα γωνιών, λωρίδα, τίτλος και δική τους τυπογραφία για το σώμα και τις λίστες.

**Χρησιμοποιεί επίσης**

- [Αριθμημένες καρτέλες πλαισίων](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων)
- [Στήλες σε πλαίσιο ή στο κείμενο](https://postext.dev/el/docs/document-format-directives.md#columns)
- [Πλαίσια σε όλο το πλάτος της σελίδας](https://postext.dev/el/docs/configuration-callouts.md#ο-περιέκτης-callout)
- [Κινητά πλαίσια](https://postext.dev/el/docs/configuration-callouts.md#ο-περιέκτης-callout)
- [Σημειώσεις περιθωρίου](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων)
- [Στήλη και μισή](https://postext.dev/el/docs/configuration-page-layout.md#τύποι-διάταξης)
- [Στήλη περιθωρίου για κινητά στοιχεία](https://postext.dev/el/docs/configuration-page-layout.md#διάταξη)
- [Έντονα, πλάγια και τα χρώματά τους](https://postext.dev/el/docs/configuration-text.md#κυρίως-κείμενο)
- [Αριθμημένες λίστες](https://postext.dev/el/docs/configuration-lists-math.md#αριθμημένες-λίστες)
- [Σχεδιασμένες εναρκτήριες σελίδες](https://postext.dev/el/docs/configuration-headings.md#πλάτος-και-προηγμένη-σχεδίαση)
- [Ιδιότητες επικεφαλίδων](https://postext.dev/el/docs/document-format.md#χαρακτηριστικά-επικεφαλίδων)
- [Τρέχουσες κεφαλίδες και αριθμοί σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα)
- [Κεφαλίδες ανά ρόλο σελίδας](https://postext.dev/el/docs/configuration-headers-footers.md#στοιχεία-κειμένου)
- [Συμμετρικά περιθώρια](https://postext.dev/el/docs/configuration-page-layout.md#κατοπτρικά-περιθώρια)
- [Σημασιολογική χρωματική παλέτα](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων)
- [Στιλ παραγράφων](https://postext.dev/el/docs/configuration-styles.md#στιλ-παραγράφων)
- [Βέλτιστη αλλαγή γραμμής (Knuth–Plass)](https://postext.dev/el/docs/justification.md#knuth-plass-η-ματιά-σε-ολόκληρη-την-παράγραφο)
- [Μαθηματικά](https://postext.dev/el/docs/document-format-inline.md#μαθηματικοί-τύποι)

**Η διαμόρφωση με μια ματιά**

- [`bodyText`](https://postext.dev/el/docs/configuration-text.md#κυρίως-κείμενο), [`calloutStyles`](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων), [`chipStyles`](https://postext.dev/el/docs/configuration-styles.md#στιλ-ετικετών), [`codeStyle`](https://postext.dev/el/docs/configuration-styles.md#κατάλογοι-κώδικα), [`colorPalette`](https://postext.dev/el/docs/configuration-fonts-colors-viewers.md#παλέτα-χρωμάτων), [`footer`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`header`](https://postext.dev/el/docs/configuration-headers-footers.md#κεφαλίδες-και-υποσέλιδα), [`headings`](https://postext.dev/el/docs/configuration-headings.md#επικεφαλίδες), [`layout`](https://postext.dev/el/docs/configuration-page-layout.md#διάταξη), [`locale`](https://postext.dev/el/docs/configuration-language.md#συλλαβισμός), [`orderedLists`](https://postext.dev/el/docs/configuration-lists-math.md#αριθμημένες-λίστες), [`page`](https://postext.dev/el/docs/configuration-page-layout.md#σελίδα), [`paragraphStyles`](https://postext.dev/el/docs/configuration-styles.md#στιλ-παραγράφων)

**API**

- [`buildDocument`](https://postext.dev/el/docs/configuration-programmatic-usage.md#κατασκευή-εγγράφου), [`prepareFonts`](https://postext.dev/el/docs/configuration-programmatic-usage.md#φόρτωση-γραμματοσειρών-πριν-από-τη-σελιδοποίηση), [`renderPageToCanvas`](https://postext.dev/el/docs/configuration-programmatic-usage.md#απόδοση-σελίδας-σε-bitmap), [`withLoadedFonts`](https://postext.dev/el/docs/configuration-programmatic-usage.md#φόρτωση-γραμματοσειρών-πριν-από-τη-σελιδοποίηση)

**Γραμματοσειρές**

- Charis SIL (OFL-1.1), Sora (OFL-1.1), JetBrains Mono (OFL-1.1)

## Προετοιμασία

### 1 · Δώστε στα περιφράγματα ένα πλαίσιο

Ο κώδικας αυτού του βήματος είναι η [σύντομη απάντηση](https://postext.dev/el/cookbook/code-listings-and-keycaps.md#η-σύντομη-απάντηση) παραπάνω. Κάθε περίφραγμα ```` ``` ```` στο Markdown είναι ένα [μπλοκ κώδικα](https://postext.dev/el/docs/document-format.md#μπλοκ-κώδικα): το Postext στοιχειοθετεί τις γραμμές του όπως πληκτρολογήθηκαν, μία γραμμή κώδικα σε μία γραμμή στοιχείων, κρατώντας τις εσοχές, τις κενές γραμμές του σεναρίου και την έξοδο δύο στηλών του `du`. Το `codeStyle` σχεδιάζει όλες τις λίστες μαζί ([Λίστες κώδικα](https://postext.dev/el/docs/configuration-styles.md#κατάλογοι-κώδικα)): τη γραμματοσειρά και το διάστιχό της, το σχεδόν μαύρο γέμισμα, το εσωτερικό περιθώριο και τον χώρο πάνω και κάτω. Ό,τι ακολουθεί τη γλώσσα στη γραμμή του περιφράγματος (`Terminal`, `backup.sh`) είναι ο τίτλος της λίστας, και επειδή έχει οριστεί το `codeStyle.label`, τυπώνεται σε μια [καρτέλα ετικέτας](https://postext.dev/el/docs/configuration-callouts.md#στιλ-πλαισίων) στην πάνω άκρη του πλαισίου αντί για γραμμή τίτλου. Το `codeStyle.inline` στοιχειοθετεί τον κώδικα μέσα στο τρέχον κείμενο, `ls` ή `grep -c`, στην ίδια γραμματοσειρά στα 0,88 em ([Κώδικας μέσα στο κείμενο](https://postext.dev/el/docs/configuration-styles.md#κώδικας-μέσα-στη-γραμμή)). Η παράγραφος μετά από μια λίστα μπαίνει σε `:::paragraphs{style="resume"}`, ώστε να αρχίζει χωρίς εσοχή, όπως θα άρχιζε μετά από επικεφαλίδα.

### 2 · Κρατήστε το κείμενο στενό και αφήστε τον κώδικα να περάσει στο περιθώριο

```js
// script.js, γραμμές 124–127
  page: { sizePreset: 'custom', width: mm(178), height: mm(229), margins: {
    top: mm(22), bottom: mm(21), left: mm(20), right: mm(OUTER), mirror: true } },
  layout: { layoutType: 'oneAndHalf', sideColumnPercent: 26, gutterWidth: mm(6),
    sideColumnRole: 'floats', sideColumnSide: 'outer' },
```

Στα 10 pt, η Charis SIL χωρά περίπου 62 χαρακτήρες στη στήλη των 100 mm. Η πλευρική στήλη αυτής της [διάταξης μιάμισης στήλης](https://postext.dev/el/docs/configuration-page-layout.md#τύποι-διάταξης) δέχεται μόνο κινητά στοιχεία και σημειώσεις, οπότε το κείμενο δεν μπαίνει ποτέ μέσα της. Το `span: 'page'` στο `codeStyle` απλώνει κάθε λίστα και στις δύο στήλες, 143 mm. Μέσα στο εσωτερικό του περιθώριο ένα πλαίσιο χωρά 73 χαρακτήρες JetBrains Mono στα 8,6 pt· η μακρύτερη γραμμή αυτών των σελίδων, το σχόλιο που ανοίγει το `backup.sh`, έχει 71.

### 3 · Χρωματίστε τον κώδικα ανά token

```js
// script.js, γραμμές 45–54
function tokens() {
  const plain = { color: col('code') }; // every other kind in the listing's own colour
  return {
    keyword: { color: col('amber'), bold: true }, function: { color: col('amber'), bold: true },
    string: { color: col('phosphor'), italic: true },
    comment: { color: col('slate'), italic: false }, // upright: the default comment is italic
    prompt: { color: col('amber'), bold: true }, output: plain, // what you type, the answer
    number: plain, type: plain, variable: plain, meta: plain, operator: plain, punctuation: plain,
  };
}
```

Η γλώσσα στο περίφραγμα (`console`, `bash`) επιλέγει τον ενσωματωμένο αναλυτή, και το `codeStyle.tokens` δίνει σε κάθε είδος token το χρώμα, το βάρος και την κλίση του ([Χρωματισμός σύνταξης](https://postext.dev/el/docs/configuration-styles.md#χρωματισμός-σύνταξης)). Στο `backup.sh`, λέξεις-κλειδιά όπως `for` και `done` και ενσωματωμένες εντολές όπως `set` και `echo` τυπώνονται σε κεχριμπαρένια έντονα, οι συμβολοσειρές σε πράσινα πλάγια και τα σχόλια σε γκρι· προγράμματα όπως `mkdir` και `rsync` μένουν απλά. Το προεπιλεγμένο στιλ στοιχειοθετεί τα σχόλια σε πλάγια, οπότε το `italic: false` τα κρατά όρθια. Σε ένα περίφραγμα `console`, μια γραμμή που ανοίγει με προτροπή είναι token `prompt` και κάθε άλλη γραμμή είναι `output`, έτσι οι εντολές που πληκτρολογείτε τυπώνονται σε κεχριμπαρένια έντονα και η απάντηση του κελύφους μένει στο ανοιχτό γκρι της λίστας. Τα είδη που η συνταγή δεν θέλει χρωματισμένα, ανάμεσά τους οι αριθμοί, οι μεταβλητές και οι επιλογές, παίρνουν κι αυτά το ίδιο γκρι.

### 4 · Στοιχειοθετήστε τα πλήκτρα ως ετικέτες

```js
// script.js, γραμμές 58–65
// Chips never break or stretch, so a line with keys puts all its slack in its word spaces;
// the breaker tries other breaks before a space passes 140 % (default 200 %).
const spacing = { maxWordSpacing: 1.4 }; // spread into bodyText
const chipStyles = [
  { id: 'key', fontFamily: MONO, fontSize: pt(7.8), bold: true, color: col('ink'),
    background: col('code'), borderColor: col('slate'), borderWidth: pt(0.6),
    borderRadius: pt(1.6), paddingX: em(0.45), paddingY: em(0.14), gap: em(0.3) },
];
```

Τα πλήκτρα είναι ετικέτες `key` με ανοιχτό γέμισμα και περίγραμμα 0,6 pt. Το μέγεθός τους δίνεται σε στιγμές, έτσι ένα πλήκτρο έχει 7,8 pt στο κείμενο των 10 pt, στη σημείωση περιθωρίου των 8,6 pt και στο σκονάκι των 8,4 pt· το `em(0.78)` θα μίκραινε τα πλήκτρα του σκονακιού στα 6,6 pt. Μια ετικέτα δεν σπάει ποτέ ανάμεσα σε γραμμές και δεν τεντώνεται ποτέ ([Ετικέτες μέσα στο κείμενο](https://postext.dev/el/docs/document-format-inline.md#ετικέτες-μέσα-στη-γραμμή)), οπότε μια γραμμή με πλήκτρα ρίχνει όλο τον ελεύθερο χώρο της στα διαστήματα λέξεων. Το `spacing` κάνει τον αλγόριθμο αλλαγής γραμμής να δοκιμάζει άλλες αλλαγές πριν ένα διάστημα μεγαλώσει πέρα από το 140% του κανονικού του πλάτους. Με την προεπιλογή, 200%, έξι γραμμές αυτών των σελίδων τεντώνονται περισσότερο από αυτό· με τη ρύθμιση, η φαρδύτερη φτάνει το 132%.

### 5 · Αριθμήστε τα βήματα πάνω στο πλέγμα

```js
// script.js, γραμμές 91–94
const orderedLists = { fontFamily: DISPLAY, fontWeight: 800, color: col('ember'),
  gap: em(0.7), separator: '›', separatorGap: em(0.25), separatorFontFamily: MONO,
  separatorFontWeight: 700, separatorColor: col('muted'),
  marginTop: ZERO, marginBottom: ZERO }; // the default 1.5 em opens 5.3 mm above and below
```

Οι αριθμοί είναι Sora 800 στο χρώμα έμφασης, και το διαχωριστικό είναι ένα `›` σε γραμματοσειρά σταθερού πλάτους και σε γκρι. Το διαχωριστικό έχει δική του γραμματοσειρά και χρώμα, οπότε σχεδιάζεται ως ξεχωριστό τμήμα ([Αριθμημένες λίστες](https://postext.dev/el/docs/configuration-lists-math.md#αριθμημένες-λίστες)). Τα περιθώρια της λίστας είναι μηδέν, έτσι τα βήματα συνεχίζουν στο πλέγμα των 14,5 pt του κειμένου γύρω τους. Το προεπιλεγμένο 1,5 em θα άνοιγε 5,3 mm πάνω από τα βήματα και θα έσπρωχνε το σκονάκι στη σελίδα 51.

### 6 · Στείλτε το σκονάκι στο κάτω μέρος της σελίδας

```js
// script.js, γραμμές 69–76
const sheet = { id: 'sheet', background: col('night'), span: 'page', placement: 'bottom',
  marginTop: mm(6), marginBottom: mm(2.5),
  columnGap: mm(8), padding: { top: mm(5), right: mm(6), bottom: mm(5.5), left: mm(6) },
  titleStyle: { fontFamily: MONO, fontSize: pt(7.5), fontWeight: 700, gap: mm(3.5),
    color: col('phosphor'), textTransform: 'uppercase', letterSpacing: pt(1.5) },
  body: { fontFamily: DISPLAY, fontSize: pt(8.4), lineHeight: pt(13), textAlign: 'left',
    color: col('code'), boldColor: col('amber'), italicColor: col('phosphor'),
    paragraphSpacing: false, firstLineIndent: ZERO } };
```

Το σκονάκι είναι ένα στιλ πλαισίου με το γέμισμα των λιστών, Sora για τις ενέργειες, και `placement: 'bottom'`, που το στέλνει ως κινητό στοιχείο στο κάτω μέρος της σελίδας 50 ([Κινητά πλαίσια](https://postext.dev/el/docs/configuration-callouts.md#ο-περιέκτης-callout)). Αν μείνει στη ροή, ένα πλαίσιο πλάτους σελίδας χρειάζεται χώρο για τον εαυτό του και για δύο γραμμές κειμένου κάτω του. Εδώ το πλαίσιο θα μετακινούνταν στη σελίδα 51, αφήνοντας 58 mm κενά κάτω από τα βήματα, και το κεφάλαιο θα έφτανε τις τέσσερις σελίδες. Στο Markdown, το `:::columns{count=2 breaks="8"}` ανοίγει τη δεξιά στήλη στο όγδοο μπλοκ, την επικεφαλίδα της. Η εξισορρόπηση από μόνη της κόβει με βάση το ύψος, και όταν μια ενέργεια πιάνει δεύτερη γραμμή αφήνει το *Commands and history* στο κάτω μέρος της αριστερής στήλης. Κάθε λήμμα ανοίγει με τις ίδιες δύο ετικέτες, `Ctrl` και ένα γράμμα, και οι δύο σε γραμματοσειρά σταθερού πλάτους, έτσι κάθε ενέργεια αρχίζει στην ίδια απόσταση από την αριστερή άκρη της στήλης της.

## Η πλήρης συνταγή

Ένα αρχείο, συντεθειμένο από τον φάκελο της συνταγής με το δείγμα κειμένου και το κοινό κιτ του Συνταγολογίου ενσωματωμένα· φτιάχνει τη δική του σελίδα. Για να το εκτελέσετε, βάλτε το σε ένα `<script type="module">` σε μια κενή σελίδα, ή επικολλήστε το στο πάνελ JS ενός νέου CodePen (ως module). Εισάγει το postext από το esm.sh, οπότε δεν χρειάζεται εγκατάσταση ούτε build.

- Φάκελος πηγής: https://github.com/drnachio/postext/tree/main/cookbook/code-listings-and-keycaps

### script.js

````js
// ═══ Postext Cookbook · Nº 048 · Code listings and keycaps ═══
// https://postext.dev/en/cookbook/code-listings-and-keycaps
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Charis SIL, Sora, JetBrains Mono (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocument, prepareFonts, withLoadedFonts, renderPageToCanvas,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'code-listings-and-keycaps';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#1b1f24', muted: '#5c636b', ember: '#9a5410', // text, heads, accent
  night: '#0e1116', code: '#d3d9df', amber: '#f2b134', phosphor: '#3ddc84', // the listings
  slate: '#8a939d' }; // comments in a listing, the outline of a key (code is its face)
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the accent, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.ember })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, MONO] = ['Charis SIL', 'Sora', 'JetBrains Mono'];
const LEAD = 14.5; // pt: the body leading, the page's baseline grid
const ZERO = pt(0);

// #region answer: a fence is a code listing; codeStyle gives it a dark box
// A ``` fence is a listing set line by line as written: indents, blank lines and the output
// columns of a session are kept. The rest of the fence line (Terminal, backup.sh) is its
// title; with a label set, it goes on the tab.
// The text after a listing goes in :::paragraphs{style="resume"}: flush, as after a heading.
const resume = { id: 'resume', firstLineIndent: ZERO };
const codeStyle = {
  fontFamily: MONO, fontSize: pt(8.6), lineHeight: pt(12.4), color: col('code'),
  background: col('night'), span: 'page', // across the text and the margin
  padding: { top: mm(4), right: mm(5), bottom: mm(4), left: mm(5) },
  marginTop: mm(6), marginBottom: mm(2.5),
  label: { fontFamily: MONO, fontSize: pt(7), fontWeight: 700, color: col('phosphor'),
    background: col('night'), height: mm(5), offset: mm(5), paddingX: mm(3), // the tab
    position: 'top-left' },
  tokens: tokens(), // the colours, below
  inline: { fontSize: em(0.88) }, // `grep` in running text: the code face, no box
};
// #endregion

// #region paint: keywords amber, strings green, comments slate; a session's typed lines amber
function tokens() {
  const plain = { color: col('code') }; // every other kind in the listing's own colour
  return {
    keyword: { color: col('amber'), bold: true }, function: { color: col('amber'), bold: true },
    string: { color: col('phosphor'), italic: true },
    comment: { color: col('slate'), italic: false }, // upright: the default comment is italic
    prompt: { color: col('amber'), bold: true }, output: plain, // what you type, the answer
    number: plain, type: plain, variable: plain, meta: plain, operator: plain, punctuation: plain,
  };
}
// #endregion

// #region keycaps: keys are chips
// Chips never break or stretch, so a line with keys puts all its slack in its word spaces;
// the breaker tries other breaks before a space passes 140 % (default 200 %).
const spacing = { maxWordSpacing: 1.4 }; // spread into bodyText
const chipStyles = [
  { id: 'key', fontFamily: MONO, fontSize: pt(7.8), bold: true, color: col('ink'),
    background: col('code'), borderColor: col('slate'), borderWidth: pt(0.6),
    borderRadius: pt(1.6), paddingX: em(0.45), paddingY: em(0.14), gap: em(0.3) },
];
// #endregion

// #region sheet: a two-column cheat sheet floated to the foot of its page
const sheet = { id: 'sheet', background: col('night'), span: 'page', placement: 'bottom',
  marginTop: mm(6), marginBottom: mm(2.5),
  columnGap: mm(8), padding: { top: mm(5), right: mm(6), bottom: mm(5.5), left: mm(6) },
  titleStyle: { fontFamily: MONO, fontSize: pt(7.5), fontWeight: 700, gap: mm(3.5),
    color: col('phosphor'), textTransform: 'uppercase', letterSpacing: pt(1.5) },
  body: { fontFamily: DISPLAY, fontSize: pt(8.4), lineHeight: pt(13), textAlign: 'left',
    color: col('code'), boldColor: col('amber'), italicColor: col('phosphor'),
    paragraphSpacing: false, firstLineIndent: ZERO } };
// #endregion

const aside = { id: 'aside', span: 'side', backgroundEnabled: false, // notes in the margin
  stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('ember') },
  padding: { top: mm(2.2), right: ZERO, bottom: ZERO, left: ZERO },
  titleStyle: { fontFamily: MONO, fontSize: pt(7.5), fontWeight: 700, color: col('ember'),
    textTransform: 'uppercase', letterSpacing: pt(1.2), gap: mm(1.2) },
  body: { fontFamily: TEXT, fontSize: pt(8.6), lineHeight: pt(12.5), textAlign: 'left',
    firstLineIndent: ZERO } };
const colophon = { ...aside, id: 'colophon', stripe: { enabled: false }, body: { ...aside.body,
  fontFamily: MONO, fontSize: pt(7.5), lineHeight: pt(10.5), color: col('muted'),
  italicColor: col('muted') } };

// #region steps: numbered steps on the grid, a prompt sign for a separator
const orderedLists = { fontFamily: DISPLAY, fontWeight: 800, color: col('ember'),
  gap: em(0.7), separator: '›', separatorGap: em(0.25), separatorFontFamily: MONO,
  separatorFontWeight: 700, separatorColor: col('muted'),
  marginTop: ZERO, marginBottom: ZERO }; // the default 1.5 em opens 5.3 mm above and below
// #endregion

const OUTER = 15; // mm: the outer margin; the running heads align to it
const text = (id, content, family, size, look, placement) => ({ kind: 'text', id, content,
  fontFamily: family, fontSize: pt(size), color: col('ink'), placement, ...look,
  align: 'left' }); // design text is centred by default; an opener wraps its text
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' },
  offset: { x: ZERO, y: mm(y) }, size: { width } });
const opener = { enabled: true, slot: { elements: [
  text('kicker', '{attr.kicker}', MONO, 8, { fontWeight: 700, letterSpacing: pt(1.6),
    textTransform: 'uppercase', color: col('ember') },
  { anchor: { to: 'container', edge: 'top-left' }, offset: { x: ZERO, y: mm(4) } }),
  text('title', '{titleText}', DISPLAY, 33, { fontWeight: 800, lineHeight: 1.04 },
    below('kicker', 3.5, mm(118))),
  text('lead', '{attr.lead}', TEXT, 12, { italic: true, lineHeight: 1.36 },
    below('title', 5, 'fill')),
] } };
const head = (id, content, parity, edge, x, extra = {}) => ({
  kind: 'text', id, content, parity, pages: 'body', fontFamily: MONO, fontSize: pt(7.5),
  letterSpacing: pt(1.1), textTransform: 'uppercase', color: col('muted'),
  placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(12) } }, ...extra,
});
const folio = { fontWeight: 700, color: col('ember') };

const config = () => ({
  locale: t({ en: 'en-us', es: 'es' }), // the hyphenation patterns of each edition
  colorPalette, chipStyles, orderedLists, paragraphStyles: [resume],
  calloutStyles: [sheet, aside, colophon], codeStyle,
  // #region page: a text column and a margin column that only listings and notes enter
  page: { sizePreset: 'custom', width: mm(178), height: mm(229), margins: {
    top: mm(22), bottom: mm(21), left: mm(20), right: mm(OUTER), mirror: true } },
  layout: { layoutType: 'oneAndHalf', sideColumnPercent: 26, gutterWidth: mm(6),
    sideColumnRole: 'floats', sideColumnSide: 'outer' },
  // #endregion
  bodyText: { ...spacing, // keycaps
    fontFamily: TEXT, fontSize: pt(10), lineHeight: pt(LEAD), color: col('ink'),
    boldColor: col('ink'), italicColor: col('ink'), referenceColor: col('ink'),
    firstLineIndent: mm(4.5), indentAfterHeading: false },
  headings: { fontFamily: DISPLAY, color: col('ink'), fontWeight: 800, levels: [
    // parity 'odd': the next recto; the default 'always-odd' also leaves a blank page before it.
    { level: 1, breakBefore: { enabled: true, parity: 'odd' }, advancedDesign: opener },
    { level: 2, fontSize: pt(13), lineHeight: pt(LEAD), marginTop: pt(LEAD), marginBottom: ZERO },
  ] },
  header: { elements: [
    head('verso-folio', '{pageNumber}', 'even', 'top-left', OUTER, folio),
    head('verso-title', '{title}', 'even', 'top-left', OUTER + 8),
    head('recto-title', '{chapterTitle}', 'odd', 'top-right', -(OUTER + 8)),
    head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUTER, folio),
  ] },
  footer: { elements: [head('drop-folio', '{pageNumber}', 'all', 'top', 0, {
    ...folio, pages: 'opener', // the opener has no running head: its folio drops to the foot
    placement: { anchor: { to: 'container', edge: 'top' }, offset: { x: ZERO, y: mm(9) } } })] },
});

// ─── 2 · Content ────────────────────────────────────────────────────────────
const markdown = `---
title: "The Shell, Gently"
subtitle: "A pocket guide to the command line"
author: "Tove Ahlberg"
---

# Small tools, joined {kicker="Chapter 4" lead="How the pipe character chains programs that each do one job to answer a question about a folder."}

Each program in this chapter does one job. \`ls\` lists the names in a folder, \`grep\` keeps the lines that match a pattern, \`sort\` puts lines in order and \`du\` reports how much disk space a file takes. The pipe, the \`|\` character, sends whatever one program prints into the next one, so you can chain them on a single line and read the answer at the end.

:::callout{type="aside" title="The prompt"}
On a Mac, zsh prints \`%\` instead of \`$\`.
:::

Try it in a folder of photographs. In the listings, a line that starts with a dollar sign is one you type, leaving out the dollar, and run with :chip[Enter]{style="key"}. The dollar is the prompt, which the shell prints to show it is waiting for you. The lines under it are the shell’s answer.

\`\`\`console Terminal
$ cd ~/Pictures/2025
$ ls | grep -c 'JPG$'
268
$ ls | grep -v 'JPG$'
IMG_0413.MOV
IMG_0977.MOV
IMG_1502.PNG
$ du -sh *.MOV | sort -rh
812M    IMG_0977.MOV
455M    IMG_0413.MOV
\`\`\`

:::paragraphs{style="resume"}
\`grep -c\` counts the matching lines instead of printing them, and \`-v\` keeps the lines that do not match. The single quotes hand the pattern to \`grep\` as typed; in it, \`$\` marks the end of the line. The star in the last command belongs to the shell: before \`du\` starts, \`*.MOV\` is already the list of names ending in \`.MOV\`.
:::

:::callout{type="aside" title="On a Mac"}
:chip[Ctrl]{style="key"} is :chip[control]{style="key"}

:chip[Enter]{style="key"} is :chip[return]{style="key"}

Shortcuts use :chip[control]{style="key"}, not :chip[command]{style="key"}.
:::

## When a command will not stop

Sooner or later you will start a command that does not finish. Type \`grep JPG\` with no file after it, and \`grep\` sits waiting for you to type the lines it should search. To stop it, hold :chip[Ctrl]{style="key"} and press :chip[C]{style="key"}; the prompt comes back and nothing has changed. To end its input properly instead, press :chip[Ctrl]{style="key"} :chip[D]{style="key"} at the start of an empty line; \`grep\` reads it as the end of its input. :chip[Ctrl]{style="key"} :chip[C]{style="key"} also stops a \`ping\`, which would otherwise print a line every second until you close the window.

The shell also saves you typing. After the first letters of a file or folder name, press :chip[Tab]{style="key"} and the shell fills in the rest; when more than one name fits, it lists them (bash waits for a second :chip[Tab]{style="key"}). :chip[↑]{style="key"} brings back the last command, and each press goes one further back, so a pipeline with a typo can be mended instead of typed again.

1. Type \`cd ~/Pic\` and press :chip[Tab]{style="key"} to complete the folder name, \`Pictures/\`, then add \`2025\` and press :chip[Enter]{style="key"}.
2. Press :chip[↑]{style="key"} until \`ls | grep -v 'JPG$'\` is back on the line.
3. Hold :chip[Ctrl]{style="key"} and press :chip[A]{style="key"} to jump to the start of the line, then :chip[Ctrl]{style="key"} :chip[E]{style="key"} to return to the end.
4. Type \`| sort -r\` and press :chip[Enter]{style="key"}. The same names come back in reverse order.

:::callout{type="sheet" title="Cheat sheet · bash and zsh"}
:::columns{count=2 breaks="8"}
**On the line**

:chip[Ctrl]{style="key"} :chip[A]{style="key"} start of the line

:chip[Ctrl]{style="key"} :chip[E]{style="key"} end of the line

:chip[Ctrl]{style="key"} :chip[W]{style="key"} cut the word to the left

:chip[Ctrl]{style="key"} :chip[K]{style="key"} cut to the end of the line

:chip[Ctrl]{style="key"} :chip[Y]{style="key"} paste what you cut

:chip[Ctrl]{style="key"} :chip[T]{style="key"} swap two letters

**Commands and history**

:chip[Ctrl]{style="key"} :chip[R]{style="key"} search earlier commands

:chip[Ctrl]{style="key"} :chip[P]{style="key"} the previous command

:chip[Ctrl]{style="key"} :chip[C]{style="key"} stop the running command

:chip[Ctrl]{style="key"} :chip[Z]{style="key"} pause it; \`fg\` resumes it

:chip[Ctrl]{style="key"} :chip[L]{style="key"} clear the screen

:chip[Ctrl]{style="key"} :chip[D]{style="key"} close the shell (empty line)
:::
:::

## A script to keep

Commands you type every week are worth keeping in a file. The one below copies each folder in Documents to an external disk, into a new folder named after the day’s date. Save it as \`backup.sh\` in your home folder.

\`\`\`bash backup.sh
#!/usr/bin/env bash
# Copy each folder in ~/Documents to a dated folder on the backup disk.
set -euo pipefail

src="$HOME/Documents"
dest="/Volumes/Backup/$(date +%F)"

mkdir -p "$dest"
for dir in "$src"/*/; do
  name=$(basename "$dir")
  rsync -a "$dir" "$dest/$name/"
  echo "copied $name"
done
\`\`\`

:::callout{type="aside" title="Archive mode"}
\`rsync -a\` copies the subfolders too and keeps each file’s dates and permissions.
:::

:::paragraphs{style="resume"}
The first line, the *shebang*, names the program that runs the file. \`set -euo pipefail\` stops the script at the first command that fails, so it never carries on with half a backup. \`$(date +%F)\` runs \`date\` and puts what it prints, such as 2026-09-26, into the path. The quotes round each variable keep a folder called My Taxes in one piece; without them the shell would split the name at the space and \`rsync\` would look for two folders that do not exist.
:::

Run \`chmod +x backup.sh\` once to make the file executable, then start it with \`./backup.sh\`. On Linux an external disk usually appears under \`/media\`, in a folder named after your user, so change the \`dest\` line to match.

:::callout{type="colophon"}
*The Shell, Gently* is a fictional book written for the Postext Cookbook. Set in Charis SIL, Sora and JetBrains Mono (SIL OFL). Text: original, CC BY 4.0.
:::

Chapter 5 points \`grep\` at the log files under \`/var/log\`, where a pipeline of three commands counts how many errors the system logged on each day of the past week.
`; // content.<lang>.md, inlined by the Cookbook
const continuation = { pageIndexOffset: 48, pageNumbering: { startAt: 49 } }; // p. 49, a recto

// ─── 3 · Fonts ──────────────────────────────────────────────────────────────
const FONTS = { 'Charis SIL': ['400', '400i'], Sora: ['400', '700', '800'],
  'JetBrains Mono': ['400', '400i', '700'] };

// ─── 4 · Build & show ───────────────────────────────────────────────────────
await prepareFonts(markdown, config(), kitFonts(FONTS));
const build = () => buildDocument({ markdown, continuation }, config());
const doc = await withLoadedFonts(build, { ...kitFonts(FONTS), text: markdown });
showPages(doc, { title: t({ en: 'The Shell, Gently', es: 'La terminal, con calma' }) });

// ─── Kit ── helpers shared by every Cookbook recipe · postext.dev/cookbook ─────

// ─── Kit · core v1 ── the same in every recipe · postext.dev/cookbook
function mm(value) { return { value, unit: 'mm' }; }
function pt(value) { return { value, unit: 'pt' }; }
function em(value) { return { value, unit: 'em' }; }
/** The sample language's string: t({ en: 'Figure', es: 'Figura' }). */
function t(strings) { return strings[LANG] ?? Object.values(strings)[0]; }
/** A file in this recipe's assets folder, served from the Postext repo by jsDelivr. */
function asset(file) { return `https://cdn.jsdelivr.net/gh/drnachio/postext@main/cookbook/${RECIPE}/assets/${file}`; }

// ─── Kit · fonts v3 ── the same in every recipe · postext.dev/cookbook
// Postext loads the faces a config asks for before layout and asks the kit
// for Fontsource's files, the ones the PDF embeds too.

/** buildDocumentWithFonts' options: the resolver, and FONTS' faces loaded
 *  with the config's. FONTS = { 'Family Name': ['400', '400i', '700'] }. */
function kitFonts(FONTS = {}) {
  const faces = Object.entries(FONTS).flatMap(([family, specs]) => specs.map((spec) =>
    ({ family, weight: parseInt(spec, 10), style: spec.endsWith('i') ? 'italic' : 'normal' })));
  return { resolve: fontsourceResolver, faces };
}

/** A face's files with their ranges: latin, then latin-ext and greek when
 *  `text` needs them (kitSubsetsFor). Null for a face Fontsource lacks. */
async function fontsourceResolver(family, weight, style, { text = '' } = {}) {
  const id = fontsourceId(family);
  const meta = await fontsourceMeta(family);
  if (meta && !(await fontsourceWeights(family, style)).includes(weight)) return null;
  kitStatus('Loading fonts…');
  const at = await fontsourceAt(id);
  return ['latin', ...kitSubsetsFor(text, meta)].map((subset) => ({
    source: `${at}files/${id}-${subset}-${weight}-${style}.woff2`,
    unicodeRange: kitRanges()[subset],
  }));
}

/** Each file's unicode-range (a function: the kit runs after the pen's code). */
function kitRanges() {
  return {
    latin: 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,'
      + 'U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD',
    'latin-ext': 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,'
      + 'U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF',
    greek: 'U+0370-03FF',
  };
}

/** For the cjk, arabic and comics blocks: loads `faces` (as FONTS) for the
 *  sample `text`; `optional` skips a face Fontsource lacks. Files are added in
 *  the order asked, the last winning a shared character. Resolves to the count. */
async function loadFonts(faces, text = '', { optional = false } = {}) {
  kitStatus('Loading fonts…');
  const ranges = kitRanges();
  const jobs = [];
  for (const [family, specs] of Object.entries(faces)) {
    const id = fontsourceId(family);
    const todo = [...new Set(specs)].map((spec) => [parseInt(spec, 10), spec.endsWith('i') ? 'italic' : 'normal'])
      .filter(([weight, style]) => !hasFace(family, weight, style)); // before any await
    const at = fontsourceAt(id);
    const meta = optional || /[^\0-ÿ]/u.test(text) ? await fontsourceMeta(family) : null;
    const subsets = ['latin', ...kitSubsetsFor(text, meta)];
    for (const [weight, style] of todo) {
      if (optional && !(meta && (await fontsourceWeights(family, style)).includes(weight))) continue;
      for (const subset of subsets) {
        const url = `${await at}files/${id}-${subset}-${weight}-${style}.woff2`;
        const face = new FontFace(family, `url(${url}) format('woff2')`,
          { weight: String(weight), style, unicodeRange: ranges[subset] });
        jobs.push(face.load().catch(() => {
          if (subset === 'latin' && !optional) throw new Error(`Fontsource has no ${family} ${weight} ${style}`);
        }));
      }
    }
  }
  const ready = await Promise.all(jobs).catch((error) => { kitFail(error); throw error; });
  return ready.filter((face) => face && document.fonts.add(face)).length;
}

/** A loaded FontFace covers this face (fonts.check() says yes to any family). */
function hasFace(family, weight, style) {
  for (const face of document.fonts) {
    if (face.status !== 'loaded' || face.style !== style) continue;
    if (face.family.replace(/^["']|["']$/g, '') !== family) continue;
    const [low, high = low] = face.weight.split(' ').map(Number);
    if (weight >= low && weight <= high) return true;
  }
  return false;
}

/** The files beyond latin `text` needs that `meta`'s family ships. */
function kitSubsetsFor(text, meta) {
  return [[/[Ā-˿ᴀ-ᶿḀ-ỿ†ℓⱠ-Ɀ꜠-ꟿ]/u, 'latin-ext'], [/[Ͱ-Ͽ]/u, 'greek']]
    .filter(([re, x]) => re.test(text) && meta?.subsets?.includes(x)).map(([, x]) => x);
}

/** Fontsource's id for a family: 'Source Serif 4' → 'source-serif-4'. */
function fontsourceId(family) { return family.toLowerCase().replace(/\s+/g, '-'); }

/** A package's folder at the one version @5 names now (#766). */
function fontsourceAt(id, u = `https://cdn.jsdelivr.net/npm/@fontsource/${id}@`) {
  return (fontsourceAt.c ??= {})[id] ??= fetch(u + '5/package.json').then((r) => r.json())
    .then((p) => p.version || 5, () => 5).then((v) => `${u}${v}/`);
}

/** The family's Fontsource metadata (weights, styles, subsets), or null. */
function fontsourceMeta(family, id = fontsourceId(family)) {
  return (fontsourceMeta.c ??= {})[id] ??= fetch(`https://api.fontsource.org/v1/fonts/${id}`)
    .then((res) => (res.ok ? res.json() : null), () => null);
}

/** The weights the package ships in `style`: the API pairs none (no Libre
 *  Caslon 700 italic file), so italics are read from latin-italic.css. */
function fontsourceWeights(family, style, id = fontsourceId(family)) {
  return (fontsourceWeights.c ??= {})[id + style] ??= fontsourceMeta(family).then(async (m) => {
    if (!m?.styles.includes(style)) return m ? [] : [400, 700];
    const css = style === 'italic' ? await fetch(`${await fontsourceAt(id)}latin-italic.css`).then((r) => (r.ok ? r.text() : ''), () => '') : '';
    const w = [...css.matchAll(/weight: (\d+)/g)].map((x) => +x[1]);
    return w.length ? w : m.weights;
  });
}

// ─── Kit · viewer v2 ── the same in every recipe · postext.dev/cookbook
/** The pages as spreads on a dark desk, page 1 alone, then verso | recto,
 *  each painted when it scrolls near. Other options go to renderPageToCanvas. */
function showPages(docs, { title, width = 460, ...render } = {}) {
  const root = viewer(title);
  const pages = [docs].flat().flatMap((doc) =>
    doc.pages.map((page) => ({ doc, page, n: (doc.pageIndexOffset ?? 0) + page.index })));
  const spreads = [];
  let verso = null;
  for (const p of pages) {
    if (p.n % 2 === 1) { if (verso) spreads.push([verso, null]); verso = p; }
    else { spreads.push([verso, p]); verso = null; }
  }
  if (verso) spreads.push([verso, null]);
  const density = Math.min(window.devicePixelRatio || 1, 2);
  showPages.painter?.disconnect();
  const painter = new IntersectionObserver((entries) => {
    for (const { isIntersecting, target } of entries) {
      if (!isIntersecting) continue;
      painter.unobserve(target);
      const { doc, page } = target.postext;
      renderPageToCanvas(page, doc, target, { ...render, scale: (width * density) / page.width });
    }
  }, { rootMargin: '800px' });
  showPages.painter = painter;
  root.replaceChildren(...spreads.map((pair) => {
    const spread = document.createElement('div');
    spread.className = 'pt-spread';
    for (const p of pair) {
      const figure = document.createElement('figure');
      if (p) {
        const label = p.page.pageLabel || String(p.n + 1);
        const canvas = document.createElement('canvas');
        canvas.postext = p;
        canvas.style.aspectRatio = `${p.page.width} / ${p.page.height}`;
        canvas.setAttribute('role', 'img');
        canvas.setAttribute('aria-label', `Page ${label}`);
        const folio = document.createElement('figcaption');
        folio.textContent = label;
        figure.append(canvas, folio);
        painter.observe(canvas);
      } else figure.className = 'pt-blank';
      spread.append(figure);
    }
    return spread;
  }));
  kitStatus(`${pages.length} ${pages.length === 1 ? 'page' : 'pages'}`);
  document.documentElement.dataset.postext = 'ready';
  return pages.length;
}

/** The desk, the bar and the error reporting, created once. */
function viewer(title) {
  if (!document.getElementById('pt-kit')) {
    document.head.insertAdjacentHTML('beforeend', `<style id="pt-kit">
      :root { color-scheme: dark; }
      body { margin: 0; background: #0e1014; color: #b9bcc4; font: 13px/1.45 system-ui, sans-serif; }
      #pt-bar { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center;
        gap: 6px 16px; padding: 10px 16px; background: rgb(14 16 20 / .92); backdrop-filter: blur(6px);
        border-bottom: 1px solid #23262d; }
      #pt-bar strong { color: #f4f1ea; font-weight: 600; }
      #pt-actions { display: flex; gap: 12px; margin-left: auto; }
      #pt-actions a, #pt-actions button { color: #d8a21a; font: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
      #pages { display: grid; justify-items: center; gap: 48px; padding: 32px 16px 72px; }
      .pt-spread { display: flex; }
      .pt-spread figure { margin: 0; width: min(460px, 44vw); }
      .pt-spread canvas { display: block; width: 100%; background: #fff;
        box-shadow: 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figure:first-child canvas { box-shadow: inset -14px 0 14px -14px rgb(0 0 0 / .18), 0 1px 2px rgb(0 0 0 / .5), 0 22px 44px -16px rgb(0 0 0 / .8); }
      .pt-spread figcaption { margin-top: 10px; text-align: center; font: 600 10px/1 system-ui, sans-serif;
        letter-spacing: .18em; text-transform: uppercase; color: #6c7079; }
      .pt-blank { visibility: hidden; }
      @media (max-width: 760px) {
        .pt-spread { flex-direction: column; gap: 32px; }
        .pt-spread figure { width: min(460px, 92vw); }
        .pt-blank { display: none; }
      }
    </style>`);
    document.body.insertAdjacentHTML('afterbegin',
      '<header id="pt-bar"><strong id="pt-title"></strong><span id="pt-status" role="status"></span><span id="pt-actions"></span></header>');
    document.getElementById('pt-title').textContent = document.title || 'Postext';
    addEventListener('error', (event) => kitFail(event.error ?? event.message));
    addEventListener('unhandledrejection', (event) => kitFail(event.reason));
  }
  if (title) document.getElementById('pt-title').textContent = title;
  return document.getElementById('pages')
    ?? document.body.appendChild(Object.assign(document.createElement('main'), { id: 'pages' }));
}

function kitStatus(text) {
  viewer();
  document.getElementById('pt-status').textContent = text;
}

function kitFail(error) {
  document.documentElement.dataset.postext = 'error';
  kitStatus(`Error: ${error?.message ?? error}`);
}

// ─── /Kit ───────────────────────────────────────────────────────────────────────
````

## Παραλλαγές

### Κρεμάστε την καρτέλα στα δεξιά

Η καρτέλα μετακινείται στην πάνω δεξιά γωνία του πλαισίου, που σε μονή σελίδα στέκεται πάνω από τη στήλη περιθωρίου.

```diff
-    position: 'top-left' },
+    position: 'top-right' },
```

### Αριθμήστε τις γραμμές

Κάθε λίστα παίρνει αριθμούς γραμμών σε γκρι, σε μια ζώνη μέσα στο πλαίσιό της. Η ζώνη πιάνει περίπου τέσσερις από τους 73 χαρακτήρες, οπότε το σχόλιο που ανοίγει το `backup.sh` δεν χωρά πια: αναδιπλώνεται μετά το `backup`, και το `disk.` συνεχίζει από κάτω πίσω από ένα `»`. Ο έλεγχος του Συνταγολογίου το αναφέρει ως προειδοποίηση `codeOverflow`· συντομέψτε το σχόλιο για να κρατήσετε το σενάριο στις 13 γραμμές του. Μια μεμονωμένη λίστα παίρνει αριθμούς με `{lineNumbers}` στη γραμμή του περιφράγματός της.

```diff
+  lineNumbers: true, lineNumberColor: col('slate'),
   tokens: tokens(), // the colours, below
```

### Δώστε στα σχόλια το χρώμα των συμβολοσειρών

Τα σχόλια παίρνουν το πράσινο των συμβολοσειρών, σε πλάγια.

```diff
-    comment: { color: col('slate'), italic: false }, // upright: the default comment is italic
+    comment: { color: col('phosphor'), italic: true }, // the strings' green italic
```

## Συνήθη λάθη

- **Ένα πλευρικό πλαίσιο αρχίζει στο ύψος του μπλοκ μετά το fence του.** Στο postext 1.4.1 ένα πλαίσιο span: 'side' στέκεται στην πλευρική στήλη στο ύψος που έχει φτάσει το κείμενο στο fence του, στην επόμενη γραμμή πλέγματος, και κάτω από όποιο πλαίσιο βρίσκεται ήδη εκεί. Βάλτε το fence ενός σχολίου ακριβώς πριν από την παράγραφο που εξηγεί: αν μπει μετά, το σχόλιο αρχίζει δίπλα στην επόμενη παράγραφο. Ένα πλαίσιο που θα ξεπερνούσε τη βάση της στήλης γλιστρά προς τα πάνω ώσπου η βάση του να κάθεται στη βάση της στήλης, όσο επιτρέπει το πλαίσιο από πάνω του· ένα που και πάλι δεν χωρά περιμένει την πλευρική στήλη της επόμενης σελίδας.

- Κρατήστε κάθε γραμμή κώδικα μέσα στους 73 χαρακτήρες. Μια μακρύτερη αναδιπλώνεται στο τελευταίο της διάστημα ή σημείο στίξης που χωρά και συνεχίζει από κάτω πίσω από ένα `»`, και η μηχανή αναφέρει προειδοποίηση `codeOverflow`· το `overflow: 'shrink'` στοιχειοθετεί αντί γι’ αυτό ολόκληρη τη λίστα μικρότερη, και το `'clip'` κόβει τη γραμμή στην άκρη του πλαισίου.
- Ένα tab σε λίστα κώδικα προχωρά στο επόμενο πολλαπλάσιο των τεσσάρων στηλών (`codeStyle.tabSize`). Ένα σενάριο με εσοχές από tab που ο επεξεργαστής σας δείχνει με πλάτος οκτώ στηλών βγαίνει εδώ στενότερο.
- Με ορισμένο το `codeStyle.inline`, ο κώδικας μέσα στο κείμενο δεν σπάει ποτέ ανάμεσα σε γραμμές, όπως και μια ετικέτα. Μια μακριά διαδρομή μέσα στο τρέχον κείμενο, όπως `~/Pictures/2025/IMG_0977.MOV`, πηγαίνει ολόκληρη στην επόμενη γραμμή και μπορεί να αφήσει πίσω της μια χαλαρή γραμμή.

## Ευχαριστίες

- Συνταγή: Ignacio Ferro ([@drnachio](https://github.com/drnachio))
- Γραμματοσειρές: Charis SIL (OFL-1.1), Sora (OFL-1.1), JetBrains Mono (OFL-1.1)
- Κώδικας: MIT · Δείγμα περιεχομένου: CC-BY-4.0

## Σχετικές συνταγές

- [Αρ. 050 · Εγχειρίδιο προϊόντος με ειδοποιήσεις ασφαλείας](https://postext.dev/el/cookbook/product-manual-warnings.md): Γερμανικό εγχειρίδιο βραστήρα: πλαίσια WARNUNG και VORSICHT με τρίγωνο προειδοποίησης σε ταινία χρώματος σήματος, γερμανικές ονομασίες εικόνων και πινάκων. · Επίπεδο 2 (Μεσαίο) · Εγχειρίδια, οδηγοί και έργα αναφοράς
- [Αρ. 008 · Μια οικογένεια πλαισίων σχολικού βιβλίου με χρωματικό κώδικα](https://postext.dev/el/cookbook/textbook-box-family.md): Έξι πλαίσια σχολικού βιβλίου σε τρία χρώματα, που ξεχωρίζουν με λωρίδα και εικονίδιο, σήμα, αριθμημένη καρτέλα, σειρά εικονογραμμάτων ή σημάδι εκτός πλαισίου. · Επίπεδο 2 (Μεσαίο) · Σχολικά βιβλία
- [Αρ. 022 · Φύλλο εργασίας με πλαίσια απαντήσεων και τράπεζα λέξεων](https://postext.dev/el/cookbook/worksheet-answer-boxes.md): Τετρασέλιδο φύλλο εργασίας φυσικών: λευκά πλαίσια απαντήσεων σε πράσινες κάρτες, 2 mm κάτω από κάθε ερώτηση εκτός πλέγματος, λέξεις και κενά σε ετικέτες. · Επίπεδο 2 (Μεσαίο) · Τετράδια και ασκήσεις
