tarsec 0.3.0 → 0.3.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.
@@ -3,20 +3,22 @@ export * from "./inline.js";
3
3
  export * from "./blocks.js";
4
4
  export * from "./references.js";
5
5
  export * from "./frontmatter.js";
6
- import { seq, sepBy, or, optional, many1, map } from "../../combinators.js";
6
+ import { seq, or, optional, many, capture, seqC, map } from "../../combinators.js";
7
7
  import { spaces, newline } from "../../parsers.js";
8
8
  import { headingParser, codeBlockParser, blockQuoteParser, paragraphParser, imageParser, horizontalRuleParser, setextHeadingParser, indentedCodeBlockParser, listParser, tableParser, htmlBlockParser, } from "./blocks.js";
9
9
  import { linkDefinitionParser, footnoteDefinitionParser, resolveReferences, } from "./references.js";
10
10
  import { frontmatterParser } from "./frontmatter.js";
11
- // Block separator: one or more newlines (with optional trailing horizontal
12
- // whitespace). Crucially this does NOT consume leading indentation on the
13
- // next block so a 4-space indented code block isn't dewhitespaced before
14
- // indentedCodeBlockParser ever sees it.
15
- const blockSeparator = many1(newline);
11
+ const blockAlt = or(setextHeadingParser, horizontalRuleParser, headingParser, codeBlockParser, indentedCodeBlockParser, tableParser, blockQuoteParser, listParser, htmlBlockParser, linkDefinitionParser, footnoteDefinitionParser, paragraphParser, imageParser);
12
+ // A block followed by zero-or-more trailing newlines. Blocks differ in whether
13
+ // they consume their own terminating "\n" (e.g. headingParser does, codeBlock
14
+ // doesn't), so we can't use sepBy(many1(newline), block) — it would fail to
15
+ // separate two blocks when the first already ate its newline (e.g. a heading
16
+ // directly followed by a list with no intervening blank line).
17
+ const blockEntry = map(seqC(capture(blockAlt, "b"), many(newline)), ({ b }) => b);
16
18
  const _markdownParser = seq([
17
19
  optional(frontmatterParser),
18
20
  optional(spaces),
19
- sepBy(blockSeparator, or(setextHeadingParser, horizontalRuleParser, headingParser, codeBlockParser, indentedCodeBlockParser, tableParser, blockQuoteParser, listParser, htmlBlockParser, linkDefinitionParser, footnoteDefinitionParser, paragraphParser, imageParser)),
21
+ many(blockEntry),
20
22
  optional(spaces),
21
23
  ], (r) => {
22
24
  const fm = r[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsec",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "A parser combinator library for TypeScript, inspired by Parsec.",
5
5
  "homepage": "https://github.com/egonSchiele/tarsec",
6
6
  "scripts": {