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

Commit8ba4877

Browse files
committed
update markdown validation
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent504103a commit8ba4877

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

‎src/utils/validateMarkdown.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ const validations: Validation[] = [
2424
},
2525
},
2626
{
27-
message:"should have a level `##` with a format of `L[0-9]+`",
27+
message:"should have a level `##` with a format of `[0-9]+.`",
2828
validate:(t)=>{
2929
constheaders=t.match(/^#{2}\s(.+)$/gm)||[];
3030
for(constheaderofheaders){
31-
if(!header.match(/^#{2}\s(L\d+)\s(.+)$/)){
31+
if(!header.match(/^#{2}\s(\d+\.)\s(.+)$/)){
3232
returnfalse;
3333
}
3434
}
3535
returntrue;
3636
},
3737
},
3838
{
39-
message:"should have a step `###` with a format of `L[0-9]+S[0-9]+`",
39+
message:"should have a step `###` with a format of `[0-9].[0-9]+`",
4040
validate:(t)=>{
4141
constheaders=t.match(/^#{3}\s(.+)$/gm)||[];
4242
for(constheaderofheaders){
43-
if(!header.match(/^#{3}\s(L\d+)S\d+/)){
43+
if(!header.match(/^#{3}\s(\d+\.\d+)/)){
4444
returnfalse;
4545
}
4646
}
@@ -60,9 +60,9 @@ export function validateMarkdown(md: string): boolean {
6060
for(constvofvalidations){
6161
if(!v.validate(text)){
6262
valid=false;
63-
if(process.env.NODE_ENV!=="test"){
64-
console.warn(v.message);
65-
}
63+
//if (process.env.NODE_ENV !== "test") {
64+
console.warn(v.message);
65+
//}
6666
}
6767
}
6868

‎tests/markdown.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe("validate markdown", () => {
55
constmd=`
66
Description.
77
8-
## Put Level's title here
8+
##1.Put Level's title here
99
1010
> Level's summary: a short description of the level's content in one line.
1111
@@ -19,7 +19,7 @@ Description.
1919
2020
# Another Title
2121
22-
## Put Level's title here
22+
##1.Put Level's title here
2323
2424
> Level's summary: a short description of the level's content in one line.
2525
@@ -29,7 +29,7 @@ Some text that describes the level`;
2929
Description.
3030
3131
32-
## Put Level's title here
32+
##1.Put Level's title here
3333
3434
> Level's summary: a short description of the level's content in one line.
3535
@@ -45,7 +45,7 @@ Some text that describes the level
4545
it("should return false if missing a summary description",()=>{
4646
constmd=`# A Title
4747
48-
## Put Level's title here
48+
##1.Put Level's title here
4949
5050
> Level's summary: a short description of the level's content in one line.
5151
@@ -79,24 +79,25 @@ A description
7979
8080
Some text that describes the level
8181
82-
###A Step
82+
###Missing step id
8383
8484
First step
8585
`;
86+
expect(validateMarkdown(md)).toBe(false);
8687
});
8788

8889
it("should return true for valid markdown",()=>{
8990
constmd=`# Title
9091
9192
Description.
9293
93-
## Put Level's title here
94+
##1.Put Level's title here
9495
9596
> Level's summary: a short description of the level's content in one line.
9697
9798
Some text that describes the level
9899
99-
###Step1
100+
###1.1
100101
101102
First Step`;
102103
expect(validateMarkdown(md)).toBe(true);
@@ -114,19 +115,19 @@ Should not be a problem
114115
\`\`\`
115116
116117
117-
## Put Level's title here
118+
##1.Put Level's title here
118119
119120
> Level's summary: a short description of the level's content in one line.
120121
121122
Some text that describes the level
122123
123124
\`\`\`
124-
## Another Level in markdown
125+
##2.Another Level in markdown
125126
126127
Should not be an issue
127128
\`\`\`
128129
129-
###Step1
130+
###1.1
130131
131132
First Step`;
132133
expect(validateMarkdown(md)).toBe(true);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp