rapier-html 1.1.55 → 1.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BUILD.json +5 -5
- package/README.md +21 -8
- package/{cli.mjs → dist/cli.mjs} +0 -0
- package/dist/ledger/LICENSE +45 -0
- package/dist/ledger/authorship.mjs +59 -0
- package/dist/ledger/carried.mjs +69 -0
- package/dist/ledger/data.mjs +33 -0
- package/dist/ledger/format.mjs +131 -0
- package/dist/ledger/hash.mjs +47 -0
- package/dist/ledger/journal-records.mjs +139 -0
- package/{page.mjs → dist/page.mjs} +8 -12
- package/dist/rapier.html +952 -0
- package/package.json +4 -7
- package/rapier.html +0 -952
- /package/{return-address.mjs → dist/return-address.mjs} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {encodeCarried, decodeCarried, writeParts, takeParts, readDocument} from './ledger/carried.mjs';
|
|
1
2
|
import {readFile, writeFile} from 'node:fs/promises';
|
|
2
3
|
import {basename, dirname, join} from 'node:path';
|
|
3
4
|
import {PAGE_SEED, returnAddress, returnExpiresAt} from './return-address.mjs';
|
|
@@ -13,14 +14,6 @@ const SEARCH_WORDS = /<!-- RAPIER_SEO_BEGIN -->[\s\S]*?<!-- RAPIER_SEO_END -->\n
|
|
|
13
14
|
|
|
14
15
|
// One encoding, exactly reversible (docs/page-door.md, "What a block may hold"): no `<` before `/` or `!`, no CR, no NUL.
|
|
15
16
|
// engine.js _rapierDecodeCarried is its inverse.
|
|
16
|
-
function encodeCarried(text) {
|
|
17
|
-
return String(text).replace(/[\\\r\0]|<[/!]/g, m =>
|
|
18
|
-
m === '\\' ? '\\\\' : m === '\r' ? '\\r' : m === '\0' ? '\\0' : m === '</' ? '\\/' : '\\!');
|
|
19
|
-
}
|
|
20
|
-
function decodeCarried(text) {
|
|
21
|
-
return String(text).replace(/\\([\\/!r0])/g, (_, c) =>
|
|
22
|
-
c === '\\' ? '\\' : c === 'r' ? '\r' : c === '0' ? '\0' : c === '/' ? '</' : '<!');
|
|
23
|
-
}
|
|
24
17
|
export {encodeCarried, decodeCarried};
|
|
25
18
|
|
|
26
19
|
const PROPOSED_AT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/;
|
|
@@ -33,7 +26,9 @@ function safeName(name, fallback) {
|
|
|
33
26
|
export function wrap(pageHtml, text, name, options) {
|
|
34
27
|
if (typeof pageHtml !== 'string' || !pageHtml.includes('</body>')) throw new Error('not a Rapier page: no </body>');
|
|
35
28
|
if (typeof text !== 'string') throw new Error('the document must be text');
|
|
36
|
-
const
|
|
29
|
+
const saved = readDocument(text);
|
|
30
|
+
text = saved.text;
|
|
31
|
+
const opts = {...saved, ...(options || {})};
|
|
37
32
|
const docName = safeName(name, 'document.md');
|
|
38
33
|
// `view`: the view the page opens on with the document behind it, `draw` or `notes` (docs/page-door.md).
|
|
39
34
|
if (opts.view != null && !['draw', 'notes'].includes(opts.view)) throw new Error('the view is draw or notes');
|
|
@@ -42,11 +37,11 @@ export function wrap(pageHtml, text, name, options) {
|
|
|
42
37
|
if (!!address !== !!expiry) throw new Error('a return needs its URL and return_expires_at from document.create_return');
|
|
43
38
|
const block = START + ' data-name="' + docName + '"' + (opts.view ? ' data-view="' + opts.view + '"' : '') +
|
|
44
39
|
(address ? ' data-return="' + address + '" data-return-expires-at="' + expiry + '"' : '') + '>' + encodeCarried(text) + END;
|
|
45
|
-
let carriedBlocks = '';
|
|
40
|
+
let carriedBlocks = '\n' + writeParts(text, opts);
|
|
46
41
|
if (opts.drawing != null) {
|
|
47
42
|
if (typeof opts.drawing !== 'string') throw new Error('the drawing must be SVG text');
|
|
48
43
|
const drawingName = safeName(opts.drawingName, 'drawing.svg');
|
|
49
|
-
carriedBlocks
|
|
44
|
+
carriedBlocks += '\n' + DRAWING_START + ' data-name="' + drawingName + '">' + encodeCarried(opts.drawing) + END;
|
|
50
45
|
}
|
|
51
46
|
if ((opts.by != null || opts.at != null) && opts.base == null) throw new Error('a proposer needs the base it proposes over');
|
|
52
47
|
if (opts.base != null) {
|
|
@@ -113,7 +108,8 @@ export function unwrap(pageHtml) {
|
|
|
113
108
|
html = html.slice(0, e) + html.slice(b + END.length);
|
|
114
109
|
if (e > 0 && html[e - 1] === '\n') html = html.slice(0, e - 1) + html.slice(e);
|
|
115
110
|
}
|
|
116
|
-
|
|
111
|
+
const parts = takeParts(html, text);
|
|
112
|
+
return {...parts, text, name, view, drawing, drawingName, base, baseName, by, at, return: address, return_expires_at: expiry};
|
|
117
113
|
}
|
|
118
114
|
// Unknown options, a bare --drawing or --base and a third name are refused, never dropped.
|
|
119
115
|
const USAGE = 'usage: rapier-html <document.md> [out.html] [--view draw|notes] [--drawing sketch.svg] [--base original.md [--by <your name>]] [--return <url> --return-expires-at <timestamp>]\n' +
|