@flex-development/docmark-grammar 1.0.0-alpha.1

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/LICENSE.md ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Flex Development, LLC All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software without
17
+ specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # docmark-grammar
2
+
3
+ [![npm](https://img.shields.io/npm/v/@flex-development/docmark.svg)](https://npmjs.com/package/@flex-development/docmark-grammar)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@flex-development/docmark.svg)](https://www.npmcharts.com/compare/@flex-development/docmark-grammar?interval=30)
5
+ [![install size](https://packagephobia.now.sh/badge?p=@flex-development/docmark)](https://packagephobia.now.sh/result?p=@flex-development/docmark-grammar)
6
+ [![module type: esm](https://img.shields.io/badge/module%20type-esm-brightgreen)](https://github.com/voxpelli/badges-cjs-esm)
7
+
8
+ core [docmark][] constructs and utilities.
9
+
10
+ ## Contents
11
+
12
+ - [What is this?](#what-is-this)
13
+ - [When should I use this?](#when-should-i-use-this)
14
+ - [Install](#install)
15
+ - [Use](#use)
16
+ - [API](#api)
17
+ - [Types](#types)
18
+ - [Contribute](#contribute)
19
+
20
+ ## What is this?
21
+
22
+ **TODO**: what is this?
23
+
24
+ ## When should I use this?
25
+
26
+ This package is useful when extending docmark.
27
+
28
+ ## Install
29
+
30
+ This package is [ESM only][esm].
31
+
32
+ In Node.js with [yarn][]:
33
+
34
+ ```sh
35
+ yarn add @flex-development/docmark-grammar
36
+ ```
37
+
38
+ <blockquote>
39
+ <small>
40
+ See <a href='https://yarnpkg.com/protocol/git'>Git - Protocols | Yarn</a>
41
+ &nbsp;for details regarding installing from Git.
42
+ </small>
43
+ </blockquote>
44
+
45
+ In Deno with [`esm.sh`][esmsh]:
46
+
47
+ ```ts
48
+ import {
49
+ blankLine,
50
+ eoc,
51
+ region,
52
+ summary,
53
+ trailingWhitespace,
54
+ typeExpressionValue
55
+ } from 'https://esm.sh/@flex-development/docmark'
56
+ ```
57
+
58
+ In browsers with [`esm.sh`][esmsh]:
59
+
60
+ ```html
61
+ <script type="module">
62
+ import {
63
+ blankLine,
64
+ eoc,
65
+ region,
66
+ summary,
67
+ trailingWhitespace,
68
+ typeExpressionValue
69
+ } from 'https://esm.sh/@flex-development/docmark'
70
+ </script>
71
+ ```
72
+
73
+ ## Use
74
+
75
+ **TODO**: use
76
+
77
+ ## API
78
+
79
+ **TODO**: api
80
+
81
+ ## Types
82
+
83
+ This package is fully typed with [TypeScript][].
84
+
85
+ ## Contribute
86
+
87
+ See [`CONTRIBUTING.md`](../../CONTRIBUTING.md).
88
+
89
+ This project has a [code of conduct](../../CODE_OF_CONDUCT.md).
90
+ By interacting with this repository, organization, or community you agree to abide by its terms.
91
+
92
+ [docmark]: ../../README.md
93
+
94
+ [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
95
+
96
+ [esmsh]: https://esm.sh
97
+
98
+ [typescript]: https://www.typescriptlang.org
99
+
100
+ [yarn]: https://yarnpkg.com
@@ -0,0 +1,138 @@
1
+ import type { PartialConstruct, ContinuableConstruct, NamedConstruct } from '@flex-development/docmark-util-types';
2
+
3
+ /**
4
+ * @file Constructs - blankLine
5
+ * @module docmark-grammar/constructs/blankLine
6
+ */
7
+
8
+ /**
9
+ * The blank line construct.
10
+ *
11
+ * A blank line may start at the beginning of stream or after a new line.
12
+ *
13
+ * At the `source` content level, blank lines are considered opaque content when
14
+ * there is no active comment.\
15
+ * Otherwise, leading whitespace is a captured as a `linePrefix`.
16
+ *
17
+ * This construct is expected to run at the `comment` or `source` content level.
18
+ *
19
+ * @category
20
+ * constructs
21
+ *
22
+ * @const {PartialConstruct} blankLine
23
+ */
24
+ declare const blankLine: PartialConstruct;
25
+
26
+ /**
27
+ * @file Constructs - eoc
28
+ * @module docmark-grammar/constructs/eoc
29
+ */
30
+
31
+ /**
32
+ * The end-of-content construct.
33
+ *
34
+ * End of content consists of zero or more line endings and/or whitespace
35
+ * characters followed by end of stream.
36
+ *
37
+ * This construct is used when a caller must determine whether the remainder of
38
+ * a content stream contains only blank lines and/or whitespace.
39
+ *
40
+ * @const {PartialConstruct} eoc
41
+ */
42
+ declare const eoc: PartialConstruct;
43
+
44
+ /**
45
+ * @file Constructs - region
46
+ * @module docmark-grammar/constructs/region
47
+ */
48
+
49
+ /**
50
+ * Attempt a comment region at the current position.
51
+ *
52
+ * An unprefixed region attempt is made first.\
53
+ * If the initial attempt fails, a line prefix is then attempted and regions are
54
+ * checked again at the new position, or the current position if no line prefix
55
+ * is present.
56
+ *
57
+ * The construct fails without consuming any input if no prefixed or unprefixed
58
+ * region can begin.
59
+ *
60
+ * Constructs registered for the `comment` content type are then attempted
61
+ * in extension order.
62
+ *
63
+ * @category
64
+ * constructs
65
+ *
66
+ * @const {PartialConstruct} region
67
+ */
68
+ declare const region: PartialConstruct;
69
+
70
+ /**
71
+ * @file Constructs - summary
72
+ * @module docmark-grammar/constructs/summary
73
+ */
74
+
75
+ /**
76
+ * The comment summary construct.
77
+ *
78
+ * A summary is the initial markdown region of a comment.\
79
+ * Summary content is only allowed at the beginning of a comment and continues
80
+ * across subsequent logical comment lines until another region begins or the
81
+ * end of content is reached.
82
+ *
83
+ * Summary content is not tokenized by this construct,
84
+ * nor its `continuation` construct.
85
+ * Markdown chunk creation, region-boundary detection, and continuation routing
86
+ * are handled by the `comment` initializer.
87
+ *
88
+ * This construct is expected to run at the `comment` content level.
89
+ *
90
+ * @category
91
+ * constructs
92
+ *
93
+ * @const {ContinuableConstruct & NamedConstruct} summary
94
+ */
95
+ declare const summary: ContinuableConstruct & NamedConstruct;
96
+
97
+ /**
98
+ * @file Constructs - trailingWhitespace
99
+ * @module docmark-grammar/constructs/trailingWhitespace
100
+ */
101
+
102
+ /**
103
+ * The trailing whitespace construct.
104
+ *
105
+ * Trailing whitespace may be seen at the end of a line.
106
+ *
107
+ * > 👉 **Note**: Blank lines are expected to already be parsed.\
108
+ * > The construct does not check for blank lines before parse attempts.
109
+ *
110
+ * @category
111
+ * constructs
112
+ *
113
+ * @const {PartialConstruct} trailingWhitespace
114
+ */
115
+ declare const trailingWhitespace: PartialConstruct;
116
+
117
+ /**
118
+ * @file Constructs - typeExpressionValue
119
+ * @module docmark-grammar/constructs/typeExpressionValue
120
+ */
121
+
122
+ /**
123
+ * The type expression value construct.
124
+ *
125
+ * A type expression value represents the contents of a value within a type
126
+ * expression. The value is preserved as-is until the end of the current `type`
127
+ * content stream.
128
+ *
129
+ * This construct is expected to run at the `type` content level.
130
+ *
131
+ * It is `partial` so the enclosing type construct remains the tokenizer's
132
+ * `currentConstruct` while the value is parsed.
133
+ *
134
+ * @const {NamedConstruct & PartialConstruct} typeExpressionValue
135
+ */
136
+ declare const typeExpressionValue: NamedConstruct & PartialConstruct;
137
+
138
+ export { blankLine, eoc, region, summary, trailingWhitespace, typeExpressionValue };
package/dist/index.mjs ADDED
@@ -0,0 +1,148 @@
1
+ import { factorySpace } from '@flex-development/docmark-factory-space';
2
+ import { constants, tt } from '@flex-development/docmark-util-symbol';
3
+ import { bos, eol, whitespace, eos } from '@flex-development/mark-util-character';
4
+ import { ok } from 'devlop';
5
+
6
+ const blankLine = {
7
+ partial: true,
8
+ previous: previousBlankLine,
9
+ tokenize: tokenizeBlankLine
10
+ };
11
+ function previousBlankLine(code) {
12
+ return bos(code) || eol(code);
13
+ }
14
+ function tokenizeBlankLine(effects, ok, nok) {
15
+ const self = this;
16
+ return startBlankLine;
17
+ function startBlankLine(code) {
18
+ if (!whitespace(code))
19
+ return afterLinePrefix(code);
20
+ const type =
21
+ self.contentType !== constants.contentTypeSource ||
22
+ self.containerState?.comment
23
+ ? tt.linePrefix
24
+ : undefined;
25
+ return factorySpace(effects, afterLinePrefix, type)(code);
26
+ }
27
+ function afterLinePrefix(code) {
28
+ if (eol(code) || eos(code))
29
+ return ok(code);
30
+ return nok(code);
31
+ }
32
+ }
33
+
34
+ const eoc = { partial: true, tokenize: tokenizeEndOfContent };
35
+ function tokenizeEndOfContent(effects, ok, nok) {
36
+ return maybeEnd;
37
+ function maybeEnd(code) {
38
+ if (eos(code))
39
+ return ok(code);
40
+ if (eol(code) || whitespace(code))
41
+ return effects.consume(code), maybeEnd;
42
+ return nok(code);
43
+ }
44
+ }
45
+
46
+ const region = { partial: true, tokenize: tokenizeRegion };
47
+ function tokenizeRegion(effects, ok$1, nok) {
48
+ const self = this;
49
+ return effects.attempt(this.parser.constructs.comment, ok$1, prefixedRegion);
50
+ function prefixedRegion(code) {
51
+ ok(self.parser.constructs.disable.null, 'expected `disable.null`');
52
+ ok(eos(code) || bos(self.previous) || eol(self.previous), 'expected end of stream, beginning of stream, or beginning of line');
53
+ return factorySpace(effects, effects.attempt(self.parser.constructs.comment, ok$1, nok), tt.linePrefix, self.parser.constructs.disable.null.includes(tt.codeIndented)
54
+ ? undefined
55
+ : constants.tabSize)(code);
56
+ }
57
+ }
58
+
59
+ const summary = {
60
+ continuation: { tokenize: tokenizeSummaryContinuation },
61
+ exit: exitSummary,
62
+ name: tt.summary,
63
+ previous: previousSummary,
64
+ tokenize: tokenizeSummary
65
+ };
66
+ function exitSummary(effects) {
67
+ return void effects.exit(tt.summary);
68
+ }
69
+ function previousSummary(code) {
70
+ return bos(code) || eol(code);
71
+ }
72
+ function tokenizeSummary(effects, ok$1, nok) {
73
+ const self = this;
74
+ return startSummary;
75
+ function startSummary(code) {
76
+ ok(self.containerState, 'expected `containerState` inside region');
77
+ ok(!self.parser.atBlankLine, 'did not expect blank line');
78
+ ok(!eol(code), 'did not expect line ending');
79
+ ok(!eos(code), 'did not expect end of stream');
80
+ if (self.containerState.open)
81
+ return nok(code);
82
+ if (self.parser.skipSummary)
83
+ return nok(code);
84
+ effects.enter(tt.summary, { _container: true, _region: true });
85
+ self.containerState.open = true;
86
+ effects.enter(tt.summaryMarker);
87
+ effects.exit(tt.summaryMarker);
88
+ return effects.check(region, nok, ok$1)(code);
89
+ }
90
+ }
91
+ function tokenizeSummaryContinuation(effects, ok, nok) {
92
+ return continueSummary;
93
+ function continueSummary(code) {
94
+ if (eos(code))
95
+ return nok(code);
96
+ return ok(code);
97
+ }
98
+ }
99
+
100
+ const trailingWhitespace = {
101
+ partial: true,
102
+ tokenize: tokenizeTrailingWhitespace
103
+ };
104
+ function tokenizeTrailingWhitespace(effects, ok$1, nok) {
105
+ const self = this;
106
+ return whitespaceTrail;
107
+ function whitespaceTrail(code) {
108
+ ok(!self.parser.atBlankLine, 'did not expect blank line');
109
+ ok(whitespace(code), 'expected whitespace');
110
+ return factorySpace(effects, afterWhitespaceTrail, tt.whitespace)(code);
111
+ }
112
+ function afterWhitespaceTrail(code) {
113
+ self.events.at(-1)[1]._trailing = true;
114
+ if (eol(code)) {
115
+ effects.enter(tt.lineEnding);
116
+ effects.consume(code);
117
+ effects.exit(tt.lineEnding);
118
+ return ok$1;
119
+ }
120
+ if (eos(code))
121
+ return ok$1(code);
122
+ return nok(code);
123
+ }
124
+ }
125
+
126
+ const typeExpressionValue = {
127
+ add: 'after',
128
+ name: tt.typeExpressionValue,
129
+ partial: true,
130
+ tokenize: tokenizeTypeExpressionValue
131
+ };
132
+ function tokenizeTypeExpressionValue(effects, ok) {
133
+ return startTypeExpressionValue;
134
+ function startTypeExpressionValue(code) {
135
+ effects.enter(tt.typeExpressionValue);
136
+ return insideValue(code);
137
+ }
138
+ function insideValue(code) {
139
+ if (eos(code)) {
140
+ effects.exit(tt.typeExpressionValue);
141
+ return ok(code);
142
+ }
143
+ effects.consume(code);
144
+ return insideValue;
145
+ }
146
+ }
147
+
148
+ export { blankLine, eoc, region, summary, trailingWhitespace, typeExpressionValue };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@flex-development/docmark-grammar",
3
+ "description": "core docmark constructs and utilities",
4
+ "version": "1.0.0-alpha.1",
5
+ "keywords": [
6
+ "commonmark",
7
+ "docdown",
8
+ "docmark",
9
+ "documentation",
10
+ "gfm",
11
+ "markdown",
12
+ "md",
13
+ "mdast",
14
+ "parse",
15
+ "parser",
16
+ "token",
17
+ "tokenize",
18
+ "tokenizer"
19
+ ],
20
+ "license": "BSD-3-Clause",
21
+ "homepage": "https://github.com/flex-development/docmark",
22
+ "repository": {
23
+ "directory": "packages/docmark-grammar",
24
+ "type": "git",
25
+ "url": "git+https://github.com/flex-development/docmark.git"
26
+ },
27
+ "bugs": "https://github.com/flex-development/docmark/issues",
28
+ "author": {
29
+ "name": "Lexus Drumgold",
30
+ "url": "https://github.com/unicornware"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "diff-dst-prefix": "docmark-grammar",
35
+ "diff-src-prefix": "docmark-grammar",
36
+ "directory": "./",
37
+ "executableFiles": [],
38
+ "node-options": null,
39
+ "pack-destination": ".",
40
+ "parseable": true,
41
+ "prefer-dedupe": true,
42
+ "provenance": true,
43
+ "tag-version-prefix": "docmark-grammar"
44
+ },
45
+ "type": "module",
46
+ "files": [
47
+ "LICENSE.md",
48
+ "README.md",
49
+ "dist"
50
+ ],
51
+ "exports": {
52
+ ".": {
53
+ "docmark": "./src/index.mts",
54
+ "default": "./dist/index.mjs"
55
+ },
56
+ "./package.json": "./package.json"
57
+ },
58
+ "module": "./dist/index.mjs",
59
+ "types": "./dist/index.d.mts",
60
+ "scripts": {
61
+ "attw": "tsc --build tsconfig.build.json --clean --dry && tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.json --verbose"
62
+ },
63
+ "dependencies": {
64
+ "@flex-development/docmark-factory-space": "1.0.0-alpha.1",
65
+ "@flex-development/docmark-util-symbol": "1.0.0-alpha.1",
66
+ "@flex-development/docmark-util-types": "1.0.0-alpha.1",
67
+ "@flex-development/mark-util-character": "1.1.0",
68
+ "devlop": "1.1.0"
69
+ },
70
+ "sideEffects": false,
71
+ "build": "524f7d653272a777cde27efaac4656fb90cd4855"
72
+ }