Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2587efd

Browse files
authored
Merge pull request#32 from coderoad/fix/truncate-first-line
level summary truncate use only first line
2 parentsedbe775 +e294e6b commit2587efd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

‎src/utils/parse.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export function parseMdContent(md: string): TutorialFrame | never {
6969
title:levelTitle.trim(),
7070
summary:levelSummary
7171
?levelSummary.trim()
72-
:truncate(levelContent.trim(),{length:80,omission:"..."}),
72+
:truncate(levelContent.split(/[\n\r]+/)[0].trim(),{
73+
length:80,
74+
omission:"...",
75+
}),
7376
content:levelContent.trim(),
7477
};
7578
current={level:levelId,step:"0"};

‎tests/parse.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,37 @@ Some text that becomes the summary and goes beyond the maximum length of 80 so t
166166
expect(result.levels[0].summary).toMatch(/\.\.\.$/);
167167
});
168168

169+
it("should only truncate the first line of a level description",()=>{
170+
constmd=`# Title
171+
172+
Description.
173+
174+
## L1 Put Level's title here
175+
176+
Some text.
177+
178+
But not including this line.
179+
`;
180+
181+
constskeleton={levels:[{id:"L1"}]};
182+
constresult=parse({
183+
text:md,
184+
skeleton,
185+
commits:{},
186+
});
187+
constexpected={
188+
levels:[
189+
{
190+
id:"L1",
191+
title:"Put Level's title here",
192+
summary:"Some text.",
193+
content:"Some text.\n\nBut not including this line.",
194+
},
195+
],
196+
};
197+
expect(result.levels[0].summary).toEqual("Some text.");
198+
});
199+
169200
it("should match line breaks with double line breaks for proper spacing",()=>{
170201
constmd=`# Title
171202

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp