Skip to content

Commit f0efe97

Browse files
committed
ignore leading/trailing white space in validate markdown
Signed-off-by: shmck <[email protected]>
1 parent a00362b commit f0efe97

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Diff for: src/utils/validateMarkdown.ts

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

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

5859
let valid = true;
5960

6061
for (const v of validations) {
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

Diff for: tests/markdown.test.ts

+22
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+
const md = `
137+
138+
# Title
139+
140+
Description.`;
141+
expect(validateMarkdown(md)).toBe(true);
142+
});
143+
it("should ignore empty space at the bottom", () => {
144+
const md = `
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)