wyreframe 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.
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +132 -0
- package/src/parser/Fixer/FixTypes.mjs +2 -0
- package/src/parser/Fixer/FixTypes.res +34 -0
- package/src/parser/Fixer/Fixer.gen.tsx +24 -0
- package/src/parser/Fixer/Fixer.mjs +447 -0
- package/src/parser/Fixer/Fixer.res +567 -0
package/dist/index.d.ts
CHANGED
|
@@ -157,6 +157,27 @@ export type CreateUIErrorResult = {
|
|
|
157
157
|
errors: ParseError[];
|
|
158
158
|
};
|
|
159
159
|
export type CreateUIResult = CreateUISuccessResult | CreateUIErrorResult;
|
|
160
|
+
/** Describes a single fix that was applied */
|
|
161
|
+
export interface FixedIssue {
|
|
162
|
+
original: ParseError;
|
|
163
|
+
description: string;
|
|
164
|
+
line: number;
|
|
165
|
+
column: number;
|
|
166
|
+
}
|
|
167
|
+
/** Successful fix result */
|
|
168
|
+
export type FixSuccessResult = {
|
|
169
|
+
success: true;
|
|
170
|
+
text: string;
|
|
171
|
+
fixed: FixedIssue[];
|
|
172
|
+
remaining: ParseError[];
|
|
173
|
+
};
|
|
174
|
+
/** Failed fix result */
|
|
175
|
+
export type FixErrorResult = {
|
|
176
|
+
success: false;
|
|
177
|
+
errors: ParseError[];
|
|
178
|
+
};
|
|
179
|
+
/** Result of fix operation */
|
|
180
|
+
export type FixResult = FixSuccessResult | FixErrorResult;
|
|
160
181
|
/**
|
|
161
182
|
* Parse mixed text containing wireframe and interactions.
|
|
162
183
|
*
|
|
@@ -261,6 +282,48 @@ export declare function createUI(text: string, options?: RenderOptions): CreateU
|
|
|
261
282
|
export declare function createUIOrThrow(text: string, options?: RenderOptions): RenderResult & {
|
|
262
283
|
ast: AST;
|
|
263
284
|
};
|
|
285
|
+
/**
|
|
286
|
+
* Attempt to auto-fix errors and warnings in the wireframe text.
|
|
287
|
+
*
|
|
288
|
+
* This function analyzes the text for common issues and automatically
|
|
289
|
+
* corrects them where possible. Fixable issues include:
|
|
290
|
+
* - MisalignedPipe: Adjusts pipe positions to correct columns
|
|
291
|
+
* - MisalignedClosingBorder: Fixes closing border alignment
|
|
292
|
+
* - UnusualSpacing: Replaces tabs with spaces
|
|
293
|
+
* - UnclosedBracket: Adds missing closing brackets
|
|
294
|
+
* - MismatchedWidth: Extends shorter borders to match
|
|
295
|
+
*
|
|
296
|
+
* @param text - The wireframe markdown text
|
|
297
|
+
* @returns Fix result with fixed text and details about applied fixes
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const result = fix(text);
|
|
302
|
+
* if (result.success) {
|
|
303
|
+
* console.log(`Fixed ${result.fixed.length} issues`);
|
|
304
|
+
* if (result.remaining.length > 0) {
|
|
305
|
+
* console.warn('Some issues require manual fix:', result.remaining);
|
|
306
|
+
* }
|
|
307
|
+
* // Use the fixed text
|
|
308
|
+
* const parsed = parse(result.text);
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
export declare function fix(text: string): FixResult;
|
|
313
|
+
/**
|
|
314
|
+
* Convenience function - fix and return just the fixed text.
|
|
315
|
+
* Returns the original text if nothing was fixed or if fixing failed.
|
|
316
|
+
*
|
|
317
|
+
* @param text - The wireframe markdown text
|
|
318
|
+
* @returns The fixed text (or original if no fixes applied)
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const fixedText = fixOnly(rawMarkdown);
|
|
323
|
+
* const result = parse(fixedText);
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
export declare function fixOnly(text: string): string;
|
|
264
327
|
export declare const version: string;
|
|
265
328
|
export declare const implementation: string;
|
|
266
329
|
declare const _default: {
|
|
@@ -271,6 +334,8 @@ declare const _default: {
|
|
|
271
334
|
render: typeof render;
|
|
272
335
|
createUI: typeof createUI;
|
|
273
336
|
createUIOrThrow: typeof createUIOrThrow;
|
|
337
|
+
fix: typeof fix;
|
|
338
|
+
fixOnly: typeof fixOnly;
|
|
274
339
|
version: string;
|
|
275
340
|
implementation: string;
|
|
276
341
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,wCAAwC;AACxC,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,kBAAkB,GAClB,QAAQ,GACR,kBAAkB,CAAC;AAEvB,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC;AAE5E,qBAAqB;AACrB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEpD,4BAA4B;AAC5B,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAE9D,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC;AAEhC,uBAAuB;AACvB,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,KAAK,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,QAAQ,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;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AAGD,eAAO,MAAM,OAAO,EAAE,MAAuB,CAAC;AAC9C,eAAO,MAAM,cAAc,EAAE,MAA8B,CAAC;;;;;;;;;;;;;;AAG5D,wBAYE"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
import * as Parser from '../src/parser/Parser.mjs';
|
|
11
11
|
// @ts-ignore - ReScript generated module
|
|
12
12
|
import * as Renderer from '../src/renderer/Renderer.mjs';
|
|
13
|
+
// @ts-ignore - ReScript generated module
|
|
14
|
+
import * as Fixer from '../src/parser/Fixer/Fixer.mjs';
|
|
13
15
|
// ============================================================================
|
|
14
16
|
// API Functions
|
|
15
17
|
// ============================================================================
|
|
@@ -198,6 +200,84 @@ export function createUIOrThrow(text, options) {
|
|
|
198
200
|
const { root, sceneManager } = render(ast, options);
|
|
199
201
|
return { root, sceneManager, ast };
|
|
200
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Convert ReScript error to ParseError
|
|
205
|
+
*/
|
|
206
|
+
function convertReScriptError(err) {
|
|
207
|
+
// The ReScript error has a complex structure, extract what we need
|
|
208
|
+
return {
|
|
209
|
+
message: String(err.code) || 'Unknown error',
|
|
210
|
+
line: undefined,
|
|
211
|
+
column: undefined,
|
|
212
|
+
source: undefined,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Attempt to auto-fix errors and warnings in the wireframe text.
|
|
217
|
+
*
|
|
218
|
+
* This function analyzes the text for common issues and automatically
|
|
219
|
+
* corrects them where possible. Fixable issues include:
|
|
220
|
+
* - MisalignedPipe: Adjusts pipe positions to correct columns
|
|
221
|
+
* - MisalignedClosingBorder: Fixes closing border alignment
|
|
222
|
+
* - UnusualSpacing: Replaces tabs with spaces
|
|
223
|
+
* - UnclosedBracket: Adds missing closing brackets
|
|
224
|
+
* - MismatchedWidth: Extends shorter borders to match
|
|
225
|
+
*
|
|
226
|
+
* @param text - The wireframe markdown text
|
|
227
|
+
* @returns Fix result with fixed text and details about applied fixes
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const result = fix(text);
|
|
232
|
+
* if (result.success) {
|
|
233
|
+
* console.log(`Fixed ${result.fixed.length} issues`);
|
|
234
|
+
* if (result.remaining.length > 0) {
|
|
235
|
+
* console.warn('Some issues require manual fix:', result.remaining);
|
|
236
|
+
* }
|
|
237
|
+
* // Use the fixed text
|
|
238
|
+
* const parsed = parse(result.text);
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export function fix(text) {
|
|
243
|
+
const result = Fixer.fix(text);
|
|
244
|
+
if (result.TAG === 'Ok') {
|
|
245
|
+
const success = result._0;
|
|
246
|
+
return {
|
|
247
|
+
success: true,
|
|
248
|
+
text: success.text,
|
|
249
|
+
fixed: success.fixed.map((f) => ({
|
|
250
|
+
original: convertReScriptError(f.original),
|
|
251
|
+
description: f.description,
|
|
252
|
+
line: f.line,
|
|
253
|
+
column: f.column,
|
|
254
|
+
})),
|
|
255
|
+
remaining: success.remaining.map(convertReScriptError),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return {
|
|
260
|
+
success: false,
|
|
261
|
+
errors: result._0.map(convertReScriptError),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Convenience function - fix and return just the fixed text.
|
|
267
|
+
* Returns the original text if nothing was fixed or if fixing failed.
|
|
268
|
+
*
|
|
269
|
+
* @param text - The wireframe markdown text
|
|
270
|
+
* @returns The fixed text (or original if no fixes applied)
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const fixedText = fixOnly(rawMarkdown);
|
|
275
|
+
* const result = parse(fixedText);
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export function fixOnly(text) {
|
|
279
|
+
return Fixer.fixOnly(text);
|
|
280
|
+
}
|
|
201
281
|
// Version info
|
|
202
282
|
export const version = Parser.version;
|
|
203
283
|
export const implementation = Parser.implementation;
|
|
@@ -210,6 +290,8 @@ export default {
|
|
|
210
290
|
render,
|
|
211
291
|
createUI,
|
|
212
292
|
createUIOrThrow,
|
|
293
|
+
fix,
|
|
294
|
+
fixOnly,
|
|
213
295
|
version,
|
|
214
296
|
implementation,
|
|
215
297
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0EAA0E;AAC1E,yFAAyF;AACzF,yCAAyC;AACzC,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,yCAAyC;AACzC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0EAA0E;AAC1E,yFAAyF;AACzF,yCAAyC;AACzC,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,yCAAyC;AACzC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAC;AACzD,yCAAyC;AACzC,OAAO,KAAK,KAAK,MAAM,+BAA+B,CAAC;AA+PvD,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAsD,CAAC;IAEvF,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;QACxB,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,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ript generated module
|
|
13
13
|
import * as Renderer from '../src/renderer/Renderer.mjs';
|
|
14
|
+
// @ts-ignore - ReScript generated module
|
|
15
|
+
import * as Fixer from '../src/parser/Fixer/Fixer.mjs';
|
|
14
16
|
|
|
15
17
|
// ============================================================================
|
|
16
18
|
// Type Definitions
|
|
@@ -220,6 +222,35 @@ export type CreateUIErrorResult = {
|
|
|
220
222
|
|
|
221
223
|
export type CreateUIResult = CreateUISuccessResult | CreateUIErrorResult;
|
|
222
224
|
|
|
225
|
+
// ============================================================================
|
|
226
|
+
// Fix Result Types
|
|
227
|
+
// ============================================================================
|
|
228
|
+
|
|
229
|
+
/** Describes a single fix that was applied */
|
|
230
|
+
export interface FixedIssue {
|
|
231
|
+
original: ParseError;
|
|
232
|
+
description: string;
|
|
233
|
+
line: number;
|
|
234
|
+
column: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Successful fix result */
|
|
238
|
+
export type FixSuccessResult = {
|
|
239
|
+
success: true;
|
|
240
|
+
text: string;
|
|
241
|
+
fixed: FixedIssue[];
|
|
242
|
+
remaining: ParseError[];
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/** Failed fix result */
|
|
246
|
+
export type FixErrorResult = {
|
|
247
|
+
success: false;
|
|
248
|
+
errors: ParseError[];
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/** Result of fix operation */
|
|
252
|
+
export type FixResult = FixSuccessResult | FixErrorResult;
|
|
253
|
+
|
|
223
254
|
// ============================================================================
|
|
224
255
|
// Internal ReScript Result Type
|
|
225
256
|
// ============================================================================
|
|
@@ -447,6 +478,105 @@ export function createUIOrThrow(
|
|
|
447
478
|
return { root, sceneManager, ast };
|
|
448
479
|
}
|
|
449
480
|
|
|
481
|
+
// ============================================================================
|
|
482
|
+
// Fix API Functions
|
|
483
|
+
// ============================================================================
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Internal ReScript Fix Result type
|
|
487
|
+
*/
|
|
488
|
+
interface ReScriptFixSuccess {
|
|
489
|
+
text: string;
|
|
490
|
+
fixed: Array<{
|
|
491
|
+
original: { code: unknown; severity: unknown; context: unknown };
|
|
492
|
+
description: string;
|
|
493
|
+
line: number;
|
|
494
|
+
column: number;
|
|
495
|
+
}>;
|
|
496
|
+
remaining: Array<{ code: unknown; severity: unknown; context: unknown }>;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Convert ReScript error to ParseError
|
|
501
|
+
*/
|
|
502
|
+
function convertReScriptError(err: { code: unknown; severity: unknown; context: unknown }): ParseError {
|
|
503
|
+
// The ReScript error has a complex structure, extract what we need
|
|
504
|
+
return {
|
|
505
|
+
message: String(err.code) || 'Unknown error',
|
|
506
|
+
line: undefined,
|
|
507
|
+
column: undefined,
|
|
508
|
+
source: undefined,
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Attempt to auto-fix errors and warnings in the wireframe text.
|
|
514
|
+
*
|
|
515
|
+
* This function analyzes the text for common issues and automatically
|
|
516
|
+
* corrects them where possible. Fixable issues include:
|
|
517
|
+
* - MisalignedPipe: Adjusts pipe positions to correct columns
|
|
518
|
+
* - MisalignedClosingBorder: Fixes closing border alignment
|
|
519
|
+
* - UnusualSpacing: Replaces tabs with spaces
|
|
520
|
+
* - UnclosedBracket: Adds missing closing brackets
|
|
521
|
+
* - MismatchedWidth: Extends shorter borders to match
|
|
522
|
+
*
|
|
523
|
+
* @param text - The wireframe markdown text
|
|
524
|
+
* @returns Fix result with fixed text and details about applied fixes
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* const result = fix(text);
|
|
529
|
+
* if (result.success) {
|
|
530
|
+
* console.log(`Fixed ${result.fixed.length} issues`);
|
|
531
|
+
* if (result.remaining.length > 0) {
|
|
532
|
+
* console.warn('Some issues require manual fix:', result.remaining);
|
|
533
|
+
* }
|
|
534
|
+
* // Use the fixed text
|
|
535
|
+
* const parsed = parse(result.text);
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
export function fix(text: string): FixResult {
|
|
540
|
+
const result = Fixer.fix(text) as ReScriptResult<ReScriptFixSuccess, Array<{ code: unknown; severity: unknown; context: unknown }>>;
|
|
541
|
+
|
|
542
|
+
if (result.TAG === 'Ok') {
|
|
543
|
+
const success = result._0;
|
|
544
|
+
return {
|
|
545
|
+
success: true,
|
|
546
|
+
text: success.text,
|
|
547
|
+
fixed: success.fixed.map((f) => ({
|
|
548
|
+
original: convertReScriptError(f.original),
|
|
549
|
+
description: f.description,
|
|
550
|
+
line: f.line,
|
|
551
|
+
column: f.column,
|
|
552
|
+
})),
|
|
553
|
+
remaining: success.remaining.map(convertReScriptError),
|
|
554
|
+
};
|
|
555
|
+
} else {
|
|
556
|
+
return {
|
|
557
|
+
success: false,
|
|
558
|
+
errors: result._0.map(convertReScriptError),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Convenience function - fix and return just the fixed text.
|
|
565
|
+
* Returns the original text if nothing was fixed or if fixing failed.
|
|
566
|
+
*
|
|
567
|
+
* @param text - The wireframe markdown text
|
|
568
|
+
* @returns The fixed text (or original if no fixes applied)
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* const fixedText = fixOnly(rawMarkdown);
|
|
573
|
+
* const result = parse(fixedText);
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
export function fixOnly(text: string): string {
|
|
577
|
+
return Fixer.fixOnly(text) as string;
|
|
578
|
+
}
|
|
579
|
+
|
|
450
580
|
// Version info
|
|
451
581
|
export const version: string = Parser.version;
|
|
452
582
|
export const implementation: string = Parser.implementation;
|
|
@@ -460,6 +590,8 @@ export default {
|
|
|
460
590
|
render,
|
|
461
591
|
createUI,
|
|
462
592
|
createUIOrThrow,
|
|
593
|
+
fix,
|
|
594
|
+
fixOnly,
|
|
463
595
|
version,
|
|
464
596
|
implementation,
|
|
465
597
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// FixTypes.res
|
|
2
|
+
// Type definitions for the auto-fix functionality
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Describes a single fix that was applied to the source text
|
|
6
|
+
*/
|
|
7
|
+
type fixedIssue = {
|
|
8
|
+
original: ErrorTypes.t,
|
|
9
|
+
description: string,
|
|
10
|
+
line: int,
|
|
11
|
+
column: int,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Result of a successful fix operation
|
|
16
|
+
*/
|
|
17
|
+
type fixSuccess = {
|
|
18
|
+
text: string,
|
|
19
|
+
fixed: array<fixedIssue>,
|
|
20
|
+
remaining: array<ErrorTypes.t>,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Result type for fix operations
|
|
25
|
+
*/
|
|
26
|
+
type fixResult = result<fixSuccess, array<ErrorTypes.t>>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Strategy for fixing a specific error type
|
|
30
|
+
*/
|
|
31
|
+
type fixStrategy = {
|
|
32
|
+
canFix: ErrorTypes.errorCode => bool,
|
|
33
|
+
apply: (string, ErrorTypes.t) => option<(string, fixedIssue)>,
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* TypeScript file generated from Fixer.res by genType. */
|
|
2
|
+
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/* tslint:disable */
|
|
5
|
+
|
|
6
|
+
import * as FixerJS from './Fixer.mjs';
|
|
7
|
+
|
|
8
|
+
import type {fixResult as FixTypes_fixResult} from './FixTypes.gen';
|
|
9
|
+
|
|
10
|
+
/** * Main fix function - attempts to fix all errors in the text
|
|
11
|
+
*
|
|
12
|
+
* This function:
|
|
13
|
+
* 1. Parses the text to get errors/warnings
|
|
14
|
+
* 2. Attempts to fix each fixable error
|
|
15
|
+
* 3. Re-parses after each fix to get updated positions
|
|
16
|
+
* 4. Returns the fixed text and list of applied fixes
|
|
17
|
+
*
|
|
18
|
+
* @param text The wireframe markdown text
|
|
19
|
+
* @returns FixResult with fixed text and details */
|
|
20
|
+
export const fix: (text:string) => FixTypes_fixResult = FixerJS.fix as any;
|
|
21
|
+
|
|
22
|
+
/** * Convenience function - fix and return just the fixed text
|
|
23
|
+
* Returns the original text if nothing was fixed */
|
|
24
|
+
export const fixOnly: (text:string) => string = FixerJS.fixOnly as any;
|