Skip to content

fix Inconsistent parsing of number list with non-plain text #1755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"build:vite": "vite build",
"prepare": "npm run build",
"test": "vitest run --coverage",
"test:update": "vitest run --updateSnapshot --no-cache",
"test:update": "vitest run -u",
"lint": "run-p lint:*",
"lint:biome": "biome check .",
"lint:tsc": "tsc -p ./tsconfig.lint.json",
Expand Down
2 changes: 1 addition & 1 deletion src/block/node/NumberListNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const createNumberListNode: NodeCreator<NumberListNode | PlainNode> = (
raw,
rawNumber,
number,
nodes: convertToNodes(text, { ...opts, nested: true }),
nodes: convertToNodes(text, { ...opts, nested: false }),
},
];
};
Expand Down
2 changes: 1 addition & 1 deletion src/block/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const convertToNodes: ReturnType<typeof combineNodeParsers> =
FalsyEliminator,
QuoteNodeParser,
HelpfeelNodeParser,
NumberListNodeParser,
CodeNodeParser,
CommandLineNodeParser,
FormulaNodeParser,
Expand All @@ -65,5 +66,4 @@ export const convertToNodes: ReturnType<typeof combineNodeParsers> =
GoogleMapNodeParser,
InternalLinkNodeParser,
HashTagNodeParser,
NumberListNodeParser,
);
58 changes: 58 additions & 0 deletions tests/line/__snapshots__/numberList.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`numberList > 1. with code 1`] = `
[
{
"indent": 0,
"nodes": [
{
"nodes": [
{
"raw": "\`code\`",
"text": "code",
"type": "code",
},
],
"number": 1,
"raw": "1. \`code\`",
"rawNumber": "1",
"type": "numberList",
},
],
"type": "line",
},
]
`;

exports[`numberList > 1. with decoration 1`] = `
[
{
"indent": 0,
"nodes": [
{
"nodes": [
{
"decos": [
"*-1",
],
"nodes": [
{
"raw": "deco",
"text": "deco",
"type": "plain",
},
],
"raw": "[* deco]",
"rawDecos": "*",
"type": "decoration",
},
],
"number": 1,
"raw": "1. [* deco]",
"rawNumber": "1",
"type": "numberList",
},
],
"type": "line",
},
]
`;

exports[`numberList > 1. with no space is not numberList 1`] = `
[
{
Expand Down
8 changes: 8 additions & 0 deletions tests/line/numberList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ describe("numberList", () => {
).toMatchSnapshot();
});

it("1. with decoration", () => {
expect(parse("1. [* deco]", { hasTitle: false })).toMatchSnapshot();
});

it("1. with code", () => {
expect(parse("1. `code`", { hasTitle: false })).toMatchSnapshot();
});

it("1. with no space is not numberList", () => {
expect(
parse("1.not numberList", {
Expand Down
Loading