@p-buddy/parkdown 0.0.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.
Files changed (43) hide show
  1. package/.assets/api-note.md +3 -0
  2. package/.assets/api.md +34 -0
  3. package/.assets/authoring.md +69 -0
  4. package/.assets/code/depopulate.ts +6 -0
  5. package/.assets/code/inclusions.ts +6 -0
  6. package/.assets/depopulated.md +25 -0
  7. package/.assets/invocation.md +16 -0
  8. package/.assets/populated/block.md +9 -0
  9. package/.assets/populated/inline.multi.md +5 -0
  10. package/.assets/populated/inline.single.md +3 -0
  11. package/.assets/query.md +73 -0
  12. package/.assets/remap-imports.md +0 -0
  13. package/.assets/unpopulated/block.md +5 -0
  14. package/.assets/unpopulated/inline.multi.md +3 -0
  15. package/.assets/unpopulated/inline.single.md +1 -0
  16. package/.devcontainer/Dockerfile +16 -0
  17. package/.devcontainer/devcontainer.json +35 -0
  18. package/LICENSE +21 -0
  19. package/README.md +418 -0
  20. package/dist/cli.js +14 -0
  21. package/dist/index.d.ts +7 -0
  22. package/dist/index.js +396 -0
  23. package/dist/index.umd.cjs +15 -0
  24. package/package.json +42 -0
  25. package/src/api/index.test.ts +32 -0
  26. package/src/api/index.ts +8 -0
  27. package/src/api/types.ts +78 -0
  28. package/src/api/utils.test.ts +132 -0
  29. package/src/api/utils.ts +161 -0
  30. package/src/cli.ts +31 -0
  31. package/src/include.test.ts +369 -0
  32. package/src/include.ts +252 -0
  33. package/src/index.ts +35 -0
  34. package/src/region.test.ts +145 -0
  35. package/src/region.ts +138 -0
  36. package/src/remap.test.ts +37 -0
  37. package/src/remap.ts +72 -0
  38. package/src/utils.test.ts +238 -0
  39. package/src/utils.ts +184 -0
  40. package/src/wrap.ts +61 -0
  41. package/tsconfig.json +5 -0
  42. package/vite.cli.config.ts +23 -0
  43. package/vite.config.ts +20 -0
@@ -0,0 +1,3 @@
1
+ **_NOTE ON API USAGE:_** As you can see from the included examples, each _invocation_ of an API method looks like a less strict (more quirky) version of a typical javascript function invocation.
2
+
3
+ Please see the [full explanation](#query-parameters-with-function-like-apis) to learn more and/or if the below is confusing.
package/.assets/api.md ADDED
@@ -0,0 +1,34 @@
1
+ ## Query Parameters with Function-like APIs
2
+
3
+ Some query parameters have more complex APIs, which are defined by a collection of typescript function singatures (limited to only `string`, `boolean`, and `number` arguments), like:
4
+
5
+ ```ts
6
+ const definitions = [
7
+ "method(arg1: string, arg2: boolean, arg3?: number)",
8
+ "otherMethod(arg1: string, arg2?: boolean, arg3?: number)"
9
+ ]
10
+ ```
11
+
12
+ These APIs are utilized when setting the query parameter with a _function-like_ invocation syntax, such as:
13
+
14
+ ```md
15
+ [](<url>?example=method(hello-world,true))
16
+ ```
17
+
18
+ As you can maybe tell from the example above, we're relaxing some constraints on typical function invocations (like the need to wrap string arguments in quotes), while also imposing some additional constraints (like not using spaces) to ensure the links are valid markdown and the URLs are [safe](https://support.exactonline.com/community/s/knowledge-base?language=en_GB#All-All-DNO-Content-urlcharacters).
19
+
20
+ The goal is to make it as painless as possible to author links that are valid markdown, valid URLs, and easy to read and write.
21
+
22
+ Please note the following:
23
+
24
+ - Methods that take no arguments can be invoked without parentheses (e.g. `[](<url>?example=method)`).
25
+ - String arguments do not need to be wrapped in quotes (e.g. `[](<url>?example=method(some-string))`), and they should **NOT** be wrapped in double quotes (see more below).
26
+ - You cannot use spaces within a string argument or anywhere else in the query (as this would violate the markdown link syntax). For arguments that reasonably could include spaces, there should be an optional `space` argument that defaults to `-`, so that any usage of the space character will be converted to a space (e.g. `hello-world` becomes `hello world`).
27
+ - If a method takes a string argument, and you want to include a comma within that argument, you must wrap it in one or more single quotes (`'`).
28
+ - String arguments wrapped in single set of single quotes will automatically have their single quotes removed when the query is parsed (e.g. the argument included in `[](<url>?example=method('hello,world'))` will parse to `hello,world`).
29
+ - If you want single quotes preserved in the parsed output, use two single quotes in a row (e.g. `[](<url>?example=method(''single-quoted''))`).
30
+ - You cannot use double quotes within a string argument (as they are not a [URL safe character](https://support.exactonline.com/community/s/knowledge-base#All-All-DNO-Content-urlcharacters)). To include a double-quote in the parsed output, use three single quotes in a row (e.g. `[](<url>?example=method'''double-quoted'''))`).
31
+ - Optional arguments can be completely ommitted (for example if a `method` took 3 optional arguments, and you only wanted to provide the third, you could do the following: `[](<url>?example=method(,,your-third-argument))`).
32
+ - Overall, text meant to be displayed to a human will be _sanitized_ in the following manner (unless otherwise noted):
33
+
34
+ [](../src/utils.ts?region=extract(sanitize))
@@ -0,0 +1,69 @@
1
+ # Authoring
2
+
3
+ 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`).
4
+
5
+ These links can be rendered either [inline](#inline) or [block](#block), depending on how you author them.
6
+
7
+ ## Inline
8
+
9
+ Inline inclusions occur when your _text-less_ link has 1 or more siblings (meaning it's **not** the only node in a [paragraph](https://www.markdownguide.org/basic-syntax/#paragraphs-1)).
10
+
11
+ There are two equivalent ways to author inline inclusions, [single-line](#single-line) or [multi-line](#multi-line), and which you choose depends solely on how you want your raw markdown to look (it will **not** affect the rendered output).
12
+
13
+ ### Single-line
14
+
15
+ What you write:
16
+
17
+ [](./unpopulated/inline.single.md?wrap=code)
18
+
19
+ What is rendered (**_before_** processing, same as [Option B](#option-b-multi-line)):
20
+
21
+ [](./unpopulated/inline.single.md?wrap=quote&inline)
22
+
23
+ What your markdown file contains (**_after_** processing):
24
+
25
+ [](./populated/inline.single.md?wrap=code)
26
+
27
+ What is rendered (**_after_** processing, same as [Option B](#option-b-multi-line)):
28
+
29
+ [](./populated/inline.single.md?wrap=quote&inline)
30
+
31
+ ### Multi-line
32
+
33
+ What you write:
34
+
35
+ [](./unpopulated/inline.multi.md?wrap=code)
36
+
37
+ What is rendered (**_before_** processing, same as [Option A](#option-a-single-line)):
38
+
39
+ [](./unpopulated/inline.multi.md?wrap=quote&inline)
40
+
41
+ What your markdown file contains (**_after_** processing):
42
+
43
+ [](./populated/inline.multi.md?wrap=code)
44
+
45
+ What is rendered (**_after_** processing, same as [Option A](#option-a-single-line)):
46
+
47
+ [](./populated/inline.multi.md?wrap=quote&inline)
48
+
49
+ ## Block
50
+
51
+ Block inclusions occur when your "empty" link is the **only** node in a [paragraph](https://www.markdownguide.org/basic-syntax/#paragraphs-1) (at least before being populated). This is likely the most common way to author inclusions.
52
+
53
+ What you write:
54
+
55
+ [](./unpopulated/block.md?wrap=code)
56
+
57
+ What is rendered (**_before_** processing):
58
+
59
+ [](./unpopulated/block.md?wrap=quote)
60
+
61
+ What your markdown file contains (**_after_** processing):
62
+
63
+ [](./populated/block.md?wrap=code)
64
+
65
+ What is rendered (**_after_** processing):
66
+
67
+ [](./populated/block.md?wrap=quote)
68
+
69
+ [](./query.md?heading=-1)
@@ -0,0 +1,6 @@
1
+ import { depopulateMarkdownInclusions } from /** p▼: pkg */ "../../src" /** p▼: pkg */;
2
+
3
+ const file = "README.md";
4
+ const writeFile = true;
5
+
6
+ depopulateMarkdownInclusions(file, writeFile);
@@ -0,0 +1,6 @@
1
+ import { populateMarkdownInclusions } from /** p▼: pkg */ "../../src" /** p▼: pkg */;
2
+
3
+ const file = "README.md";
4
+ const writeFile = true;
5
+
6
+ populateMarkdownInclusions(file, writeFile);
@@ -0,0 +1,25 @@
1
+ # Removing populated inclusions
2
+
3
+ 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):
4
+
5
+ ## CLI (removing populated inclusions)
6
+
7
+ The following commands are all equivalent:
8
+
9
+ ```bash
10
+ npx parkdown --file ./README.md --depopulate --no-inclusions
11
+ npx parkdown -f README.md -d --ni # Notice the double-dash (--) on 'ni'
12
+ npx parkdown -d --ni # defaults to processing the 'README.md' file of the current working directory
13
+ ```
14
+
15
+ The following commands will lead to the same result, but since `--no-inclusions` (`--ni`) is not specified, there will be some wasted work as inclusions will be processed and then removed.
16
+
17
+ ```bash
18
+ npx parkdown --file ./README.md --depopulate
19
+ npx parkdown -f README.md -d
20
+ npx parkdown -d # defaults to processing the 'README.md' file of the current working directory
21
+ ```
22
+
23
+ ## `depopulateMarkdownIncludes` export
24
+
25
+ [](./code/depopulate.ts?region=replace(pkg,'''parkdown'''))
@@ -0,0 +1,16 @@
1
+ # Invocation
2
+
3
+ Invoke [parkdown's]() functionality with either the [cli](#cli-inclusions) or via the `processMarkdownIncludes` [export](#populateMarkdownIncludes-export):
4
+
5
+ ## CLI
6
+
7
+ The following commands are all equivalent:
8
+ ```bash
9
+ npx parkdown --file ./README.md
10
+ npx parkdown -f README.md
11
+ npx parkdown # defaults to processing inclusions in the 'README.md' file of the current working directory
12
+ ```
13
+
14
+ ## `populateMarkdownIncludes` export
15
+
16
+ [](./code/inclusions.ts?region=replace(pkg,'''parkdown'''))
@@ -0,0 +1,9 @@
1
+ Before...
2
+
3
+ [](<url>)
4
+ <!-- p▼ Begin -->
5
+ ...Included Content...
6
+ ...Included Content...
7
+ <!-- p▼ End -->
8
+
9
+ ...After
@@ -0,0 +1,5 @@
1
+ Before...
2
+ [](<url>) <!-- p▼ Begin -->
3
+ ...Included Content...
4
+ ...Included Content... <!-- p▼ End -->
5
+ ...After
@@ -0,0 +1,3 @@
1
+ Before... [](<url>) <!-- p▼ Begin -->
2
+ ...Included Content...
3
+ ...Included Content... <!-- p▼ End --> ...After
@@ -0,0 +1,73 @@
1
+ # Query parameters
2
+
3
+ You can pass query parameters to your inclusion links to control how their content is processed and included within your markdown.
4
+
5
+ ## Processing Order
6
+
7
+ [](../src/include.ts?&region=extract(query))
8
+
9
+ ## `region`
10
+
11
+ Either extract, remove, or replace content from the included file based on the provided specifier(s).
12
+
13
+ Specifiers will be searched for within the file's comments, and are expected to come in pairs / bookend the desired region, like so:
14
+
15
+ ```ts
16
+ /** some-specifier */
17
+ ... code to find ...
18
+ /** some-specifier */
19
+ ```
20
+
21
+ ```md
22
+ [](...?region=extract(some-specifier))
23
+ ```
24
+
25
+ Below is the currently supported API for the `region` query parameter, where each defined method signature can be _invoked_ as a value for the `region` parameter (e.g. `[](<url>?region=extract(some-specifier))`, `[](<url>?region=remove(some-specifier))`, `[](<url>?region=replace(some-specifier))`).
26
+
27
+ [](./api-note.md?wrap=quote)
28
+
29
+ [](../src/region.ts?region=extract(definition))
30
+
31
+ ## `skip`
32
+
33
+ Skip the default processing behavior for the given type of file.
34
+
35
+ [](../src/include.ts?wrap=dropdown(See-default-processing-behavior.)&region=extract(Default-Behavior),replace(...))
36
+
37
+ ```md
38
+ [](<url>?skip)
39
+ ```
40
+
41
+ ## `heading`
42
+
43
+ Modify the heading depth applied to included content. By default, the headings of the included content are adjusted to be one-level below their parent heading.
44
+
45
+ In the following example, the headings within the included content of `<url>` will be adjusted to one-level below the parent heading (which is an `h2` / `##`), so any `#` headings will be converted to `###` headings, and `##` headings will be converted to `####` headings, and so on.
46
+
47
+ ```md
48
+ ## Heading
49
+
50
+ [](<url>)
51
+ ```
52
+
53
+ The following would then ensure that the headings of the included content are at the same level as the parent heading.
54
+
55
+ ```md
56
+ ## Heading
57
+
58
+ [](<url>?heading=-1)
59
+ ```
60
+
61
+ A value of `-2` would result in the headings of the included content being at their original level (since the content is being included underneath an `h2` / `##` heading).
62
+
63
+ ## `inline` (Advanced)
64
+
65
+ ## `wrap`
66
+
67
+ Wrap the content of the included file in a specific kind of element.
68
+
69
+ Below is the currently supported API for the `wrap` query parameter, where each defined method signature can be _invoked_ as a value for the `wrap` parameter (e.g. `[](<url>?wrap=code)`, `[](<url>?wrap=dropdown(hello-world))`).
70
+
71
+ [](./api-note.md?wrap=quote)
72
+
73
+ [](../src/wrap.ts?region=extract(definition))
File without changes
@@ -0,0 +1,5 @@
1
+ Before...
2
+
3
+ [](<url>)
4
+
5
+ ...After
@@ -0,0 +1,3 @@
1
+ Before...
2
+ [](<url>)
3
+ ...After
@@ -0,0 +1 @@
1
+ Before... [](<url>) ...After
@@ -0,0 +1,16 @@
1
+ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/typescript-node/.devcontainer/base.Dockerfile
2
+
3
+ # [Choice] Node.js version: 16, 18, 20
4
+ ARG VARIANT="20-buster"
5
+ FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
6
+
7
+ # [Optional] Uncomment this section to install additional OS packages.
8
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
10
+
11
+ # [Optional] Uncomment if you want to install an additional version of node using nvm
12
+ # ARG EXTRA_NODE_VERSION=10
13
+ # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
14
+
15
+ # To install more global node packages
16
+ RUN su node -c "npm install -g pnpm@10"
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "parkdown-dev",
3
+ "dockerFile": "Dockerfile",
4
+ "customizations": {
5
+ "vscode": {
6
+ "extensions": [
7
+ "ms-vscode.vscode-typescript-next",
8
+ "svelte.svelte-vscode",
9
+ "ms-azuretools.vscode-docker",
10
+ "bradlc.vscode-tailwindcss",
11
+ "YoavBls.pretty-ts-errors"
12
+ ]
13
+ }
14
+ },
15
+ "postStartCommand": [
16
+ "bash",
17
+ "-c",
18
+ "git config --global user.name \"${GIT_USER_NAME}\"",
19
+ "bash",
20
+ "-c",
21
+ "git config --global user.email \"${GIT_USER_EMAIL}\"",
22
+ "bash",
23
+ "-c",
24
+ "pnpm install"
25
+ ],
26
+ "mounts": [
27
+ "source=${localEnv:HOME}/.ssh,target=/home/node/.ssh,type=bind,readonly"
28
+ ],
29
+ "containerEnv": {
30
+ "NPM_TOKEN": "${localEnv:PARKDOWN_NPM_TOKEN}",
31
+ "HOST_WORKSPACE_PATH": "${localWorkspaceFolder}",
32
+ "GIT_USER_NAME": "${localEnv:GIT_USER_NAME}",
33
+ "GIT_USER_EMAIL": "${localEnv:GIT_USER_EMAIL}"
34
+ }
35
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Parker Malachowsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.