Skip to content

Fixes #50

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 3 commits into from
Jun 25, 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
Next Next commit
ignore leading/trailing white space in validate markdown
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 25, 2020
commit f0efe97e0cc24f2391e306c3efa118d08add7bd3
9 changes: 5 additions & 4 deletions src/utils/validateMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ const codeBlockRegex = /```[a-z]*\n[\s\S]*?\n```/gm;

export function validateMarkdown(md: string): boolean {
// remove codeblocks which might contain any valid combinations
const text = md.replace(codeBlockRegex, "");
// trim white space
const text = md.replace(codeBlockRegex, "").trim();

let valid = true;

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
22 changes: 22 additions & 0 deletions tests/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ Should not be an issue
First Step`;
expect(validateMarkdown(md)).toBe(true);
});
it("should ignore empty space at the top", () => {
const md = `

# Title

Description.`;
expect(validateMarkdown(md)).toBe(true);
});
it("should ignore empty space at the bottom", () => {
const md = `

# Title

Description.





`;
expect(validateMarkdown(md)).toBe(true);
});
});