tarsec 0.3.1 → 0.3.2

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.
@@ -2,11 +2,17 @@ import { seqC, seqR, capture, captureCaptures, or, not, map, many, many1, many1T
2
2
  import { str, char, eof, set, oneOf, alphanum, noneOf, digit, letter, anyChar } from "../../parsers.js";
3
3
  import { success, failure } from "../../types.js";
4
4
  import { optional, between } from "../../combinators.js";
5
- // Stop inline-text at any single delimiter char OR at a hard-break sequence
6
- // (" \n"+). Using many1Till with an `or` of delimiters makes the stop set
7
- // composable rather than embedded inside a regex. `]` is included so that
8
- // inline-text inside a link-text (`[...]`) terminates at the closing `]`.
9
- const inlineTextStop = or(oneOf("*_`[]!<~\\&\n"), str(" "));
5
+ // The "two-or-more trailing spaces then `\n`" half of a hard break. Shared
6
+ // between `hardBreakParser` (which emits the hard-break node) and
7
+ // `inlineTextStop` (which uses it to know where to stop). Keeping these in
8
+ // sync matters: if the run pattern here disagreed with what `hardBreakParser`
9
+ // accepts, inline-text could either swallow a real hard break or — as the
10
+ // previous `str(" ")` did — stop on any incidental double-space (e.g. a
11
+ // 2-space line indent inside a list-item continuation) and freeze the
12
+ // surrounding paragraph at zero progress.
13
+ const hardBreakSpaces = seqR(str(" "), many(char(" ")), char("\n"));
14
+ // `]` is included so inline-text inside a link-text (`[...]`) ends at the `]`.
15
+ const inlineTextStop = or(oneOf("*_`[]!<~\\&\n"), hardBreakSpaces);
10
16
  export const inlineTextParser = map(many1Till(inlineTextStop), (content) => ({ type: "inline-text", content }));
11
17
  /**
12
18
  * Run `inlineMarkdownParser` repeatedly until `stop` would match at the
@@ -219,7 +225,7 @@ export const imageParser = map(seqC(str("!["), capture(iManyTillStr("]("), "alt"
219
225
  });
220
226
  export const hardBreakParser = map(or(
221
227
  // two-or-more trailing spaces then newline
222
- seqR(str(" "), many(char(" ")), char("\n")),
228
+ hardBreakSpaces,
223
229
  // backslash then newline
224
230
  seqR(char("\\"), char("\n"))), () => ({ type: "inline-hard-break" }));
225
231
  /** A single `\n` that is *not* part of a blank line (which would terminate the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsec",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A parser combinator library for TypeScript, inspired by Parsec.",
5
5
  "homepage": "https://github.com/egonSchiele/tarsec",
6
6
  "scripts": {