Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/markdown as master #48

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 17 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update markdown validation
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Jun 21, 2020
commit 8ba48775ffa5c548f68426146abf0c01a0f062da
14 changes: 7 additions & 7 deletions src/utils/validateMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ const validations: Validation[] = [
},
},
{
message: "should have a level `##` with a format of `L[0-9]+`",
message: "should have a level `##` with a format of `[0-9]+.`",
validate: (t) => {
const headers = t.match(/^#{2}\s(.+)$/gm) || [];
for (const header of headers) {
if (!header.match(/^#{2}\s(L\d+)\s(.+)$/)) {
if (!header.match(/^#{2}\s(\d+\.)\s(.+)$/)) {
return false;
}
}
return true;
},
},
{
message: "should have a step `###` with a format of `L[0-9]+S[0-9]+`",
message: "should have a step `###` with a format of `[0-9].[0-9]+`",
validate: (t) => {
const headers = t.match(/^#{3}\s(.+)$/gm) || [];
for (const header of headers) {
if (!header.match(/^#{3}\s(L\d+)S\d+/)) {
if (!header.match(/^#{3}\s(\d+\.\d+)/)) {
return false;
}
}
Expand All @@ -60,9 +60,9 @@ export function validateMarkdown(md: string): boolean {
for (const v of validations) {
if (!v.validate(text)) {
valid = false;
if (process.env.NODE_ENV !== "test") {
console.warn(v.message);
}
// if (process.env.NODE_ENV !== "test") {
console.warn(v.message);
// }
}
}

Expand Down
21 changes: 11 additions & 10 deletions tests/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("validate markdown", () => {
const md = `
Description.

## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand All @@ -19,7 +19,7 @@ Description.

# Another Title

## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand All @@ -29,7 +29,7 @@ Some text that describes the level`;
Description.


## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand All @@ -45,7 +45,7 @@ Some text that describes the level
it("should return false if missing a summary description", () => {
const md = `# A Title

## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Expand Down Expand Up @@ -79,24 +79,25 @@ A description

Some text that describes the level

### A Step
### Missing step id

First step
`;
expect(validateMarkdown(md)).toBe(false);
});

it("should return true for valid markdown", () => {
const md = `# Title

Description.

## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Some text that describes the level

### Step 1
### 1.1

First Step`;
expect(validateMarkdown(md)).toBe(true);
Expand All @@ -114,19 +115,19 @@ Should not be a problem
\`\`\`


## Put Level's title here
## 1. Put Level's title here

> Level's summary: a short description of the level's content in one line.

Some text that describes the level

\`\`\`
## Another Level in markdown
## 2. Another Level in markdown

Should not be an issue
\`\`\`

### Step 1
### 1.1

First Step`;
expect(validateMarkdown(md)).toBe(true);
Expand Down