Με λίγα λόγια
Μια επιμελήτρια άφησε πέντε σημειώσεις στο προσχέδιο ενός οδηγού πεζοπορίας και ο συγγραφέας το άλλαξε. Η σελίδα ψάχνει κάθε σημείωση στο νέο κείμενο. Κάποιες είναι στη θέση τους, άλλες μετακινήθηκαν, μία ταιριάζει σε τρία σημεία.
Τι θα στοιχειοθετήσετε
Μια διαδρομή από το Walks from the Valley Station, έναν οδηγό σε σελίδα 135 × 200 mm. Μια επιμελήτρια άφησε πέντε σημειώσεις στο πρώτο προσχέδιο· ύστερα ο συγγραφέας πρόσθεσε μια πρόταση, ξανάγραψε μια άλλη και έσβησε μια τρίτη. Το pen ψάχνει κάθε σημείωση στο αναθεωρημένο κείμενο και δείχνει την απάντηση σε δύο σημεία. Η λίστα δεξιά δίνει σε κάθε σημείωση την κατάστασή της: μία στη θέση της, δύο μετακινημένες, μία αμφίσημη ανάμεσα σε τρία σκαλοπάτια φράχτη και μία ορφανή. Οι σελίδες αριστερά φέρουν όσες σημειώσεις επιζούν, αριθμημένες στο περιθώριο, και πλαισιώνουν τα τρία σημεία που θα μπορούσε να εννοεί η αμφίσημη.
Αυτή η συνταγή απαντά
- Πώς κρατώ τα σχόλια δεμένα στο χωρίο τους όταν αναθεωρείται το κείμενο;
Η σύντομη απάντηση
const COLOR = { exact: '#1f7a45', moved: '#b0640a', ambiguous: '#7b4cc4' };
const found = NOTES.map((note) => resolveAnchor(markdown, note.anchor));
const marks = NOTES.flatMap((note, i) => {
const at = found[i];
const label = String(i + 1);
// In place or moved: one range, the note's mark with its number in the margin.
if (at.status === 'exact' || at.status === 'moved') {
return [{ id: note.id, kind: 'note', range: at, label, color: COLOR[at.status] }];
}
// Ambiguous: every place the words fit, boxed, for a person to choose.
if (at.status === 'ambiguous') {
return at.candidates.map((range, k) => ({ id: `${note.id}.${k}`, kind: 'box', range,
color: COLOR.ambiguous }));
}
return []; // orphaned: the words are gone, the note stays in the thread
});
view.setAnnotations(marks);
Υλικά
- Λειτουργίες
- Άγκυρες που αντέχουν στις αναθεωρήσειςΣημάδια σχολιασμούΠρόγραμμα προβολής σελίδων (postext-viewer)Σελίδες σε καμβάΓραμματοσειρές πριν από τη σελιδοποίησηΤρέχουσες κεφαλίδες και αριθμοί σελίδαςΣυμμετρικά περιθώριαΣημασιολογική χρωματική παλέτα
- Χρησιμοποιεί επίσης
- Κεφαλίδες ανά ρόλο σελίδας
- Γραμματοσειρές
- Newsreader, Archivo (SIL OFL 1.1)
- Αρχεία
- Κανένα: κάθε εικόνα σχεδιάζεται με κώδικα
Προετοιμασία
#1 · Αποθηκεύστε άγκυρα, όχι θέση
// [the words to find in the draft, the words noted, the note]. A CMS reads the anchors from
// its database; here they are made on the draft so the pen runs on its own.
const NOTES = t({
en: [
['follow the wall up the field', 'the wall', 'Rebuilt last winter: does it reach the top?'],
['a cairn that walkers have built', 'a cairn', 'A photograph of the cairn would help here.'],
['Cross the stile at', 'the stile', 'Which way does this stile face?'],
['the bog on either side is deeper', 'the bog on either side is deeper',
'Rangers say knee-deep at most. Too alarming?'],
['The stepping stones at the ford', 'The stepping stones', 'Give the detour in minutes.'],
],
es: [
['sigue el muro prado arriba', 'el muro', '¿Lo rehicieron este invierno? ¿Sigue hasta arriba?'],
['un hito de piedras que los caminantes', 'un hito de piedras', 'Aquí iría bien una foto.'],
['Salta la escalera del', 'la escalera', '¿Hacia dónde da esta escalera?'],
['la turbera de los lados es más honda', 'la turbera de los lados es más honda',
'Los guardas dicen que no pasa de la rodilla.'],
['Las piedras del vado resbalan', 'Las piedras del vado', 'Da el rodeo en minutos.'],
],
}).map(([around, words, body], i) => {
const start = earlier.indexOf(around) + around.indexOf(words);
const anchor = textAnchor(earlier, { start, end: start + words.length }); // 32 chars a side
return { id: `n${i + 1}`, body, anchor };
});
Η textAnchor κρατά το εύρος, τις λέξεις που κάλυπτε και 32 χαρακτήρες από κάθε πλευρά. Είναι απλό JSON, φτιαγμένο για μια γραμμή βάσης δεδομένων δίπλα στη σημείωση. Ένα CMS την αποθηκεύει όταν γράφεται η σημείωση· το pen φτιάχνει τις άγκυρες πάνω στο προσχέδιο για να τρέχει μόνο του.
#2 · Αναζητήστε κάθε άγκυρα στο νέο κείμενο
Ο κώδικας είναι η σύντομη απάντηση παραπάνω. Η resolveAnchor δοκιμάζει πρώτα τις αποθηκευμένες θέσεις, έπειτα τις λέξεις με όλα τα συμφραζόμενά τους οπουδήποτε στο αρχείο, μετά με λιγότερα συμφραζόμενα και τέλος τις λέξεις μόνες, και σταματά στο πρώτο βήμα που δίνει απάντηση. Ποτέ δεν διαλέγει ανάμεσα σε δύο σημεία: η σημείωση για το «the stile» έχασε τα συμφραζόμενά της όταν ξαναγράφτηκε η πρόταση, και οι λέξεις μόνες ταιριάζουν σε τρία σκαλοπάτια, οπότε η απάντηση είναι ambiguous με τους τρεις υποψηφίους. Τι θα σχεδιαστεί για κάθε κατάσταση το αποφασίζει ο ιστότοπος.
#3 · Πείτε τι απέγινε κάθε σημείωση
const STATUS = t({
en: { exact: 'In place', moved: 'Moved', ambiguous: 'Ambiguous', orphaned: 'Orphaned' },
es: { exact: 'En su sitio', moved: 'Movida', ambiguous: 'Ambigua', orphaned: 'Huérfana' },
});
const detail = (note, at) => ({
exact: () => `${at.start}`,
moved: () => `${note.anchor.start} → ${at.start}`,
ambiguous: () => at.candidates.map((c) => c.start).join(' · '),
orphaned: () => t({ en: 'the words are gone', es: 'las palabras ya no están' }),
})[at.status]();
document.getElementById('notes').replaceChildren(...NOTES.map((note, i) => {
const at = found[i];
const li = document.createElement('li');
li.className = at.status;
li.innerHTML = '<button type="button"><b></b><span class="status"></span><q></q>'
+ '<span class="body"></span><small></small></button>';
const [n, status, quote, body, small] = li.querySelectorAll('b, .status, q, .body, small');
n.textContent = String(i + 1);
status.textContent = STATUS[at.status];
quote.textContent = note.anchor.text;
body.textContent = note.body;
small.textContent = detail(note, at);
const id = at.status === 'ambiguous' ? `${note.id}.0` : note.id;
li.firstChild.addEventListener('click', () => view.revealAnnotation(id, { behavior: 'smooth' }));
li.firstChild.disabled = at.status === 'orphaned';
return li;
}));
document.getElementById('title').textContent = t({ en: 'Notes on the draft',
es: 'Notas del borrador' });
Μια μετακινημένη σημείωση δείχνει την παλιά και τη νέα της θέση, μια αμφίσημη τους υποψηφίους της, και η ορφανή κρατά τις λέξεις της διαγραμμένες ώστε η επιμελήτρια να ξέρει ακόμη τι αφορούσε. Ένα πάτημα σε μια σημείωση κυλά την προβολή ως το σημάδι της με τη revealAnnotation.
Η πλήρης συνταγή
// ═══ Postext Cookbook · Nº 217 · Anchors through a revision ═══════════════════════════
// https://postext.dev/en/cookbook/anchors-through-a-revision
// Code: MIT · Text: original (CC BY 4.0) · Pictures: none
// Fonts: Newsreader, Archivo (SIL OFL 1.1) · Needs postext ≥ 1.103.0
//
// An editor left five notes on the first draft of a walking guide; the author then revised the
// text. Each note was stored as an anchor (its words and some context), and each is looked for
// in the new revision: found in place, moved, ambiguous between several places, or orphaned.
// The notes that survive are drawn on the new pages, the others wait in the list for a person.
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 = 'anchors-through-a-revision';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, every one linked by id
const palette = {
ink: '#202421', // text
accent: '#3d6b45', // moorland green: headings, folios
muted: '#6b7068', // 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.6; // pt of body leading
const head = (id, content, parity, edge, x, extra = {}) => ({ kind: 'text', id, content, parity,
pages: 'body', fontFamily: 'Archivo', fontSize: pt(7), fontWeight: 500, letterSpacing: pt(0.8),
textTransform: 'uppercase', color: col('muted'),
placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(10) } }, ...extra });
const folio = { fontWeight: 600, color: col('accent') };
const config = {
locale: t({ en: 'en-gb', es: 'es' }),
colorPalette,
page: { sizePreset: 'custom', width: mm(135), height: mm(200), dpi: 150,
margins: { top: mm(19), bottom: mm(20), left: mm(17), right: mm(15), mirror: true } },
layout: { layoutType: 'single' },
bodyText: { fontFamily: 'Newsreader', fontSize: pt(10), lineHeight: pt(LEAD),
color: col('ink'), boldColor: col('accent'), italicColor: col('ink'),
referenceColor: col('ink'), textAlign: 'justify', firstLineIndent: mm(4),
indentAfterHeading: false, hyphenation: { enabled: true }, optimalLineBreaking: true,
avoidWidows: true, avoidOrphans: true, avoidRunts: true },
<main id="pages">
<div id="viewer"></div>
<aside id="panel">
<h2 id="title"></h2>
<ol id="notes"></ol>
</aside>
</main>
/* The host's frame: the revised pages on the left, the notes on the right. */
main#pages {
display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
height: max(560px, calc(100vh - 44px)); gap: 0; padding: 0; justify-items: stretch;
}
#viewer { min-height: 0; }
#viewer .postext-viewer { --pv-background: #0e1014; --pv-focus: #e0a43a; }
#panel { min-height: 0; overflow: auto; background: #15181d; border-left: 1px solid #23262d;
font: 14px/1.45 system-ui, sans-serif; color: #c9ccd3; }
#panel h2 { margin: 0; padding: 16px 18px 10px; font: 600 13px/1.3 system-ui, sans-serif;
letter-spacing: .08em; text-transform: uppercase; color: #f4f1ea; }
#notes { list-style: none; margin: 0; padding: 0 12px 24px; display: grid; gap: 10px; }
#notes button { display: grid; grid-template-columns: 2em 1fr auto; gap: 2px 8px; width: 100%;
min-height: 44px; padding: 10px 12px; text-align: left; font: inherit; color: inherit;
background: #1c2027; border: 1px solid #2c313a; border-left: 4px solid var(--c);
border-radius: 6px; cursor: pointer; }
#notes button:disabled { cursor: default; opacity: .8; }
#notes button:focus-visible { outline: 2px solid #e0a43a; outline-offset: 2px; }
#notes li { --c: #6c7079; }
#notes .exact { --c: #3fb070; }
#notes .moved { --c: #e0913a; }
#notes .ambiguous { --c: #a77de8; }
#notes b { grid-row: span 3; color: var(--c); font-size: 16px; }
#notes .status { grid-column: 3; grid-row: 1; font-size: 12px; font-weight: 600; color: var(--c);
text-transform: uppercase; letter-spacing: .06em; }
#notes q { grid-column: 2; grid-row: 1; color: #f4f1ea; font-style: italic; }
#notes .body { grid-column: 2 / 4; }
#notes small { grid-column: 2 / 4; color: #8a909b; font-variant-numeric: tabular-nums; }
#notes .orphaned q { text-decoration: line-through; color: #9aa0aa; }
Το συντεθειμένο script.js εκτελείται ως έχει: επικολλήστε το στο module script οποιασδήποτε σελίδας ή ανοίξτε τη συνταγή στο CodePen. Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)
Παραλλαγές
#Κρατήστε περισσότερα συμφραζόμενα
Μεγαλύτερα συμφραζόμενα ξεχωρίζουν χωρία που επαναλαμβάνουν τις ίδιες λέξεις, αλλά αποτυγχάνουν νωρίτερα όταν ξαναγράφεται το κείμενο γύρω από μια σημείωση.
- const anchor = textAnchor(earlier, { start, end: start + words.length }); // 32 chars a side
+ const anchor = textAnchor(earlier, { start, end: start + words.length }, { context: 64 });#Σταματήστε πριν από τις λέξεις μόνες
Με minContext 8, μια σημείωση χρειάζεται 8 αμετάβλητους χαρακτήρες από κάθε πλευρά, οπότε οι σύντομες σημειώσεις γίνονται orphaned αντί να ταιριάξουν με κοινές λέξεις αλλού.
- const found = NOTES.map((note) => resolveAnchor(markdown, note.anchor));
+ const found = NOTES.map((note) => resolveAnchor(markdown, note.anchor, { minContext: 8 }));Ευχαριστίες
- Συνταγή
- Ignacio Ferro
- Κείμενο
- Πρωτότυπο κείμενο, CC BY 4.0
- Γραμματοσειρές
- Newsreader (SIL OFL 1.1) · Archivo (SIL OFL 1.1)
- Κώδικας
- MIT, όπως το Postext
Επεξεργασία αυτού του κειμένου ↗ (ανοίγει σε νέα καρτέλα)Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)



