feat(admin): colour picker, mail image field and the image picker with insert
- insertImage escapes markdown/html/css/text snippets per UI-SPEC C4 - MailImagePicker with canUpload-gated upload, radiogroup tiles, insert/choose modes - ColorPickerField, MailImageField, markdown/codeeditor Insert image wiring Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,7 +1,34 @@
|
||||
// Stub for TDD RED (35-03 Task 5): real escaping lands in GREEN.
|
||||
// Pure snippet builder for mail image insertion (UI-SPEC C4, D-19/D-20).
|
||||
// The SPA never builds image URLs; callers pass the absolute URL the server returned.
|
||||
export type InsertImageLanguage = 'markdown' | 'html' | 'css' | 'text'
|
||||
|
||||
/** Builds the snippet inserted into a mail body or code editor. */
|
||||
export function insertImage(_language: InsertImageLanguage, _url: string, _alt: string): string {
|
||||
return ''
|
||||
function escapeMarkdownAlt(alt: string): string {
|
||||
return alt.replace(/\\/g, '\\\\').replace(/\[/g, '\\[').replace(/\]/g, '\\]')
|
||||
}
|
||||
|
||||
/** Percent-encode spaces and parentheses in Markdown URLs (research Pitfall 4). */
|
||||
function encodeMarkdownUrl(url: string): string {
|
||||
return url.replace(/[ ()]/g, (ch) => encodeURIComponent(ch))
|
||||
}
|
||||
|
||||
function escapeHtmlAttr(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
}
|
||||
|
||||
/** Builds the snippet inserted into a mail body or code editor. */
|
||||
export function insertImage(language: InsertImageLanguage, url: string, alt: string): string {
|
||||
switch (language) {
|
||||
case 'markdown':
|
||||
return `})`
|
||||
case 'html':
|
||||
return `<img src="${escapeHtmlAttr(url)}" alt="${escapeHtmlAttr(alt)}">`
|
||||
case 'css':
|
||||
return `url("${url.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}")`
|
||||
case 'text':
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user