Validate your Markdown frontmatter data against a JSON schema — remark-lint rule plugin

Overview

remark-lint-frontmatter-schema

NPM ISC License Downloads
VS Code unified
TypeScript Prettier EditorConfig ESLint Renovate PRs Welcome

Validate Markdown frontmatter YAML against an associated JSON schema with this remark-lint rule plugin.

Supports:

  • Types validation, pattern, enumerations,… and all you can get with JSON Schema
  • Code location problems indicator (for IDE to underline)
  • Auto-fixes with suggestions
  • Command Line Interface reporting
  • VS Code integration (see below)
  • Global patterns or in-file schemas associations
  • In JS framework MD / MDX pipelines

Demo

Demo screenshot of frontmatter schema linter 1


Demo screenshot of frontmatter schema linter 2


Demo screenshot of frontmatter schema linter 3

👉   Play with pre-configured ./demo

Quick shallow clone with:

pnpx degit JulianCataldo/remark-lint-frontmatter-schema/demo ./demo

Jump to:


Quick start

Installation

pnpm install -D \
remark remark-cli \
remark-frontmatter \
@julian_cataldo/remark-lint-frontmatter-schema

Remove -D flag for runtime unified MD / MDX pipeline (custom, Astro, Gatsby, etc.), for production.
Keep it if you just want to lint with CLI or your IDE locally, without any production / CI needs.

VS Code (optional)

code --install-extension unifiedjs.vscode-remark

Configuration

CLI / IDE (VS Code) — Static linting

👉   See ./demo folder to get a working, pre-configured, bare project workspace.
You also get example markdown files and associated schema to play with.
Supports remark-cli and/or unifiedjs.vscode-remark extension.

📌   Check out the demo/README.md for bootstrapping it.

Workspace

Create root config file for remark to source from:
touch ./.remarkrc.mjs

Paste this base config:

import remarkFrontmatter from 'remark-frontmatter';
import rlFmSchema from '@julian_cataldo/remark-lint-frontmatter-schema';

const remarkConfig = {
  plugins: [remarkFrontmatter, rlFmSchema],
};
export default remarkConfig;

Schema example

./content/creative-work.schema.yaml

type: object
properties:
  title:
    type: string
#

Schemas associations

Inspired by VS Code JSON Schema and redhat.vscode-yaml conventions.

Inside frontmatter

See ./demo/content files for examples.

Schema association can be done directly inside the frontmatter of the markdown file, relative to project root, thanks to the '$schema' key:

---
'$schema': /content/creative-work.schema.yaml

title: Hello there
category: Book
#
---

# You're welcome!

🌝  My **markdown** content…  🌚
…
🆕   Globally, with patterns

Note:
Locally defined '$schema' takes precedence over global settings below.

const remarkConfig = {
  plugins: [
    remarkFrontmatter,
    [
      rlFmSchema,
      {
        schemas: {
          /* One schema for many files */
          './content/creative-work.schema.yaml': [
            /* Support glob patterns */
            './content/*-creative-work.md',
            /* Or direct file association */
            './content/the-one.md',
          ],
          './content/ghost.schema.yaml': [
            './content/casper.md',
            './content/ether.md',
          ],
        },
      },
    ],
  ],
};

'./foo', '/foo', 'foo', all will work.
It's always relative to your ./.remarkrc.mjs file, in your workspace root.

CLI usage

Linting whole workspace files (as ./**/*.md) with remark-cli:

pnpm remark .

Yields:

#
content/correct-creative-work.md
  1:1  warning  /category: Must be equal to one of the allowed values  frontmatter-schema  remark-lint
  1:1  warning  /complex/some: Must be string                          frontmatter-schema  remark-lint

⚠ 6 warnings

MD / MDX pipeline — Runtime validation

Use it as usual like any remark plugin inside your framework or your custom unified pipeline.

🆕   Custom pipeline

When processing markdown as single files inside your JS/TS app.

Schema should be provided programmatically like this:

// …
import remarkFrontmatter from 'remark-frontmatter';
import rlFmSchema from '@julian_cataldo/remark-lint-frontmatter-schema';
import type { JSONSchema7 } from 'json-schema';
import { reporter } from 'vfile-reporter';

const mySchema: JSONSchema7 = {
  /* … */
};

const output = await unified()
  // Your pipeline (basic example)
  .use(remarkParse)
  // …
  .use(remarkFrontmatter)

  .use(rlFmSchema, {
    /* Bring your own schema */
    embed: mySchema,
  })

  // …
  .use(remarkRehype)
  .use(rehypeStringify)
  .use(rehypeFormat)
  .process(theRawMarkdownLiteral);

/* `path` is for debugging purpose here, as MD literal comes from your app. */
output.path = './the-current-processed-md-file.md';

console.error(reporter([output]));

Yields:

./the-current-processed-md-file.md
  1:1  warning  Must have required property 'tag'  frontmatter-schema  remark-lint

⚠ 1 warning
Implementation living example

Checkout content-maestro repository.
It's a text based, structured content framework, for edition and consumption.
Content-Maestro relies on this library for providing file or API based linting errors logs.

You can see remark-lint-frontmatter-schema in action, on this line, in content-maestro source.

Important foot-notes for custom pipeline

This is different from static linting, with VS Code extension or CLI.
It will not source .remarkrc (but you can source it by your own means, if you want).
In fact, it's not aware of your file structure, nor it will associate or import any schema / markdown files.
That way, it will integrate easier with your own business logic.
I found that static linting (during editing) / and runtime validation are two different uses cases enough to separate them in their setups, but I might converge them partially.

Framework

Warning
WIP. NOT tested yet!

See global patterns schemas associations for settings reference.

Astro

In astro.config.mjs

// …
export default defineConfig({
  // …
  remarkPlugins: [
    // …
    'remark-frontmatter',
    ['@julian_cataldo/remark-lint-frontmatter-schema', { schemas }],
    // …
  ];
  // …
});
Gatsby

In gatsby-config.js

{
  // …
  plugins: [
    // …
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          // …
          'remark-frontmatter',
          ['@julian_cataldo/remark-lint-frontmatter-schema', { schemas }],
          // …
        ],
      },
    },
    // …
  ];
}

Using:

Major dependencies:

ajv, yaml, remark, remark-frontmatter, unified, remark-cli


See CHANGELOG.md for release history.


🔗   JulianCataldo.com

Comments
Releases(v3.15.1)
Owner
Julian Cataldo
Transmedia design with code.
Julian Cataldo
This project will be using various AI and Rule Engine algorithm to detect various attack against a company!

?? Introduction This project will be using various AI and Rule Engine algorithm to detect various attack against a website! ?? Mission After starting

Harish S.G 4 Apr 29, 2022
Obsidian plugin that adds autocomplete and auto-formatting to frontmatter tags.

Obsidian Front Matter Tag Wizard Tired of having to type # to get tag autocompletion in your Obsidian note front matter? I feel your pain. This plugin

Eric 10 Nov 5, 2022
JSON Struct is a vocabulary that allows you to annotate and validate JSON documents.

JSON-Struct JSON Struct is a vocabulary that allows you to annotate and validate JSON documents. Examples Basic This is a simple example of vocabulary

Saman 3 May 8, 2022
JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

JSON Visio is data visualization tool for your json data which seamlessly illustrates your data on graphs without having to restructure anything, paste directly or import file.

Aykut Saraç 20.6k Jan 4, 2023
This is a tic-tac-toe game but differs from most others as it carries the option of playing against an AI (COM) or against a friend.

TIC-TAC-TOE This is a simple tic-tac-toe game with the exception of playing against an algorithm or against a friend. At the very start, you have to s

Paul Ibeabuchi C. 4 Jul 2, 2022
A new Node.js resource built using Gatsby.js with React.js, TypeScript, and Remark.

Nodejs.dev Nodejs.dev site built using Gatsby.js with React.js, TypeScript, SCSS, and Remark. You can find the latest Figma design protype here. ?? Ge

Node.js 2.2k Jan 5, 2023
A simple CLI to generate a starter schema for keystone-6 from a pre-existing prisma schema.

Prisma2Keystone A tool for converting prisma schema to keystone schema typescript This is a proof of concept. More work is needed Usage npx prisma2key

Brook Mezgebu 17 Dec 17, 2022
A markdown-it plugin that process images through the eleventy-img plugin. Can be used in any projects that uses markdown-it.

markdown-it-eleventy-img A markdown-it plugin that process images through the eleventy-img plugin. Can be used in any projects that use markdown-it. F

null 25 Dec 20, 2022
✏️ A small jQuery extension to turn a static HTML table into an editable one. For quickly populating a small table with JSON data, letting the user modify it with validation, and then getting JSON data back out.

jquery-editable-table A small jQuery extension to turn an HTML table editable for fast data entry and validation Demo ?? https://jsfiddle.net/torrobin

Tor 7 Jul 31, 2022
Empty project with configured webpack, type script and es-lint

Empty project template Empty project with configured webpack, typescript and es-lint Easy to use: Download project files Go to project root directory

Kris Casper 56 Dec 20, 2022
lint the npmcli way

@npmcli/lint Lint the npmcli way USAGE This package contains two executable scripts. One for linting your code, and the other for automatically settin

npm 27 Aug 11, 2022
Free, open-source client or server-side APIs to "lint" user input.

passbird Free, open-source client or server-side APIs to lint user input. Right now, you can check type for an email address i.e., either of disposabl

Vaibhav Pandey 1 Dec 26, 2021
A Nextjs-Typescript boilerplate , configured with Tailwindcss, Eslint, Prettier, Lint-staged ,Husky and commitizen

Minimal Nextjs Typescript boilerplate A Minimal Next-Typescript boilerplate to quickly and easily bootstrap your next project. Comes pre-configured wi

TEYIM ASOBO 3 Nov 4, 2022
typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

fast-typescript-to-jsonschema English | 简体中文 a tool generate json schema from typescript. Feature compile Typescript to get all type information conve

yunfly 21 Nov 28, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (洪 民憙) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
A plugin for the Obsidian markdown note application, adding functionality to render markdown documents with multiple columns of text.

Multi-Column Markdown Take your boring markdown document and add some columns to it! With Multi Column Markdown rather than limiting your document lay

Cameron Robinson 91 Jan 2, 2023
An obsidian plugin for uploading local images embedded in markdown to remote store and export markdown for publishing to static site.

Obsidian Publish This plugin cloud upload all local images embedded in markdown to specified remote image store (support imgur only, currently) and ex

Addo.Zhang 7 Dec 13, 2022
The one DAO to rule them all. A modular DAO written in Clarity for the Stacks blockchain.

ExecutorDAO The one DAO to rule them all. ExecutorDAO is designed to be completely modular and flexible, leveraging Clarity to the fullest extent. The

Marvin 31 Oct 5, 2022