inlaycms 0.3.0 → 0.4.0

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.
@@ -320,6 +320,7 @@ function toolbarLabels(headings) {
320
320
  ...Object.fromEntries(headings.map((level) => [`heading${level}`, t('admin.richtext.heading', { level })])),
321
321
  bold: t('admin.richtext.bold'),
322
322
  italic: t('admin.richtext.italic'),
323
+ code: t('admin.richtext.code'),
323
324
  link: t('admin.richtext.link'),
324
325
  bulletList: t('admin.richtext.bulletList'),
325
326
  orderedList: t('admin.richtext.orderedList'),
@@ -341,7 +342,7 @@ function renderRichText(p, inline) {
341
342
  const features = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature));
342
343
  const value = p.value === undefined ? '' : typeof p.value === 'string' ? p.value : JSON.stringify(p.value);
343
344
  const links = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale, web: '1' }).toString()}`;
344
- return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-inline": inline, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: `${inline ? INLINE_TEXT_MOUNT : RICH_TEXT_MOUNT} [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_table]:my-2 [&_table]:border-collapse [&_th]:border [&_th]:border-base-300 [&_th]:px-2 [&_th]:text-left [&_th]:font-semibold [&_td]:border [&_td]:border-base-300 [&_td]:px-2 [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary` }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
345
+ return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-inline": inline, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: `${inline ? INLINE_TEXT_MOUNT : RICH_TEXT_MOUNT} [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_code]:rounded [&_code]:bg-base-200 [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.9em] [&_table]:my-2 [&_table]:border-collapse [&_th]:border [&_th]:border-base-300 [&_th]:px-2 [&_th]:text-left [&_th]:font-semibold [&_td]:border [&_td]:border-base-300 [&_td]:px-2 [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary` }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
345
346
  }
346
347
  function parseRichTextForm(form, name, optional, parse) {
347
348
  const raw = form.get(name);
@@ -72,8 +72,8 @@ export async function inspectUpload(deps, bytes, filename) {
72
72
  const meta = await sharp(bytes).metadata();
73
73
  if (!meta.width || !meta.height)
74
74
  throw new Error('no size');
75
- // Force a full decode so truncated files are caught.
76
- await sharp(bytes).rotate().toBuffer();
75
+ // Force a full decode so truncated files are caught. One raw channel: no encoding, little memory.
76
+ await sharp(bytes).extractChannel(0).raw().toBuffer();
77
77
  const swap = (meta.orientation ?? 1) >= 5;
78
78
  width = swap ? meta.height : meta.width;
79
79
  height = swap ? meta.width : meta.height;
@@ -434,7 +434,8 @@ export declare const en: {
434
434
  readonly 'richtext.headingLevel': "Line {line}: this field can't contain a level {level} heading (one with {level} # signs). Use one of these levels instead: {levels}.";
435
435
  readonly 'richtext.headingContent': "Line {line}: headings can't contain {feature}. Move it to a paragraph below the heading.";
436
436
  readonly 'richtext.tableNested': "Line {line}: tables can't go inside a list or a quote. Move the table out so it stands on its own.";
437
- readonly 'richtext.tableCell': "Line {line}: table cells can't contain {feature}. Keep each cell to text, bold, italic and links.";
437
+ readonly 'richtext.tableCell': "Line {line}: table cells can't contain {feature}. Keep each cell to text, bold, italic, code and links.";
438
+ readonly 'richtext.codeEmphasis': "Line {line}: code can't be bold or italic. Move the code (the text between backticks) out of the bold or italic text.";
438
439
  readonly 'richtext.imageSource': 'Line {line}: images must come from the media library, not from another address ("{src}"). Upload the image to the media library and use that instead.';
439
440
  readonly 'richtext.linkUrl': 'Line {line}: the link address "{href}" can\'t be used. Links must start with https://, http://, mailto:, tel: or /, or point to a page of this site.';
440
441
  readonly 'richtext.title': "Line {line}: {feature} can't have a title (the text in quotes after the address). Remove the title.";
@@ -1057,6 +1058,7 @@ export declare const en: {
1057
1058
  readonly 'admin.richtext.heading': 'Heading {level}';
1058
1059
  readonly 'admin.richtext.bold': 'Bold';
1059
1060
  readonly 'admin.richtext.italic': 'Italic';
1061
+ readonly 'admin.richtext.code': 'Code';
1060
1062
  readonly 'admin.richtext.link': 'Link';
1061
1063
  readonly 'admin.richtext.bulletList': 'Bulleted list';
1062
1064
  readonly 'admin.richtext.orderedList': 'Numbered list';
@@ -434,7 +434,8 @@ export const en = {
434
434
  'richtext.headingLevel': "Line {line}: this field can't contain a level {level} heading (one with {level} # signs). Use one of these levels instead: {levels}.",
435
435
  'richtext.headingContent': "Line {line}: headings can't contain {feature}. Move it to a paragraph below the heading.",
436
436
  'richtext.tableNested': "Line {line}: tables can't go inside a list or a quote. Move the table out so it stands on its own.",
437
- 'richtext.tableCell': "Line {line}: table cells can't contain {feature}. Keep each cell to text, bold, italic and links.",
437
+ 'richtext.tableCell': "Line {line}: table cells can't contain {feature}. Keep each cell to text, bold, italic, code and links.",
438
+ 'richtext.codeEmphasis': "Line {line}: code can't be bold or italic. Move the code (the text between backticks) out of the bold or italic text.",
438
439
  'richtext.imageSource': 'Line {line}: images must come from the media library, not from another address ("{src}"). Upload the image to the media library and use that instead.',
439
440
  'richtext.linkUrl': 'Line {line}: the link address "{href}" can\'t be used. Links must start with https://, http://, mailto:, tel: or /, or point to a page of this site.',
440
441
  'richtext.title': "Line {line}: {feature} can't have a title (the text in quotes after the address). Remove the title.",
@@ -1057,6 +1058,7 @@ export const en = {
1057
1058
  'admin.richtext.heading': 'Heading {level}',
1058
1059
  'admin.richtext.bold': 'Bold',
1059
1060
  'admin.richtext.italic': 'Italic',
1061
+ 'admin.richtext.code': 'Code',
1060
1062
  'admin.richtext.link': 'Link',
1061
1063
  'admin.richtext.bulletList': 'Bulleted list',
1062
1064
  'admin.richtext.orderedList': 'Numbered list',
@@ -11,6 +11,8 @@ function marksOf(marks, resolve) {
11
11
  out.push({ key: 'b', open: '<strong>', close: '</strong>' });
12
12
  else if (mark.type === 'italic')
13
13
  out.push({ key: 'i', open: '<em>', close: '</em>' });
14
+ else if (mark.type === 'code')
15
+ out.push({ key: 'c', open: '<code>', close: '</code>' });
14
16
  else {
15
17
  const href = 'href' in mark.attrs ? mark.attrs.href : resolve.link(mark.attrs.document);
16
18
  if (href === null || ('href' in mark.attrs && !isRichTextHref(href)))
@@ -1,7 +1,7 @@
1
1
  import { type RichTextResolver } from './html.js';
2
2
  import { type RichTextProblem } from './markdown.js';
3
3
  import { type RichTextDoc, type RichTextOptions } from './schema.js';
4
- /** What an inline-text field allows: one paragraph of bold, italic and linked text. */
4
+ /** What an inline-text field allows: one paragraph of bold, italic, code and linked text. */
5
5
  export declare const INLINE_TEXT: RichTextOptions;
6
6
  /** `value` as a normalized inline-text doc: at most one block, and that a paragraph. */
7
7
  export declare function parseInlineText(value: unknown): {
@@ -2,8 +2,8 @@ import { t } from '../messages/index.js';
2
2
  import { richTextInlineHtml } from './html.js';
3
3
  import { blockLines, markdownToRichText } from './markdown.js';
4
4
  import { parseRichText } from './schema.js';
5
- /** What an inline-text field allows: one paragraph of bold, italic and linked text. */
6
- export const INLINE_TEXT = { features: ['bold', 'italic', 'link'], headings: [] };
5
+ /** What an inline-text field allows: one paragraph of bold, italic, code and linked text. */
6
+ export const INLINE_TEXT = { features: ['bold', 'italic', 'code', 'link'], headings: [] };
7
7
  /** `value` as a normalized inline-text doc: at most one block, and that a paragraph. */
8
8
  export function parseInlineText(value) {
9
9
  const parsed = parseRichText(value, INLINE_TEXT);
@@ -4,7 +4,10 @@ export interface RichTextProblem {
4
4
  line: number;
5
5
  message: string;
6
6
  }
7
- /** URL as a link destination: `<…>` when it has spaces or brackets, escaped so markdown-it gives it back unchanged. */
7
+ /**
8
+ * URL as a link destination: `<…>` when it has spaces or brackets, escaped so markdown-it gives it back unchanged.
9
+ * Stand-in characters are written as character references, so they can't be taken for formatting.
10
+ */
8
11
  export declare function markdownDestination(url: string): string;
9
12
  /** The doc as CommonMark: tight lists, `- ` bullets, `inlay:` URIs for internal links and images. */
10
13
  export declare function richTextToMarkdown(doc: RichTextDoc): string;
@@ -16,7 +16,9 @@ const OPEN_BOLD = '\uE000';
16
16
  const CLOSE_BOLD = '\uE001';
17
17
  const OPEN_ITALIC = '\uE002';
18
18
  const CLOSE_ITALIC = '\uE003';
19
- const STAND_INS = /[\uE000-\uE003]/g;
19
+ /** Stands in for a code span while a block's bold and italic are placed, so they never touch its text. */
20
+ const CODE = '\uE004';
21
+ const STAND_INS = /[\uE000-\uE004]/g;
20
22
  const STAND_IN = {
21
23
  [OPEN_BOLD]: { count: 2, open: true },
22
24
  [CLOSE_BOLD]: { count: 2, open: false },
@@ -70,12 +72,27 @@ function atLineStart(out) {
70
72
  }
71
73
  /** Characters as numeric character references, which read back as themselves. */
72
74
  const encodeChars = (s) => Array.from(s, (c) => `&#${c.codePointAt(0)};`).join('');
73
- /** URL as a link destination: `<…>` when it has spaces or brackets, escaped so markdown-it gives it back unchanged. */
75
+ /**
76
+ * URL as a link destination: `<…>` when it has spaces or brackets, escaped so markdown-it gives it back unchanged.
77
+ * Stand-in characters are written as character references, so they can't be taken for formatting.
78
+ */
74
79
  export function markdownDestination(url) {
75
80
  const entity = /&(?=#?[0-9A-Za-z]+;)/g;
76
81
  if (/[\s()<>]/.test(url))
77
- return '<' + url.replace(/[\\<>]/g, '\\$&').replace(entity, '\\&') + '>';
78
- return url.replace(/\\/g, '\\\\').replace(entity, '\\&');
82
+ return '<' + url.replace(/[\\<>]/g, '\\$&').replace(entity, '\\&').replace(STAND_INS, encodeChars) + '>';
83
+ return url.replace(/\\/g, '\\\\').replace(entity, '\\&').replace(STAND_INS, encodeChars);
84
+ }
85
+ /**
86
+ * Text as a CommonMark code span: fenced by one more backtick than its longest run of them, and padded with a space
87
+ * on each side where reading it back would otherwise take a backtick for the fence or trim a space.
88
+ */
89
+ function codeSpan(text) {
90
+ let longest = 0;
91
+ for (const run of text.match(/`+/g) ?? [])
92
+ longest = Math.max(longest, run.length);
93
+ const fence = '`'.repeat(longest + 1);
94
+ const pad = text.startsWith('`') || text.endsWith('`') || (text.startsWith(' ') && text.endsWith(' ') && /[^ ]/.test(text));
95
+ return pad ? `${fence} ${text} ${fence}` : fence + text + fence;
79
96
  }
80
97
  /** Text with each line break, and the whitespace around it, turned into one space. */
81
98
  function oneLine(s) {
@@ -183,6 +200,8 @@ class State extends StateBase {
183
200
  lastContent = new WeakMap();
184
201
  /** Finished lines, moved out of `out` so that rewriting a block's text stays cheap. */
185
202
  done = [];
203
+ /** The code spans written as `CODE` in the block being written, in order. */
204
+ codes = [];
186
205
  /** Moves every finished line out of `out`; what is still being written stays. */
187
206
  commitLines() {
188
207
  const end = this.out.lastIndexOf('\n') + 1;
@@ -300,7 +319,8 @@ function tidyInvisible(node) {
300
319
  function charKind(piece) {
301
320
  if (piece === undefined)
302
321
  return 'space';
303
- if ('delim' in piece)
322
+ // A code span starts and ends with a backtick.
323
+ if ('delim' in piece || piece.text === CODE)
304
324
  return 'punct';
305
325
  const { isWhiteSpace, isMdAsciiPunct, isPunctCharCode } = tokenizer.utils;
306
326
  const code = piece.text.codePointAt(0) ?? 0x20;
@@ -504,7 +524,9 @@ function renderTextblock(state, node, fromBlockStart) {
504
524
  state.commitLines();
505
525
  const start = state.out.length;
506
526
  state.renderInline(writing.emphasis === 'none' ? withoutEmphasis(writing.node) : tidyInvisible(writing.node), fromBlockStart);
507
- const written = placeDelimiters(state.out.slice(start), writing.emphasis === 'strict');
527
+ const codes = state.codes;
528
+ state.codes = [];
529
+ const written = placeDelimiters(state.out.slice(start), writing.emphasis === 'strict').replace(/\uE004/g, () => codes.shift() ?? '');
508
530
  const kept = written.trimEnd();
509
531
  state.out = state.out.slice(0, start) + kept + encodeChars(written.slice(kept.length));
510
532
  }
@@ -636,6 +658,12 @@ const nodes = {
636
658
  state.write('\\\n');
637
659
  },
638
660
  text(state, node, parent, index) {
661
+ if (node.marks.some((m) => m.type.name === 'code')) {
662
+ state.codes.push(codeSpan(node.text ?? ''));
663
+ state.write();
664
+ state.append(CODE);
665
+ return;
666
+ }
639
667
  // A `!` right before a link would make it an image. prosemirror-markdown checks for
640
668
  // this, but rewrites the whole output each time and misreads `\\!`, so it is escaped here.
641
669
  const text = node.text ?? '';
@@ -662,6 +690,8 @@ const marks = {
662
690
  },
663
691
  bold: { open: OPEN_BOLD, close: CLOSE_BOLD, mixable: true, expelEnclosingWhitespace: true },
664
692
  italic: { open: OPEN_ITALIC, close: CLOSE_ITALIC, mixable: true, expelEnclosingWhitespace: true },
693
+ // Written by the text serializer, which sees the whole text the mark is on.
694
+ code: { open: '', close: '' },
665
695
  };
666
696
  /** The doc as CommonMark: tight lists, `- ` bullets, `inlay:` URIs for internal links and images. */
667
697
  export function richTextToMarkdown(doc) {
@@ -807,6 +837,7 @@ const parser = new MarkdownParser(richTextSchema, tokenizer, {
807
837
  td: { block: 'tableCell' },
808
838
  em: { mark: 'italic' },
809
839
  strong: { mark: 'bold' },
840
+ code_inline: { mark: 'code', noCloseToken: true },
810
841
  link: {
811
842
  mark: 'link',
812
843
  getAttrs: (tok) => {
@@ -840,13 +871,13 @@ const TOKEN_FEATURE = {
840
871
  blockquote_open: 'blockquote',
841
872
  strong_open: 'bold',
842
873
  em_open: 'italic',
874
+ code_inline: 'code',
843
875
  link_open: 'link',
844
876
  image: 'image',
845
877
  hardbreak: 'hardBreak',
846
878
  table_open: 'table',
847
879
  };
848
880
  const TOKEN_UNSUPPORTED = {
849
- code_inline: 'code',
850
881
  code_block: 'codeBlock',
851
882
  fence: 'codeBlock',
852
883
  hr: 'rule',
@@ -967,11 +998,22 @@ function findProblems(tokens, opts, env) {
967
998
  add('image_source', line, 'richtext.imageSource', { src });
968
999
  }
969
1000
  };
970
- /** Walks inline tokens; line breaks move the line on, including those inside an image's alt. */
1001
+ /**
1002
+ * Walks inline tokens; line breaks move the line on, including those inside an image's alt. Code inside bold or
1003
+ * italic is refused, since rich text can't hold both on the same text.
1004
+ */
971
1005
  const walkInline = (children, line, inHeading, inCell, inAlt) => {
1006
+ let emphasis = 0;
972
1007
  for (const child of children) {
973
1008
  if (!inAlt)
974
1009
  check(child, line, inHeading, inCell);
1010
+ if (child.type === 'strong_open' || child.type === 'em_open')
1011
+ emphasis++;
1012
+ if (child.type === 'strong_close' || child.type === 'em_close')
1013
+ emphasis--;
1014
+ if (!inAlt && child.type === 'code_inline' && emphasis > 0 && allowed('code')) {
1015
+ add('unsupported', line, 'richtext.codeEmphasis', {});
1016
+ }
975
1017
  if (child.type === 'softbreak' || child.type === 'hardbreak')
976
1018
  line++;
977
1019
  if (child.type === 'image' && child.children)
@@ -1,6 +1,6 @@
1
1
  import { Schema } from 'prosemirror-model';
2
2
  import type { ContentRef } from '../types.js';
3
- export declare const RICH_TEXT_FEATURES: readonly ['heading', 'bold', 'italic', 'link', 'bulletList', 'orderedList', 'blockquote', 'image', 'hardBreak', 'table'];
3
+ export declare const RICH_TEXT_FEATURES: readonly ['heading', 'bold', 'italic', 'code', 'link', 'bulletList', 'orderedList', 'blockquote', 'image', 'hardBreak', 'table'];
4
4
  export type RichTextFeature = (typeof RICH_TEXT_FEATURES)[number];
5
5
  export interface RichTextOptions {
6
6
  features: readonly RichTextFeature[];
@@ -18,6 +18,8 @@ export type RichTextMark = {
18
18
  type: 'bold';
19
19
  } | {
20
20
  type: 'italic';
21
+ } | {
22
+ type: 'code';
21
23
  };
22
24
  export type RichTextText = {
23
25
  type: 'text';
@@ -85,8 +87,11 @@ export type RichTextDoc = {
85
87
  type: 'doc';
86
88
  content: RichTextNode[];
87
89
  };
88
- /** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
89
- export declare const richTextSchema: Schema<"blockquote" | "bulletList" | "doc" | "hardBreak" | "heading" | "image" | "listItem" | "orderedList" | "paragraph" | "table" | "tableCell" | "tableHeader" | "tableRow" | "text", "bold" | "italic" | "link">;
90
+ /**
91
+ * Tiptap's node and mark names. The mark order is the canonical order of marks on a node. Code comes last, inside a
92
+ * link, and never with bold or italic: Markdown can't put either inside a code span.
93
+ */
94
+ export declare const richTextSchema: Schema<"blockquote" | "bulletList" | "doc" | "hardBreak" | "heading" | "image" | "listItem" | "orderedList" | "paragraph" | "table" | "tableCell" | "tableHeader" | "tableRow" | "text", "bold" | "code" | "italic" | "link">;
90
95
  /**
91
96
  * A link address rich text can hold: a safe URL without control characters, which
92
97
  * Markdown can't carry and so wouldn't read back.
@@ -6,6 +6,7 @@ export const RICH_TEXT_FEATURES = [
6
6
  'heading',
7
7
  'bold',
8
8
  'italic',
9
+ 'code',
9
10
  'link',
10
11
  'bulletList',
11
12
  'orderedList',
@@ -15,7 +16,10 @@ export const RICH_TEXT_FEATURES = [
15
16
  'table',
16
17
  ];
17
18
  export const DEFAULT_RICH_TEXT = { features: RICH_TEXT_FEATURES, headings: [2, 3, 4] };
18
- /** Tiptap's node and mark names. The mark order is the canonical order of marks on a node. */
19
+ /**
20
+ * Tiptap's node and mark names. The mark order is the canonical order of marks on a node. Code comes last, inside a
21
+ * link, and never with bold or italic: Markdown can't put either inside a code span.
22
+ */
19
23
  export const richTextSchema = new Schema({
20
24
  nodes: {
21
25
  doc: { content: 'block*' },
@@ -37,6 +41,7 @@ export const richTextSchema = new Schema({
37
41
  link: { attrs: { href: { default: null }, document: { default: null } }, inclusive: false },
38
42
  bold: {},
39
43
  italic: {},
44
+ code: { excludes: 'bold italic code' },
40
45
  },
41
46
  });
42
47
  const NODE_FEATURE = {
@@ -132,8 +137,10 @@ function cleanNode(raw, opts) {
132
137
  if (!absent(raw.marks)) {
133
138
  if (!Array.isArray(raw.marks))
134
139
  reject();
135
- if (raw.marks.length > 0)
136
- out.marks = raw.marks.map((m) => cleanMark(m, opts));
140
+ // Code shows only on text: a line break or an image would lose it in Markdown.
141
+ const marks = raw.marks.map((m) => cleanMark(m, opts)).filter((m) => type === 'text' || m.type !== 'code');
142
+ if (marks.length > 0)
143
+ out.marks = marks;
137
144
  }
138
145
  if (type === 'text') {
139
146
  if (typeof raw.text !== 'string')
package/dist/host/app.js CHANGED
@@ -34,7 +34,8 @@ export function sourceFromConfig(loaded) {
34
34
  * (what `diff` gives) to requests that didn't come through the proxy.
35
35
  */
36
36
  export async function createSiteApp(config, source, opts) {
37
- const app = Fastify({ logger: opts.logger ?? false, trustProxy: config.trustProxy });
37
+ // No plugin timeout: the site plugin boots the site (migrations, shipped content), which takes as long as it takes.
38
+ const app = Fastify({ logger: opts.logger ?? false, trustProxy: config.trustProxy, pluginTimeout: 0 });
38
39
  const now = opts.now ?? (() => new Date());
39
40
  // Opened once the site has booted (which creates and migrates the database), for the push API, admin and proxy.
40
41
  let db = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inlaycms",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "A code-first CMS for content sites: templates, schemas and content in code, one SQLite file, signed releases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -83,6 +83,7 @@
83
83
  "@tiptap/core": "^3.32.2",
84
84
  "@tiptap/extension-blockquote": "^3.32.2",
85
85
  "@tiptap/extension-bold": "^3.32.2",
86
+ "@tiptap/extension-code": "^3.32.2",
86
87
  "@tiptap/extension-document": "^3.32.2",
87
88
  "@tiptap/extension-hard-break": "^3.32.2",
88
89
  "@tiptap/extension-heading": "^3.32.2",