Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(guides): add the single-line title rules

davbio5b840e7ff841
diff --git a/src/core/guides/__tests__/title.test.ts b/src/core/guides/__tests__/title.test.ts
new file mode 100644
index 0000000..fa621c5
--- /dev/null
+++ b/src/core/guides/__tests__/title.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from 'vitest';
+import { MAX_TITLE_LENGTH, sanitizeGuideTitle, stripTitleLineBreaks } from '../title';
+
+describe('sanitizeGuideTitle', () => {
+ it('collapses a hard line break into a single space', () => {
+ expect(sanitizeGuideTitle('Set up\nyour profile')).toBe('Set up your profile');
+ });
+
+ it('handles CRLF and runs of blank lines', () => {
+ expect(sanitizeGuideTitle('Set up\r\n\r\n your profile')).toBe('Set up your profile');
+ });
+
+ it('trims leading and trailing whitespace', () => {
+ expect(sanitizeGuideTitle(' Set up your profile \n')).toBe('Set up your profile');
+ });
+
+ it('leaves an already single-line title untouched', () => {
+ expect(sanitizeGuideTitle('Set up your profile')).toBe('Set up your profile');
+ });
+
+ it('does not truncate, so existing long titles survive a re-save', () => {
+ const long = 'a'.repeat(MAX_TITLE_LENGTH * 2);
+ expect(sanitizeGuideTitle(long)).toBe(long);
+ });
+});
+
+describe('stripTitleLineBreaks', () => {
+ it('removes line breaks while leaving other whitespace alone mid-edit', () => {
+ expect(stripTitleLineBreaks('Set up\nyour profile ')).toBe('Set up your profile ');
+ });
+});
diff --git a/src/core/guides/title.ts b/src/core/guides/title.ts
new file mode 100644
index 0000000..e1b1a8d
--- /dev/null
+++ b/src/core/guides/title.ts
@@ -0,0 +1,12 @@
+export const MAX_TITLE_LENGTH = 70;
+
+const ASCII_WHITESPACE = /[\t\n\r\f\v ]+/g;
+const LINE_BREAKS = /[\r\n]+/g;
+
+export function sanitizeGuideTitle(title: string): string {
+ return title.replace(ASCII_WHITESPACE, ' ').trim();
+}
+
+export function stripTitleLineBreaks(title: string): string {
+ return title.replace(LINE_BREAKS, ' ');
+}