links-notation 0.28.0 → 0.30.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.js +216 -336
- package/package.json +7 -4
- package/src/Cst.js +9 -26
- package/src/ReferenceLiteral.js +22 -0
- package/src/StreamParser.js +33 -13
- package/src/comments.js +50 -11
- package/src/grammar.pegjs +4 -2
- package/src/parser-generated.js +110 -274
- package/src/quotes.js +13 -7
- package/tests/Comments.test.js +31 -0
- package/tests/StreamParser.test.js +13 -0
package/tests/Comments.test.js
CHANGED
|
@@ -158,3 +158,34 @@ test('a hash that cannot open a comment is left unquoted', () => {
|
|
|
158
158
|
expect(Link.escapeReference('#')).toBe("'#'");
|
|
159
159
|
expect(Link.escapeReference('#ff0000')).toBe("'#ff0000'");
|
|
160
160
|
});
|
|
161
|
+
|
|
162
|
+
// Issue #377: the comment reader and the grammar must agree on where every
|
|
163
|
+
// delimited reference starts and how far it reaches, or a comment is blanked
|
|
164
|
+
// inside what the grammar then reads as a reference.
|
|
165
|
+
|
|
166
|
+
test('a hash inside a reference that follows a group is content', () => {
|
|
167
|
+
expect(parsesAs('(a)" #b"\n')).toBe('((<a>) < #b>)');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('a hash inside a reference that follows another reference is content', () => {
|
|
171
|
+
expect(parsesAs('"x"\' #y\'\n')).toBe('(<x> < #y>)');
|
|
172
|
+
expect(parsesAs('```q```"" #c\n"""\n')).toBe('(<q> < #c\n">)');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('a hash inside a reference that follows a literal is content', () => {
|
|
176
|
+
expect(parsesAs('~1{62}" #b"\n')).toBe('(<b> < #b>)');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('a reference is read in the document as written, comments included', () => {
|
|
180
|
+
// The body of the first `""` straddles a parenthesis, so it is the empty
|
|
181
|
+
// reference and the `#` after it opens a comment. Blanking that comment
|
|
182
|
+
// must not turn the `""` into a reference that holds the blanked text.
|
|
183
|
+
expect(parsesAs('"" a #)b\n""\n')).toBe('(<> <a>)\n(<>)');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('the comment reader skips the references the grammar reads', () => {
|
|
187
|
+
expect(stripComments('(a)" #b"\n')).toBe('(a)" #b"\n');
|
|
188
|
+
expect(stripComments('"x"\' #y\'\n')).toBe('"x"\' #y\'\n');
|
|
189
|
+
expect(stripComments('~1{62}" #b"\n')).toBe('~1{62}" #b"\n');
|
|
190
|
+
expect(stripComments('a"b #c"\n')).toBe('a"b \n');
|
|
191
|
+
});
|
|
@@ -162,4 +162,17 @@ describe('StreamParser', () => {
|
|
|
162
162
|
buffered: 2,
|
|
163
163
|
});
|
|
164
164
|
});
|
|
165
|
+
|
|
166
|
+
test('waits for the line that closes an even run of quotes (issue #377)', () => {
|
|
167
|
+
// `""` is the empty reference only when nothing closes it, and here the
|
|
168
|
+
// next line does, so the first line cannot be emitted on its own.
|
|
169
|
+
const input = 'a "" b\n"" c\n';
|
|
170
|
+
const stream = new StreamParser();
|
|
171
|
+
for (const character of input) {
|
|
172
|
+
expect(stream.write(character)).toEqual([]);
|
|
173
|
+
}
|
|
174
|
+
expect(formatLinks(stream.end())).toBe(
|
|
175
|
+
formatLinks(new Parser().parse(input))
|
|
176
|
+
);
|
|
177
|
+
});
|
|
165
178
|
});
|