@minamorl/markdown-next 2.2.1 → 2.2.3

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 (2) hide show
  1. package/lib/src/parser.js +12 -8
  2. package/package.json +12 -12
package/lib/src/parser.js CHANGED
@@ -155,23 +155,25 @@ class Parser {
155
155
  return content.trim();
156
156
  };
157
157
  // Table parser
158
- const table = P.seqMap(tableRowLine.skip(linebreak), tableRowLine.skip(linebreak), tableRowLine.skip(linebreak.atMost(1)).atLeast(0), (headerLine, sepLine, bodyLines) => {
158
+ // Use .chain() for validation instead of returning P.makeFailure from seqMap callback,
159
+ // since seqMap treats the return value as a successful parse result (not a parser control signal).
160
+ const table = P.seq(tableRowLine.skip(linebreak), tableRowLine.skip(linebreak), tableRowLine.skip(linebreak.atMost(1)).atLeast(0)).chain(([headerLine, sepLine, bodyLines]) => {
159
161
  // Validate separator row
160
162
  if (!isSeparatorRow(sepLine)) {
161
- return P.makeFailure(0, 'Not a valid table separator');
163
+ return P.fail('Not a valid table separator');
162
164
  }
163
165
  const headerCells = parseTableRow(headerLine);
164
166
  const bodyCells = bodyLines.map(parseTableRow);
165
167
  if (headerCells.length === 0) {
166
- return P.makeFailure(0, 'No header cells');
168
+ return P.fail('No header cells');
167
169
  }
168
170
  const headerRow = mapper('tr')(join(headerCells.map((h) => mapper('th')(parseCellContent(h)))));
169
171
  const bodyRows = bodyCells.map((row) => mapper('tr')(join(row.map((cell) => mapper('td')(parseCellContent(cell))))));
170
- return mapper('table')(join([headerRow, ...bodyRows]));
172
+ return P.succeed(mapper('table')(join([headerRow, ...bodyRows])));
171
173
  });
172
174
  const inlines = inline.atLeast(1).map(join);
173
175
  const paragraphBegin = inlines;
174
- const paragraphEnd = ignore(/```\n.*\n```/);
176
+ const paragraphEnd = ignore(/```[^`\r\n]*\n[\s\S]*?\n```/);
175
177
  const paragraphLine = P.lazy(() => P.alt(P.seq(paragraphBegin, linebreak.skip(paragraphEnd).result(mapper('br')(null)), paragraphLine).map(join), inlines));
176
178
  const paragraph = paragraphLine.map(mapper('p'));
177
179
  const listIndent = P.string(' ');
@@ -278,9 +280,11 @@ class Parser {
278
280
  const codeBlockBegin = P.regexp(/^```/);
279
281
  const codeBlockEnd = P.regexp(/^```/);
280
282
  const codeBlockDefinitionStr = P.regexp(/[^`\r\n]*/);
281
- const codeBlockStr = P.regexp(/[^\r\n]+/);
282
- const codeBlock = P.seqMap(codeBlockBegin, codeBlockDefinitionStr, linebreak, linebreak.or(codeBlockStr.lookahead(linebreak)).many(), codeBlockEnd, (_1, definition, _2, code, _3) => {
283
- if (code.length > 0) {
283
+ // Match a code line that is NOT a closing fence (``` at start of line)
284
+ const codeBlockStr = P.regexp(/(?!```)[^\r\n]+/);
285
+ const codeBlock = P.seqMap(codeBlockBegin, codeBlockDefinitionStr, linebreak, linebreak.or(codeBlockStr).many(), linebreak.atMost(1), codeBlockEnd, (_1, definition, _2, code, _3, _4) => {
286
+ // Remove trailing linebreak consumed by .many() before the closing fence
287
+ while (code.length > 0 && (code[code.length - 1] === '\n' || code[code.length - 1] === '\r\n' || code[code.length - 1] === '\r' || code[code.length - 1] === '')) {
284
288
  code.pop();
285
289
  }
286
290
  if (definition === '')
package/package.json CHANGED
@@ -3,6 +3,16 @@
3
3
  "description": "Markdown parser with Aozora bunko ruby support and HTML passthrough",
4
4
  "main": "./lib/src/parser.js",
5
5
  "types": "./lib/src/parser.d.ts",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "example": "cd examples && webpack",
9
+ "prepublish": "pnpm run build",
10
+ "test": "pnpm run build && mocha lib/test",
11
+ "lint": "eslint src test",
12
+ "lint:fix": "eslint src test --fix",
13
+ "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
14
+ "format:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'"
15
+ },
6
16
  "author": "minamorl",
7
17
  "license": "MIT",
8
18
  "files": [
@@ -36,15 +46,5 @@
36
46
  "url": "https://github.com/minamorl/markdown-next/issues"
37
47
  },
38
48
  "homepage": "https://github.com/minamorl/markdown-next#readme",
39
- "version": "2.2.1",
40
- "scripts": {
41
- "build": "tsc",
42
- "example": "cd examples && webpack",
43
- "prepublish": "pnpm run build",
44
- "test": "pnpm run build && mocha lib/test",
45
- "lint": "eslint src test",
46
- "lint:fix": "eslint src test --fix",
47
- "format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
48
- "format:check": "prettier --check 'src/**/*.ts' 'test/**/*.ts'"
49
- }
50
- }
49
+ "version": "2.2.3"
50
+ }