Skip to content

Feature/validate markdown #33

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 4 commits into from
Jun 13, 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
add markdown validation to build script
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 13, 2020
commit 183a5cd76046956874b82d318ff9d15f5fab21b1
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coderoad/cli",
"version": "0.2.0",
"version": "0.2.1",
"description": "A CLI to build the configuration file for Coderoad Tutorials",
"keywords": [
"coderoad",
Expand All @@ -25,7 +25,7 @@
],
"main": "bin/coderoad",
"bin": {
"@coderoad/coderoad": "bin/coderoad",
"@coderoad/cli": "bin/coderoad",
"coderoad": "bin/coderoad"
},
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getCommits, CommitLogObject } from "./utils/commits";
import skeletonSchema from "./schema/skeleton";
import tutorialSchema from "./schema/tutorial";
import { validateSchema } from "./utils/validateSchema";
import { validateMarkdown } from "./utils/validateMarkdown";
import * as T from "../typings/tutorial";

const write = util.promisify(fs.writeFile);
Expand Down Expand Up @@ -72,6 +73,18 @@ async function build(args: string[]) {
return;
}

// validate markdown loosely
try {
const isValid = validateMarkdown(_markdown);
if (!isValid) {
console.warn("Invalid markdown");
}
} catch (e) {
console.error("Error validating markdown:");
console.error(e.message);
return;
}

// parse yaml skeleton config
let skeleton;
try {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/validateMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const validations: Validation[] = [
message: "should have a level `##` with a format of `L[0-9]+`",
validate: (t) => {
const headers = t.match(/^#{2}\s(.+)$/gm) || [];
console.log("level headers", headers);
for (const header of headers) {
if (!header.match(/^#{2}\s(L\d+)\s(.+)$/)) {
return false;
Expand All @@ -40,7 +39,6 @@ const validations: Validation[] = [
message: "should have a step `###` with a format of `L[0-9]+S[0-9]+`",
validate: (t) => {
const headers = t.match(/^#{3}\s(.+)$/gm) || [];
console.log("step headers", headers);
for (const header of headers) {
if (!header.match(/^#{3}\s(L\d+)S\d+/)) {
return false;
Expand All @@ -62,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