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

Commitf0efe97

Browse files
committed
ignore leading/trailing white space in validate markdown
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parenta00362b commitf0efe97

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

‎src/utils/validateMarkdown.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ const codeBlockRegex = /```[a-z]*\n[\s\S]*?\n```/gm;
5353

5454
exportfunctionvalidateMarkdown(md:string):boolean{
5555
// remove codeblocks which might contain any valid combinations
56-
consttext=md.replace(codeBlockRegex,"");
56+
// trim white space
57+
consttext=md.replace(codeBlockRegex,"").trim();
5758

5859
letvalid=true;
5960

6061
for(constvofvalidations){
6162
if(!v.validate(text)){
6263
valid=false;
63-
//if (process.env.NODE_ENV !== "test") {
64-
console.warn(v.message);
65-
//}
64+
if(process.env.NODE_ENV!=="test"){
65+
console.warn(v.message);
66+
}
6667
}
6768
}
6869

‎tests/markdown.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,26 @@ Should not be an issue
132132
First Step`;
133133
expect(validateMarkdown(md)).toBe(true);
134134
});
135+
it("should ignore empty space at the top",()=>{
136+
constmd=`
137+
138+
# Title
139+
140+
Description.`;
141+
expect(validateMarkdown(md)).toBe(true);
142+
});
143+
it("should ignore empty space at the bottom",()=>{
144+
constmd=`
145+
146+
# Title
147+
148+
Description.
149+
150+
151+
152+
153+
154+
`;
155+
expect(validateMarkdown(md)).toBe(true);
156+
});
135157
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp