tarsec 0.3.0 → 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.
|
@@ -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,
|
|
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
|
-
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
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
|
-
|
|
21
|
+
many(blockEntry),
|
|
20
22
|
optional(spaces),
|
|
21
23
|
], (r) => {
|
|
22
24
|
const fm = r[0];
|
|
@@ -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
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
|
|
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(", "alt"
|
|
|
219
225
|
});
|
|
220
226
|
export const hardBreakParser = map(or(
|
|
221
227
|
// two-or-more trailing spaces then newline
|
|
222
|
-
|
|
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
|