basklee-nuxt 0.9.2 → 0.9.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basklee-nuxt",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Nuxt 4 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@ The supplied storefront uses this component at `/journal`.
8
8
 
9
9
  ## Contract and dependencies
10
10
 
11
- The supplied `app/pages/journal/[id].vue` loads the article during the server render with `blog_posts_get` and `filters.id = postId`, using the visitor's cookies, and passes it in `initialPost`; the browser shows it without another request. Without `initialPost` (after client-side navigation) the component sends the same request itself. Full text appears only when both `is_full` and `has_full_access` are true; otherwise the preview and the access panel remain. Article HTML is sanitized with DOMPurify in `app/utils/basklee/blogArticleHtml.ts` and keeps what the marketplace blog editor writes: headings, paragraphs and line breaks, bold, italic, underline, strikethrough, subscript and superscript, links, bullet, numbered and task lists, quotes, dividers, inline code and code blocks, tables with merged cells, images and galleries, video and audio with controls, collapsible sections, alignment, text color, highlight, font and size. External links open in a new tab with `rel="noopener noreferrer"`; editor links to other articles open `/journal/<id>`. Formulas are shown as their LaTeX source. Wide tables and code blocks scroll inside the article, and floated images stack on narrow screens. Products the author places in the text appear at those positions: an empty block with `data-product-id="12"` shows one product card, `data-product-ids="12,15,9"` a row of up to 24 cards. The block keeps the editor's float or centred style, and `data-product-hidden-badges` (`new`, `popular`, `good-deal`) turns card badges off. Products missing from `related_products` are loaded with `products_search` and `filters.id_in`, up to 35 IDs per request, and stored with `store.setProduct()`; a block whose products are not found stays hidden. Article text styles do not reach the cards, and in a narrow article a floated card stands alone in the middle. The helper is `app/utils/basklee/blogProductPlacements.ts`. Frames, scripts, forms, event attributes and other styles are removed. The server render shows the text as plain paragraphs, which search engines can read; the formatted HTML replaces them in the browser.
11
+ The supplied `app/pages/journal/[id].vue` loads the article during the server render with `blog_posts_get` and `filters.id = postId`, using the visitor's cookies, and passes it in `initialPost`; the browser shows it without another request. Without `initialPost` (after client-side navigation) the component sends the same request itself. Full text appears only when both `is_full` and `has_full_access` are true; otherwise the preview and the access panel remain. Article HTML is sanitized with DOMPurify in `app/utils/basklee/blogArticleHtml.ts` and keeps what the marketplace blog editor writes: headings, paragraphs and line breaks, bold, italic, underline, strikethrough, subscript and superscript, links, bullet, numbered and task lists, quotes, dividers, inline code and code blocks, tables with merged cells, images and galleries, video and audio with controls, YouTube players, collapsible sections, alignment, text color, highlight, font and size. External links open in a new tab with `rel="noopener noreferrer"`; editor links to other articles open `/journal/<id>`. Formulas are shown as their LaTeX source. Wide tables and code blocks scroll inside the article, and floated images stack on narrow screens. Products the author places in the text appear at those positions: an empty block with `data-product-id="12"` shows one product card, `data-product-ids="12,15,9"` a row of up to 24 cards. The block keeps the editor's float or centred style, and `data-product-hidden-badges` (`new`, `popular`, `good-deal`) turns card badges off. Products missing from `related_products` are loaded with `products_search` and `filters.id_in`, up to 35 IDs per request, and stored with `store.setProduct()`; a block whose products are not found stays hidden. Article text styles do not reach the cards, and in a narrow article a floated card stands alone in the middle. The helper is `app/utils/basklee/blogProductPlacements.ts`. A YouTube player the editor inserts is an `<iframe>` with a `youtube.com` or `youtube-nocookie.com` `/embed/<id>` address: it is kept, played from `youtube-nocookie.com` at the article's width in 16:9, with fixed `allow`, `loading="lazy"` and referrer attributes, and an optional start second. Other frames, scripts, forms, event attributes and other styles are removed. The server render shows the article as plain blocks built by `blogArticleBlocks` in the same file: headings, paragraphs with their links (checked like the full text: only web, mail and phone links; editor article links open `/journal/<id>`), lists, quotes and pictures with captions. Search engines read that structure without scripts, the browser hydrates the same blocks, and the formatted HTML replaces them once the component is mounted. Nothing else of the source markup reaches the server render.
12
12
 
13
13
  Reading accounting for an accessible paid article starts after interaction with its visible text. `blog_reading_start` starts a session; `blog_reading_heartbeat` follows the returned interval. Leaving, losing focus, hiding the text or 60 seconds without interaction stops requests. Resuming and delayed timers start a fresh baseline. Confirmed loss of access removes full text and offers a refresh.
14
14
 
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, ref, shallowRef, watch } from 'vue';
2
+ import { computed, defineComponent, h, nextTick, onMounted, ref, shallowRef, watch } from 'vue';
3
+ import type { PropType, VNode } from 'vue';
3
4
  import { useRuntimeConfig } from '#imports';
4
5
  import { useBaskleeStore } from '@/stores/basklee';
5
6
  import { useBaskleeProductsStore } from '@/stores/baskleeProducts';
@@ -16,10 +17,14 @@
16
17
  safePublicUrl,
17
18
  } from '@/utils/basklee/presentation';
18
19
  import {
20
+ blogArticleBlocks,
19
21
  removeLeadingDuplicateBlogHeading,
20
22
  safeBlogArticleHtml,
21
23
  } from '@/utils/basklee/blogArticleHtml';
22
- import { htmlTextParagraphs } from '@/utils/basklee/htmlText';
24
+ import type {
25
+ IBlogArticleInline,
26
+ TBlogArticleBlock,
27
+ } from '@/utils/basklee/blogArticleHtml';
23
28
  import {
24
29
  appMediaUrl,
25
30
  nativeAppOrigin,
@@ -156,10 +161,63 @@
156
161
  const html = computed(() =>
157
162
  safeBlogArticleHtml(articleSource.value, undefined, appOrigin),
158
163
  );
159
- // The server render and hydration show the text as plain paragraphs;
160
- // the sanitized HTML replaces them once the component is mounted.
164
+ // The server render and hydration show the text as plain blocks (headings,
165
+ // paragraphs with links, lists, quotes, pictures: blogArticleBlocks), so
166
+ // search engines read its structure; the sanitized HTML replaces them once
167
+ // the component is mounted.
161
168
  const mounted = ref(false);
162
- const paragraphs = computed(() => htmlTextParagraphs(articleSource.value));
169
+ const BlogArticleBlocks = defineComponent({
170
+ name: 'BlogArticleBlocks',
171
+ props: {
172
+ blocks: { type: Array as PropType<TBlogArticleBlock[]>, required: true },
173
+ },
174
+ setup(props) {
175
+ const inline = (parts: IBlogArticleInline[]) =>
176
+ parts.map((part) =>
177
+ part.href
178
+ ? h(
179
+ 'a',
180
+ part.external
181
+ ? { href: part.href, target: '_blank', rel: 'noopener noreferrer' }
182
+ : { href: part.href },
183
+ part.text,
184
+ )
185
+ : part.text,
186
+ );
187
+ const block = (item: TBlogArticleBlock): VNode => {
188
+ switch (item.kind) {
189
+ case 'heading':
190
+ return h(`h${item.level}`, inline(item.inline));
191
+ case 'list':
192
+ return h(
193
+ item.ordered ? 'ol' : 'ul',
194
+ item.items.map((entry) => h('li', inline(entry))),
195
+ );
196
+ case 'quote':
197
+ return h('blockquote', item.blocks.map(block));
198
+ case 'image':
199
+ return h('figure', [
200
+ h('img', {
201
+ src: item.src,
202
+ alt: item.alt,
203
+ width: item.width,
204
+ height: item.height,
205
+ loading: 'lazy',
206
+ decoding: 'async',
207
+ // Without the editor's size the box stays 3:2 until the formatted text replaces it.
208
+ style: item.width && item.height ? undefined : 'aspect-ratio: 3 / 2; object-fit: contain',
209
+ }),
210
+ ...(item.caption ? [h('figcaption', item.caption)] : []),
211
+ ]);
212
+ default:
213
+ return h('p', inline(item.inline));
214
+ }
215
+ };
216
+
217
+ return () => props.blocks.map(block);
218
+ },
219
+ });
220
+ const blocks = computed(() => blogArticleBlocks(articleSource.value, appOrigin));
163
221
  const cover = computed(() => {
164
222
  const images = [...(post.value?.preview_images ?? [])].sort(
165
223
  (left, right) => left.display_order - right.display_order,
@@ -433,12 +491,7 @@
433
491
  ref="article"
434
492
  class="op-feature-prose"
435
493
  >
436
- <p
437
- v-for="(paragraph, index) in paragraphs"
438
- :key="index"
439
- >
440
- {{ paragraph }}
441
- </p>
494
+ <BlogArticleBlocks :blocks="blocks" />
442
495
  </div>
443
496
  <template
444
497
  v-for="(placement, index) in placements"
@@ -880,6 +933,18 @@
880
933
  width: 100%;
881
934
  }
882
935
 
936
+ /* A YouTube player from the editor: the article's width, 16:9. */
937
+ .op-feature-prose :deep(iframe.blog-post-editor-youtube:where(:not([data-product-id] *, [data-product-ids] *))) {
938
+ display: block;
939
+ width: 100%;
940
+ height: auto;
941
+ margin: 1.5rem 0;
942
+ clear: both;
943
+ aspect-ratio: 16 / 9;
944
+ border: 0;
945
+ background: #000;
946
+ }
947
+
883
948
  .op-feature-prose :deep(figcaption:where(:not([data-product-id] *, [data-product-ids] *))) {
884
949
  margin-top: 0.5rem;
885
950
  font-size: 0.875rem;
@@ -4,7 +4,7 @@ import type {
4
4
  DOMPurify as TPurifier,
5
5
  UponSanitizeAttributeHookEvent,
6
6
  } from 'dompurify';
7
- import { htmlTextParagraphs } from '@/utils/basklee/htmlText';
7
+ import { decodeEntities, htmlTextParagraphs } from '@/utils/basklee/htmlText';
8
8
  import { appMediaUrl } from '@/utils/basklee/nativeApp';
9
9
 
10
10
  type TStylePatterns = Record<string, RegExp>;
@@ -14,8 +14,9 @@ type TStylePatterns = Record<string, RegExp>;
14
14
  * the backend, so the storefront sanitizes it before display. The allowlist
15
15
  * matches what that editor writes: text formatting, headings, lists and task
16
16
  * lists, quotes, code blocks, tables, images and galleries, videos,
17
- * collapsible sections, formulas and alignment, color and size styles.
18
- * The editor has no embedded frames, so iframes stay forbidden.
17
+ * collapsible sections, formulas and alignment, color and size styles,
18
+ * and YouTube players. A frame is kept only when its address is a YouTube
19
+ * embed (see blogYoutubeEmbedSource); every other frame is removed.
19
20
  */
20
21
 
21
22
  export const blogArticleTags = [
@@ -31,6 +32,7 @@ export const blogArticleTags = [
31
32
  'img', 'figure', 'figcaption',
32
33
  'video', 'audio', 'source', 'track',
33
34
  'details', 'summary',
35
+ 'iframe',
34
36
  ];
35
37
 
36
38
  const attributes = [
@@ -46,6 +48,7 @@ const attributes = [
46
48
  'data-code-scheme', 'data-gallery-width', 'data-list-offset',
47
49
  'data-float', 'data-blog-video', 'data-details-content',
48
50
  'data-product-id', 'data-product-ids', 'data-product-hidden-badges',
51
+ 'allow', 'allowfullscreen', 'referrerpolicy',
49
52
  ];
50
53
 
51
54
  const marginLength = '(-?\\d+(\\.\\d+)?(px|em|rem|%)?|auto)';
@@ -57,6 +60,7 @@ const editorClasses = new Set([
57
60
  'blog-code-block',
58
61
  'blog-post-editor-image',
59
62
  'blog-post-editor-video',
63
+ 'blog-post-editor-youtube',
60
64
  ]);
61
65
 
62
66
  // The editor's named text and background colors.
@@ -104,6 +108,53 @@ const editorArticlePath =
104
108
 
105
109
  const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
106
110
 
111
+ // A YouTube player the editor inserts: youtube.com or youtube-nocookie.com,
112
+ // /embed/ and an 11-character video ID, optionally a start second.
113
+ const youtubeEmbed =
114
+ /^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
115
+
116
+ export const blogYoutubeAllow =
117
+ 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
118
+
119
+ /**
120
+ * The privacy-enhanced player address for a YouTube embed address, or an
121
+ * empty string for anything else (other sites, other YouTube pages).
122
+ */
123
+ export function blogYoutubeEmbedSource(value: string) {
124
+ const match = youtubeEmbed.exec(value.trim());
125
+
126
+ if (!match) {
127
+ return '';
128
+ }
129
+
130
+ const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
131
+
132
+ return `https://www.youtube-nocookie.com/embed/${match[1]}${start && Number(start) > 0 ? `?start=${Number(start)}` : ''}`;
133
+ }
134
+
135
+ function prepareYoutubeFrame(node: Element) {
136
+ const source = blogYoutubeEmbedSource(node.getAttribute('src') ?? '');
137
+
138
+ if (!source) {
139
+ node.remove();
140
+ return;
141
+ }
142
+
143
+ const title = node.getAttribute('title')?.trim() || 'YouTube video';
144
+
145
+ for (const attribute of [...node.getAttributeNames()]) {
146
+ node.removeAttribute(attribute);
147
+ }
148
+
149
+ node.setAttribute('class', 'blog-post-editor-youtube');
150
+ node.setAttribute('src', source);
151
+ node.setAttribute('title', title);
152
+ node.setAttribute('allow', blogYoutubeAllow);
153
+ node.setAttribute('allowfullscreen', '');
154
+ node.setAttribute('loading', 'lazy');
155
+ node.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
156
+ }
157
+
107
158
  function normalizedHeadingText(value: string) {
108
159
  return htmlTextParagraphs(value)
109
160
  .join(' ')
@@ -230,6 +281,11 @@ let mediaOrigin = '';
230
281
  function prepareElement(node: Element) {
231
282
  const name = node.nodeName;
232
283
 
284
+ if (name === 'IFRAME') {
285
+ prepareYoutubeFrame(node);
286
+ return;
287
+ }
288
+
233
289
  if (name === 'A') {
234
290
  prepareLink(node);
235
291
  }
@@ -316,3 +372,269 @@ export function safeBlogArticleHtml(
316
372
  purifier.removeHook('afterSanitizeAttributes', prepareElementHook);
317
373
  }
318
374
  }
375
+
376
+ // Nuxt reads the storefront origin from the runtime config: BlogArticle passes it in.
377
+ const BLOCK_MEDIA_ORIGIN = '';
378
+
379
+ /*
380
+ * The server render (and the hydration that must match it) cannot run
381
+ * DOMPurify, so it shows the article as plain blocks built from the editor
382
+ * HTML: headings, paragraphs with their links, lists, quotes and pictures
383
+ * with captions. Nothing of the source markup is passed on: each block holds
384
+ * only text and checked addresses, and the component renders them with its
385
+ * own escaping. Search engines read the structure without scripts; the
386
+ * sanitized HTML replaces the blocks once the component is mounted.
387
+ */
388
+
389
+ export interface IBlogArticleInline {
390
+ text: string;
391
+ href?: string;
392
+ external?: boolean;
393
+ }
394
+
395
+ export type TBlogArticleBlock =
396
+ | { kind: 'heading'; level: 2 | 3 | 4; inline: IBlogArticleInline[] }
397
+ | { kind: 'paragraph'; inline: IBlogArticleInline[] }
398
+ | { kind: 'list'; ordered: boolean; items: IBlogArticleInline[][] }
399
+ | { kind: 'quote'; blocks: TBlogArticleBlock[] }
400
+ | { kind: 'image'; src: string; alt: string; caption: string; width?: number; height?: number };
401
+
402
+ const MAX_ARTICLE_BLOCKS = 600;
403
+
404
+ const skippedElements =
405
+ /<(script|style|template|iframe|noscript|svg|math|object|textarea|select|button|video|audio)\b[\s\S]*?<\/\1\s*>/gi;
406
+
407
+ function tagAttribute(attributes: string, name: string) {
408
+ const match = new RegExp(
409
+ `(?:^|\\s)${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`,
410
+ 'i',
411
+ ).exec(attributes);
412
+
413
+ return decodeEntities(match?.[1] ?? match?.[2] ?? match?.[3] ?? '').trim();
414
+ }
415
+
416
+ // The scheme is checked without the characters a browser drops from an
417
+ // address (`java\tscript:` would run as javascript:).
418
+ function addressScheme(value: string) {
419
+ return /^([a-z][a-z\d+.-]*):/i
420
+ .exec(value.replace(/[\u0000- \u007f-\u009f]/g, ''))?.[1]
421
+ ?.toLowerCase();
422
+ }
423
+
424
+ function blockLink(value: string): Omit<IBlogArticleInline, 'text'> | undefined {
425
+ const scheme = addressScheme(value);
426
+
427
+ if (!value || value.startsWith('//') || (scheme && !['http', 'https', 'mailto', 'tel'].includes(scheme))) {
428
+ return undefined;
429
+ }
430
+
431
+ const article = editorArticlePath.exec(value);
432
+
433
+ if (article) {
434
+ return { href: `/journal/${article[1]}` };
435
+ }
436
+
437
+ return scheme === 'http' || scheme === 'https'
438
+ ? { href: value, external: true }
439
+ : { href: value };
440
+ }
441
+
442
+ // The editor's own picture size, when it wrote one: the server render reserves
443
+ // that box; without it the component keeps a 3:2 box (the guide's screenshots).
444
+ function blockImageSize(attributes: string) {
445
+ const width = Number(tagAttribute(attributes, 'width'));
446
+ const height = Number(tagAttribute(attributes, 'height'));
447
+
448
+ return Number.isInteger(width) && Number.isInteger(height) &&
449
+ width > 0 && height > 0 && width <= 10000 && height <= 10000
450
+ ? { width, height }
451
+ : {};
452
+ }
453
+
454
+ function blockImage(value: string, appOrigin: string) {
455
+ const scheme = addressScheme(value);
456
+
457
+ if (scheme === 'http' || scheme === 'https') {
458
+ return value;
459
+ }
460
+
461
+ return !scheme && value.startsWith('/') && !value.startsWith('//')
462
+ ? appMediaUrl(value, appOrigin)
463
+ : '';
464
+ }
465
+
466
+ function blockImageSizeOf(figure: { width?: number; height?: number }) {
467
+ return figure.width && figure.height ? { width: figure.width, height: figure.height } : {};
468
+ }
469
+
470
+ /** The article as plain blocks for the server render and the hydration. */
471
+ export function blogArticleBlocks(
472
+ value: string | undefined,
473
+ appOrigin = BLOCK_MEDIA_ORIGIN,
474
+ ): TBlogArticleBlock[] {
475
+ const html = (value ?? '')
476
+ .replace(/<!--[\s\S]*?-->/g, ' ')
477
+ .replace(skippedElements, ' ');
478
+ const blocks: TBlogArticleBlock[] = [];
479
+ const quotes: TBlogArticleBlock[][] = [];
480
+ let inline: IBlogArticleInline[] = [];
481
+ let mode: 'heading' | 'paragraph' | 'item' | 'caption' = 'paragraph';
482
+ let level: 2 | 3 | 4 = 2;
483
+ let list: { ordered: boolean; items: IBlogArticleInline[][] } | undefined;
484
+ let link: Omit<IBlogArticleInline, 'text'> | undefined;
485
+ let figure: { src: string; alt: string; caption: string; width?: number; height?: number } | undefined;
486
+ let count = 0;
487
+
488
+ const target = () => quotes[quotes.length - 1] ?? blocks;
489
+ const push = (block: TBlogArticleBlock) => {
490
+ if (count < MAX_ARTICLE_BLOCKS) {
491
+ count += 1;
492
+ target().push(block);
493
+ }
494
+ };
495
+ const flush = () => {
496
+ const parts = inline
497
+ .map((part) => ({ ...part, text: part.text.replace(/\s+/g, ' ') }))
498
+ .filter((part) => part.text);
499
+
500
+ inline = [];
501
+ if (parts.length) {
502
+ parts[0]!.text = parts[0]!.text.trimStart();
503
+ parts[parts.length - 1]!.text = parts[parts.length - 1]!.text.trimEnd();
504
+ }
505
+ const kept = parts.filter((part) => part.text);
506
+
507
+ if (!kept.length) {
508
+ return;
509
+ }
510
+ if (mode === 'caption' && figure) {
511
+ figure.caption = `${figure.caption} ${kept.map((part) => part.text).join('')}`.trim();
512
+ } else if (list && mode === 'item') {
513
+ list.items.push(kept);
514
+ } else if (mode === 'heading') {
515
+ push({ kind: 'heading', level, inline: kept });
516
+ } else {
517
+ push({ kind: 'paragraph', inline: kept });
518
+ }
519
+ };
520
+ const closeList = () => {
521
+ if (list?.items.length) {
522
+ push({ kind: 'list', ordered: list.ordered, items: list.items });
523
+ }
524
+ list = undefined;
525
+ };
526
+ const closeFigure = () => {
527
+ if (figure?.src) {
528
+ push({ kind: 'image', src: figure.src, alt: figure.alt, caption: figure.caption, ...blockImageSizeOf(figure) });
529
+ }
530
+ figure = undefined;
531
+ };
532
+
533
+ for (const token of html.matchAll(/<(\/?)([a-z][a-z\d]*)\b([^>]*)>|([^<]+)/gi)) {
534
+ const [, closing, rawName, attributes = '', text] = token;
535
+
536
+ if (text !== undefined) {
537
+ const decoded = decodeEntities(text);
538
+ const last = inline[inline.length - 1];
539
+
540
+ if (last && last.href === link?.href) {
541
+ last.text += decoded;
542
+ } else {
543
+ inline.push({ text: decoded, ...(link ?? {}) });
544
+ }
545
+ continue;
546
+ }
547
+
548
+ const name = rawName!.toLowerCase();
549
+
550
+ if (closing) {
551
+ if (/^(?:h[1-6]|p|div|pre|tr|summary|li|figcaption|dt|dd)$/.test(name)) {
552
+ flush();
553
+ mode = list ? 'item' : 'paragraph';
554
+ } else if (name === 'ul' || name === 'ol') {
555
+ flush();
556
+ closeList();
557
+ mode = 'paragraph';
558
+ } else if (name === 'blockquote') {
559
+ flush();
560
+ closeList();
561
+ const quoted = quotes.pop();
562
+
563
+ if (quoted?.length) {
564
+ push({ kind: 'quote', blocks: quoted });
565
+ }
566
+ } else if (name === 'figure') {
567
+ flush();
568
+ closeFigure();
569
+ mode = 'paragraph';
570
+ } else if (name === 'a') {
571
+ link = undefined;
572
+ }
573
+ continue;
574
+ }
575
+
576
+ if (/^h[1-6]$/.test(name)) {
577
+ flush();
578
+ mode = 'heading';
579
+ level = Math.min(4, Math.max(2, Number(name[1]))) as 2 | 3 | 4;
580
+ } else if (/^(?:p|div|pre|tr|summary|section|article|details|dt|dd)$/.test(name)) {
581
+ flush();
582
+ mode = list ? 'item' : 'paragraph';
583
+ } else if (name === 'ul' || name === 'ol') {
584
+ flush();
585
+ if (!list) {
586
+ list = { ordered: name === 'ol', items: [] };
587
+ }
588
+ mode = 'item';
589
+ } else if (name === 'li') {
590
+ flush();
591
+ mode = 'item';
592
+ } else if (name === 'blockquote') {
593
+ flush();
594
+ closeList();
595
+ if (quotes.length < 3) {
596
+ quotes.push([]);
597
+ }
598
+ mode = 'paragraph';
599
+ } else if (name === 'figure') {
600
+ flush();
601
+ closeFigure();
602
+ figure = { src: '', alt: '', caption: '' };
603
+ } else if (name === 'figcaption') {
604
+ flush();
605
+ mode = 'caption';
606
+ } else if (name === 'img') {
607
+ const src = blockImage(tagAttribute(attributes, 'src'), appOrigin);
608
+ const alt = tagAttribute(attributes, 'alt');
609
+
610
+ if (!src) {
611
+ continue;
612
+ }
613
+ if (figure && !figure.src) {
614
+ Object.assign(figure, { src, alt, ...blockImageSize(attributes) });
615
+ } else {
616
+ flush();
617
+ push({ kind: 'image', src, alt, caption: '', ...blockImageSize(attributes) });
618
+ }
619
+ } else if (name === 'a') {
620
+ link = blockLink(tagAttribute(attributes, 'href'));
621
+ } else if (name === 'br' || name === 'td' || name === 'th') {
622
+ inline.push({ text: ' ', ...(link ?? {}) });
623
+ } else if (name === 'hr') {
624
+ flush();
625
+ }
626
+ }
627
+
628
+ flush();
629
+ closeList();
630
+ closeFigure();
631
+ while (quotes.length) {
632
+ const quoted = quotes.pop();
633
+
634
+ if (quoted?.length) {
635
+ push({ kind: 'quote', blocks: quoted });
636
+ }
637
+ }
638
+
639
+ return blocks;
640
+ }
@@ -20,7 +20,7 @@ const namedEntities: Record<string, string> = {
20
20
  hellip: '…',
21
21
  };
22
22
 
23
- function decodeEntities(value: string) {
23
+ export function decodeEntities(value: string) {
24
24
  return value.replace(
25
25
  /&(#x[0-9a-f]+|#\d+|[a-z]+);/gi,
26
26
  (entity, name: string) => {