rapier-html 1.2.33 → 1.2.40

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/dist/wrap.mjs CHANGED
@@ -15,7 +15,7 @@ const OFFLINE_POLICY = "default-src 'none'; script-src 'unsafe-inline' 'wasm-uns
15
15
 
16
16
  export {encodeCarried, decodeCarried};
17
17
 
18
- const PREVIEW = /<meta (?:name="(?:description|generator)"|property="og:(?:title|description)") content="[^"]*" data-rapier-preview>\n?/g;
18
+ const PREVIEW = /<meta (?:name="(?:description|generator)"|property="og:(?:title|description)") content="[^"]*" data-rapier-preview(?:="")?>\n?/g;
19
19
  const APPEARANCE = /<meta name="rapier-appearance" content="(light|dark)">\n?/g;
20
20
  const plainWords = text => text.replace(/!\[[^\]]*\]\[[^\]]*\]|!\[[^\]]*\]\([^)]*\)/g, '').replace(/\[([^\]]*)\](?:\([^)]*\)|\[[^\]]*\])/g, '$1')
21
21
  .replace(/<[^>]*>/g, '').replace(/[*_`~=]+|\[\^[^\]]*\]/g, '').replace(/\s+/g, ' ').trim();
@@ -45,6 +45,12 @@ function previewHead(markdown, fallbackTitle) {
45
45
  (description ? meta('property', 'og:description', description) : '') + meta('name', 'generator', 'Rapier (https://rapier.website)');
46
46
  }
47
47
 
48
+ function readableText(text) {
49
+ const words = text.replace(/^(\[[^\]\n]+\]:\s*)data:\S+/gm, '$1(embedded picture)').replace(/\((data:[^)\s]+)\)/g, '(embedded picture)')
50
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
51
+ return '<pre style="white-space:pre-wrap;font:inherit;margin:0">' + words + '</pre>';
52
+ }
53
+
48
54
  function readableBlock(html) {
49
55
  if (typeof html !== 'string' || !html.trim() || /<\/noscript|<!--/i.test(html)) return '';
50
56
  return '\n<noscript id="rapier-readable"><style>html,body{background:#fff;color:#000}a{color:#0000ee}</style><main style="max-width:44rem;margin:0 auto;padding:1rem">' + html + '</main></noscript>';
@@ -61,8 +67,8 @@ export function offlineTemplate(pageHtml, address = null) {
61
67
  const match = new RegExp('\\b' + name + '\\s*=\\s*(?:"([^"]*)"|\'([^\']*)\'|([^\\s>]+))', 'i').exec(tag);
62
68
  return match ? match[1] ?? match[2] ?? match[3] : '';
63
69
  };
64
- const head = pageHtml.slice(0, end).replace(/<meta\b[^>]*>/gi, tag =>
65
- attribute(tag, 'http-equiv').toLowerCase() === 'content-security-policy' ? '' : tag).replace(/<link\b[^>]*>/gi, tag =>
70
+ const head = pageHtml.slice(0, end).replace(/<meta\b[^>]*>\n?/gi, tag =>
71
+ attribute(tag, 'http-equiv').toLowerCase() === 'content-security-policy' ? '' : tag).replace(/<link\b[^>]*>\n?/gi, tag =>
66
72
  attribute(tag, 'rel').toLowerCase().split(/\s+/).some(rel => ['icon', 'apple-touch-icon', 'manifest', 'preconnect', 'dns-prefetch'].includes(rel)) ? '' : tag);
67
73
  const anchor = /<meta charset[^>]*>\n?/i.exec(head) || /<head[^>]*>\n?/.exec(head);
68
74
  if (!anchor) throw new Error('not a Rapier page: no <head>');
@@ -169,7 +175,7 @@ export function wrap(pageHtml, text, name, options) {
169
175
  const titled = stripped.replace(/<title>[^<]*<\/title>\n?/, all => '<title>' + docName.replace(/&/g, '&amp;').replace(/</g, '&lt;') + ' — Rapier</title>' +
170
176
  (all.endsWith('\n') ? '\n' : '') + previewHead(text, docName.replace(/\.[^.]*$/, '')));
171
177
  const shift = titled.length - stripped.length;
172
- return titled.slice(0, at + shift) + '\n' + block + carriedBlocks + readableBlock(opts.readable) + titled.slice(at + shift);
178
+ return titled.slice(0, at + shift) + '\n' + block + carriedBlocks + readableBlock(opts.readable === undefined ? readableText(text) : opts.readable) + titled.slice(at + shift);
173
179
  }
174
180
  export function unwrap(pageHtml) {
175
181
  const theme = Array.from(pageHtml.matchAll(APPEARANCE), match => match[1])[0] || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-html",
3
- "version": "1.2.33",
3
+ "version": "1.2.40",
4
4
  "description": "One command turns a Markdown file into one offline HTML file: the whole Rapier editor with the document inside. Opens in any browser, phone or desktop, with no install or account. Write, draw and paint watercolor, then Send back the edits to your AI agent.",
5
5
  "keywords": [
6
6
  "markdown",