@p-buddy/parkdown 0.0.28 → 0.0.32
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/README.md +63 -33
- package/dist/cli.js +1 -1
- package/dist/index.js +497 -333
- package/dist/index.umd.cjs +13 -13
- package/package.json +53 -50
- package/src/cli.ts +33 -0
- package/src/index.ts +45 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Collectively, [parkdown](https://www.npmjs.com/package/@p-buddy/parkdown) enable
|
|
|
10
10
|
|
|
11
11
|
[](./.assets/invocation.md)
|
|
12
12
|
<!-- p↓ BEGIN -->
|
|
13
|
-
<!-- p↓ length lines:
|
|
13
|
+
<!-- p↓ length lines: 24 chars: 634 -->
|
|
14
14
|
## Invocation
|
|
15
15
|
|
|
16
16
|
Invoke [parkdown's]() functionality with either the [cli](#cli-inclusions) or via the `processMarkdownIncludes` [export](#populateMarkdownIncludes-export):
|
|
@@ -28,15 +28,10 @@ npx @p-buddy/parkdown # defaults to processing inclusions in the 'README.md' fil
|
|
|
28
28
|
|
|
29
29
|
[](.assets/code/inclusions.ts?region=replace(pkg,'''@p-buddy_slash_parkdown''',_))
|
|
30
30
|
<!-- p↓ BEGIN -->
|
|
31
|
-
<!-- p↓ length lines:
|
|
31
|
+
<!-- p↓ length lines: 5 chars: 12 -->
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import { populateMarkdownInclusions } from "@p-buddy/parkdown";
|
|
35
34
|
|
|
36
|
-
const file = "README.md";
|
|
37
|
-
const writeFile = true;
|
|
38
|
-
|
|
39
|
-
populateMarkdownInclusions(file, writeFile);
|
|
40
35
|
```
|
|
41
36
|
|
|
42
37
|
<!-- p↓ END -->
|
|
@@ -44,7 +39,7 @@ populateMarkdownInclusions(file, writeFile);
|
|
|
44
39
|
|
|
45
40
|
[](./.assets/authoring.md)
|
|
46
41
|
<!-- p↓ BEGIN -->
|
|
47
|
-
<!-- p↓ length lines:
|
|
42
|
+
<!-- p↓ length lines: 730 chars: 25417 -->
|
|
48
43
|
## Authoring
|
|
49
44
|
|
|
50
45
|
You author inclusions in your markdown files using a link with no text i.e. `[](<url>)`, where `<url>` points to some local or remote text resource (e.g.`./other.md`, `https://example.com/remote.md`).
|
|
@@ -256,7 +251,7 @@ Before...
|
|
|
256
251
|
|
|
257
252
|
[](.assets/query.md?heading=-1)
|
|
258
253
|
<!-- p↓ BEGIN -->
|
|
259
|
-
<!-- p↓ length lines:
|
|
254
|
+
<!-- p↓ length lines: 517 chars: 20698 -->
|
|
260
255
|
### Query parameters
|
|
261
256
|
|
|
262
257
|
You can pass query parameters to your inclusion links to control how their content is processed and included within your markdown.
|
|
@@ -286,7 +281,7 @@ const wraps = params.get("wrap")?.split(COMMA_NOT_IN_PARENTHESIS);
|
|
|
286
281
|
|
|
287
282
|
[](.assets/region.md?heading=-1)
|
|
288
283
|
<!-- p↓ BEGIN -->
|
|
289
|
-
<!-- p↓ length lines:
|
|
284
|
+
<!-- p↓ length lines: 218 chars: 10475 -->
|
|
290
285
|
#### `region`
|
|
291
286
|
|
|
292
287
|
Modify content from the included file based on regions designated by comments.
|
|
@@ -346,17 +341,53 @@ Please see the [full explanation](#query-parameters-with-function-like-apis) to
|
|
|
346
341
|
|
|
347
342
|
[](src/region.ts?region=extract(definition))
|
|
348
343
|
<!-- p↓ BEGIN -->
|
|
349
|
-
<!-- p↓ length lines:
|
|
344
|
+
<!-- p↓ length lines: 157 chars: 8187 -->
|
|
350
345
|
|
|
351
346
|
```ts
|
|
352
347
|
const definitions = [
|
|
348
|
+
/**
|
|
349
|
+
* Include all content between comments that INCLUDE the specified ids.
|
|
350
|
+
*
|
|
351
|
+
* This is similar to `extract`, but instead of removing all other content, it appends the specified regions.
|
|
352
|
+
*
|
|
353
|
+
* @param id The id of the comment to include.
|
|
354
|
+
* @param 0 An optional additional id to include.
|
|
355
|
+
* @param 1 An optional additional id to include.
|
|
356
|
+
* @param 2 An optional additional id to include.
|
|
357
|
+
* @param 3 An optional additional id to include.
|
|
358
|
+
* @param 4 An optional additional id to include.
|
|
359
|
+
* @param 5 An optional additional id to include.
|
|
360
|
+
* @param 6 An optional additional id to include.
|
|
361
|
+
* @param 7 An optional additional id to include.
|
|
362
|
+
* @param 8 An optional additional id to include.
|
|
363
|
+
* @param 9 An optional additional id to include.
|
|
364
|
+
* @param 10 An optional additional id to include.
|
|
365
|
+
* @example [](<url>?region=include(specifier))
|
|
366
|
+
* @example [](<url>?region=include(specifier,other-specifier,some-other-specifier))
|
|
367
|
+
*/
|
|
368
|
+
"include(id: string, 0?: string, 1?: string, 2?: string, 3?: string, 4?: string, 5?: string, 6?: string, 7?: string, 8?: string, 9?: string, 10?: string)",
|
|
353
369
|
|
|
354
370
|
/**
|
|
355
371
|
* Extract regions from the retrieved content between comments that INCLUDE the specified ids.
|
|
372
|
+
*
|
|
373
|
+
* NOTE: This method is deprecated in favor of `include`, which has more intuitive behavior.
|
|
374
|
+
* `extract` effectively behaves destructively, removing all content outside of the specified regions,
|
|
375
|
+
* thus you can't chain multiple `extract` calls to build up content from different regions
|
|
376
|
+
* (like you can with `include`).
|
|
377
|
+
*
|
|
378
|
+
* @deprecated Use `include` instead (usage is more intuitive).
|
|
356
379
|
* @param id The id of the comment to extract.
|
|
357
|
-
* @param 0 An optional additional id to
|
|
358
|
-
* @param 1 An optional additional id to
|
|
359
|
-
* @param 2 An optional additional id to
|
|
380
|
+
* @param 0 An optional additional id to include.
|
|
381
|
+
* @param 1 An optional additional id to include.
|
|
382
|
+
* @param 2 An optional additional id to include.
|
|
383
|
+
* @param 3 An optional additional id to include.
|
|
384
|
+
* @param 4 An optional additional id to include.
|
|
385
|
+
* @param 5 An optional additional id to include.
|
|
386
|
+
* @param 6 An optional additional id to include.
|
|
387
|
+
* @param 7 An optional additional id to include.
|
|
388
|
+
* @param 8 An optional additional id to include.
|
|
389
|
+
* @param 9 An optional additional id to include.
|
|
390
|
+
* @param 10 An optional additional id to include.
|
|
360
391
|
* @example [](<url>?region=extract(specifier))
|
|
361
392
|
* @example [](<url>?region=extract(specifier,other-specifier,some-other-specifier))
|
|
362
393
|
*/
|
|
@@ -442,7 +473,7 @@ const definitions = [
|
|
|
442
473
|
* Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
|
|
443
474
|
* @param insert The content to insert.
|
|
444
475
|
* @param space The space character to use between words in the content to insert (defaults to `-`).
|
|
445
|
-
*
|
|
476
|
+
*
|
|
446
477
|
* **NOTE:** Content within comments will not be acted upon.
|
|
447
478
|
*/
|
|
448
479
|
"splice-start(id: string, deleteCount?: number, insert?: string, space?: string)",
|
|
@@ -455,17 +486,16 @@ const definitions = [
|
|
|
455
486
|
* Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
|
|
456
487
|
* @param insert The content to insert.
|
|
457
488
|
* @param space The space character to use between words in the content to insert (defaults to `-`).
|
|
458
|
-
*
|
|
489
|
+
*
|
|
459
490
|
* **NOTE:** Content within comments will not be acted upon.
|
|
460
491
|
*/
|
|
461
492
|
"splice-end(id: string, deleteCount?: number, insert?: string, space?: string)",
|
|
462
493
|
|
|
463
494
|
/**
|
|
464
|
-
* If included at the end of a query, parkdown comments will not be removed from the content after processing.
|
|
495
|
+
* If included at the end of a query, parkdown comments will not be removed from the content after processing.
|
|
465
496
|
* Helpful when trying to determine fine-grained edits (e.g. trimming, splicing, etc.).
|
|
466
497
|
*/
|
|
467
|
-
"debug()"
|
|
468
|
-
|
|
498
|
+
"debug()",
|
|
469
499
|
]
|
|
470
500
|
```
|
|
471
501
|
|
|
@@ -478,7 +508,7 @@ Skip the default processing behavior for the given type of file.
|
|
|
478
508
|
|
|
479
509
|
[](src/include.ts?wrap=dropdown(See-default-processing-behavior.)®ion=extract(Default-Behavior),replace(...))
|
|
480
510
|
<!-- p↓ BEGIN -->
|
|
481
|
-
<!-- p↓ length lines:
|
|
511
|
+
<!-- p↓ length lines: 22 chars: 273 -->
|
|
482
512
|
|
|
483
513
|
<details>
|
|
484
514
|
<summary>
|
|
@@ -486,12 +516,17 @@ See default processing behavior.
|
|
|
486
516
|
</summary>
|
|
487
517
|
|
|
488
518
|
```ts
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
519
|
+
* ...
|
|
520
|
+
content = recursivelyPopulateInclusions(
|
|
521
|
+
content,
|
|
522
|
+
* ...
|
|
523
|
+
);
|
|
524
|
+
} else if (/^(js|ts)x?|svelte$/i.test(extension))
|
|
525
|
+
content = wrap(
|
|
526
|
+
content,
|
|
527
|
+
"code",
|
|
528
|
+
* ...
|
|
529
|
+
);
|
|
495
530
|
```
|
|
496
531
|
|
|
497
532
|
</details>
|
|
@@ -739,7 +774,7 @@ export const sanitize = (content: string, space: string = DEFAULT_SPACE) => {
|
|
|
739
774
|
|
|
740
775
|
[](./.assets/depopulated.md)
|
|
741
776
|
<!-- p↓ BEGIN -->
|
|
742
|
-
<!-- p↓ length lines:
|
|
777
|
+
<!-- p↓ length lines: 33 chars: 1307 -->
|
|
743
778
|
## Removing populated inclusions
|
|
744
779
|
|
|
745
780
|
Sometimes you may want to remove populated inclusions from your markdown file, since they can make things more difficult to read during authoring. You can do this either using the [cli](#cli-removing-populated-inclusions) or via the `removePopulatedInclusions` [export](#depopulateMarkdownIncludes-export):
|
|
@@ -766,15 +801,10 @@ npx @p-buddy/parkdown -d # defaults to processing the 'README.md' file of the cu
|
|
|
766
801
|
|
|
767
802
|
[](.assets/code/depopulate.ts?region=replace(pkg,'''@p-buddy_slash_parkdown''',_))
|
|
768
803
|
<!-- p↓ BEGIN -->
|
|
769
|
-
<!-- p↓ length lines:
|
|
804
|
+
<!-- p↓ length lines: 5 chars: 12 -->
|
|
770
805
|
|
|
771
806
|
```ts
|
|
772
|
-
import { depopulateMarkdownInclusions } from "@p-buddy/parkdown";
|
|
773
|
-
|
|
774
|
-
const file = "README.md";
|
|
775
|
-
const writeFile = true;
|
|
776
807
|
|
|
777
|
-
depopulateMarkdownInclusions(file, writeFile);
|
|
778
808
|
```
|
|
779
809
|
|
|
780
810
|
<!-- p↓ END -->
|
package/dist/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Command as r } from "@commander-js/extra-typings";
|
|
3
3
|
import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
|
|
4
4
|
import f from "chokidar";
|
|
5
|
-
const c = "0.0.
|
|
5
|
+
const c = "0.0.32", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
|
|
6
6
|
t.length === 0 && t.push("README.md");
|
|
7
7
|
const m = [
|
|
8
8
|
[l, !u],
|