Skip to content

Commit 79e02b4

Browse files
hawkeyexlCopilot
andauthored
Add support for additional CommonMark syntax variations and improve JSON parsing (#93)
* Add support for more variations of CommonMark syntax * Normalize test-level detectSteps * Improve double-quoted JSON parsing * Fix log level * Enhance JSON and YAML parsing logic to handle escaped/double-encoded JSON * Fix warning-checking test * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0b62b5e commit 79e02b4

File tree

6 files changed

+611
-16
lines changed

6 files changed

+611
-16
lines changed

dev/doc-content.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
```
2-
PATCH https://orc.wiremockapi.cloud/satellites/8 HTTP/1.1
3-
Host: orc.wiremockapi.cloud
4-
Content-Type: application/json
5-
Accept: application/json
6-
Content-Length: 25
7-
8-
{
9-
"status": "maintenance"
10-
}
11-
```
1+
[comment]: # 'test {"testId": "uppercase-conversion", "detectSteps": false}'
2+
3+
1. Open the app at [http://localhost:3000](http://localhost:3000).
4+
5+
[comment]: # 'step {"goTo": "http://localhost:3000"}'
6+
7+
2. Type "hello world" in the input field.
8+
9+
[comment]: # 'step {"find": {"selector": "#input", "click": true}}'
10+
[comment]: # 'step {"type": "hello world"}'
11+
12+
3. Click **Convert to Uppercase**.
13+
14+
[comment]: # 'step {"find": {"selector": "button", "click": true}}'
15+
16+
4. You'll see **HELLO WORLD** in the output.
17+
18+
[comment]: # 'step {"find": "HELLO WORLD"}'
19+
[comment]: # "test end"

dev/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ main();
1212
*/
1313
async function main() {
1414
const json = {
15-
input: "dev/doc-content.dita",
15+
input: "dev/doc-content.md",
1616
logLevel: "debug",
1717
runOn: [
1818
{

src/config.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,57 @@ let defaultFileTypes = {
320320
testStart: [
321321
"{\\/\\*\\s*test\\s+?([\\s\\S]*?)\\s*\\*\\/}",
322322
"<!--\\s*test\\s*([\\s\\S]*?)\\s*-->",
323+
// CommonMark comment syntax with parentheses: [comment]: # (test ...)
323324
"\\[comment\\]:\\s+#\\s+\\(test\\s*(.*?)\\s*\\)",
324325
"\\[comment\\]:\\s+#\\s+\\(test start\\s*(.*?)\\s*\\)",
326+
// CommonMark comment syntax with single quotes: [comment]: # 'test ...'
327+
"\\[comment\\]:\\s+#\\s+'test\\s*(.*?)\\s*'",
328+
"\\[comment\\]:\\s+#\\s+'test start\\s*(.*?)\\s*'",
329+
// CommonMark comment syntax with double quotes: [comment]: # "test ..."
330+
// Uses (?:[^"\\\\]|\\\\.)* to handle escaped quotes within the content
331+
'\\[comment\\]:\\s+#\\s+"test\\s*((?:[^"\\\\]|\\\\.)*)\\s*"',
332+
'\\[comment\\]:\\s+#\\s+"test start\\s*((?:[^"\\\\]|\\\\.)*)\\s*"',
325333
],
326334
testEnd: [
327335
"{\\/\\*\\s*test end\\s*\\*\\/}",
328336
"<!--\\s*test end\\s*([\\s\\S]*?)\\s*-->",
337+
// CommonMark comment syntax with parentheses
329338
"\\[comment\\]:\\s+#\\s+\\(test end\\)",
339+
// CommonMark comment syntax with single quotes
340+
"\\[comment\\]:\\s+#\\s+'test end'",
341+
// CommonMark comment syntax with double quotes
342+
'\\[comment\\]:\\s+#\\s+"test end"',
330343
],
331344
ignoreStart: [
332345
"{\\/\\*\\s*test ignore start\\s*\\*\\/}",
333346
"<!--\\s*test ignore start\\s*-->",
347+
// CommonMark comment syntax with parentheses
348+
"\\[comment\\]:\\s+#\\s+\\(test ignore start\\)",
349+
// CommonMark comment syntax with single quotes
350+
"\\[comment\\]:\\s+#\\s+'test ignore start'",
351+
// CommonMark comment syntax with double quotes
352+
'\\[comment\\]:\\s+#\\s+"test ignore start"',
334353
],
335354
ignoreEnd: [
336355
"{\\/\\*\\s*test ignore end\\s*\\*\\/}",
337356
"<!--\\s*test ignore end\\s*-->",
357+
// CommonMark comment syntax with parentheses
358+
"\\[comment\\]:\\s+#\\s+\\(test ignore end\\)",
359+
// CommonMark comment syntax with single quotes
360+
"\\[comment\\]:\\s+#\\s+'test ignore end'",
361+
// CommonMark comment syntax with double quotes
362+
'\\[comment\\]:\\s+#\\s+"test ignore end"',
338363
],
339364
step: [
340365
"{\\/\\*\\s*step\\s+?([\\s\\S]*?)\\s*\\*\\/}",
341366
"<!--\\s*step\\s*([\\s\\S]*?)\\s*-->",
367+
// CommonMark comment syntax with parentheses: [comment]: # (step ...)
342368
"\\[comment\\]:\\s+#\\s+\\(step\\s*(.*?)\\s*\\)",
369+
// CommonMark comment syntax with single quotes: [comment]: # 'step ...'
370+
"\\[comment\\]:\\s+#\\s+'step\\s*(.*?)\\s*'",
371+
// CommonMark comment syntax with double quotes: [comment]: # "step ..."
372+
// Uses (?:[^"\\\\]|\\\\.)* to handle escaped quotes within the content
373+
'\\[comment\\]:\\s+#\\s+"step\\s*((?:[^"\\\\]|\\\\.)*)\\s*"',
343374
],
344375
},
345376
markup: [
@@ -472,7 +503,7 @@ async function setConfig({ config }) {
472503
} catch (error) {
473504
log(
474505
config,
475-
"warn",
506+
"warning",
476507
`Invalid JSON in DOC_DETECTIVE environment variable: ${error.message}. Ignoring config overrides.`
477508
);
478509
}

src/config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("envMerge", function () {
8181

8282
// Should continue normally without applying overrides
8383
expect(validStub.calledOnce).to.be.true;
84-
expect(logStub.calledWith(sinon.match.any, "warn", sinon.match.string)).to.be.true;
84+
expect(logStub.calledWith(sinon.match.any, "warning", sinon.match.string)).to.be.true;
8585
});
8686

8787
it("should handle DOC_DETECTIVE environment variable without config property", async function () {

0 commit comments

Comments
 (0)