or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdindex.mdlanguages.mdprocessor.mdrules.md
tile.json

languages.mddocs/

Languages

Language implementations for parsing and processing Markdown files with support for CommonMark and GitHub Flavored Markdown formats, including frontmatter parsing capabilities.

Capabilities

MarkdownLanguage Class

Language implementation for parsing Markdown content into AST (Abstract Syntax Tree) format.

/**
 * Language implementation for Markdown parsing
 * Supports CommonMark and GitHub Flavored Markdown formats
 */
class MarkdownLanguage {
  /**
   * The type of file to read
   */
  fileType: "text";

  /**
   * The line number at which the parser starts counting
   */
  lineStart: 1;

  /**
   * The column number at which the parser starts counting
   */
  columnStart: 1;

  /**
   * The name of the key that holds the type of the node
   */
  nodeTypeKey: "type";

  /**
   * Default language options
   */
  defaultLanguageOptions: MarkdownLanguageOptions;

  /**
   * Creates a new MarkdownLanguage instance
   * @param options - Configuration options for the language
   */
  constructor(options?: { mode?: "commonmark" | "gfm" });

  /**
   * Validates the language options
   * @param languageOptions - The language options to validate
   * @throws {Error} When the language options are invalid
   */
  validateLanguageOptions(languageOptions: MarkdownLanguageOptions): void;

  /**
   * Parses the given file into an AST
   * @param file - The virtual file to parse
   * @param context - Language context with options
   * @returns Parse result with AST root node
   */
  parse(
    file: File,
    context: MarkdownLanguageContext
  ): ParseResult<Root>;

  /**
   * Creates a new MarkdownSourceCode object from the given information
   * @param file - The virtual file to create a MarkdownSourceCode object from
   * @param parseResult - The result returned from parse()
   * @returns The new MarkdownSourceCode object
   */
  createSourceCode(
    file: File,
    parseResult: OkParseResult<Root>
  ): MarkdownSourceCode;
}

CommonMark Language

Language instance configured for CommonMark format parsing.

/**
 * Pre-configured MarkdownLanguage instance for CommonMark format
 * Accessible as markdown.languages.commonmark
 */
const commonmark: MarkdownLanguage;

Usage Example:

import markdown from "@eslint/markdown";

export default [
    {
        files: ["**/*.md"],
        plugins: { markdown },
        language: "markdown/commonmark",
        rules: {
            "markdown/heading-increment": "error"
        }
    }
];

GitHub Flavored Markdown Language

Language instance configured for GitHub Flavored Markdown (GFM) format parsing.

/**
 * Pre-configured MarkdownLanguage instance for GitHub Flavored Markdown format
 * Supports GFM extensions like tables, strikethrough, and task lists
 * Accessible as markdown.languages.gfm
 */
const gfm: MarkdownLanguage;

Usage Example:

import markdown from "@eslint/markdown";

export default [
    {
        files: ["**/*.md"],
        plugins: { markdown },
        language: "markdown/gfm",
        rules: {
            "markdown/table-column-count": "error"
        }
    }
];

Language Options

Configuration options for Markdown language parsing.

/**
 * Language options for Markdown parsing
 */
interface MarkdownLanguageOptions {
  /**
   * Enable frontmatter parsing
   * @default false
   */
  frontmatter?: false | "yaml" | "toml" | "json";
}

Usage Examples:

// Enable YAML frontmatter parsing
export default [
    {
        files: ["**/*.md"],
        plugins: { markdown },
        language: "markdown/gfm",
        languageOptions: {
            frontmatter: "yaml"
        }
    }
];
// Enable TOML frontmatter parsing
export default [
    {
        files: ["**/*.md"],
        plugins: { markdown },
        language: "markdown/commonmark",
        languageOptions: {
            frontmatter: "toml"
        }
    }
];
// Enable JSON frontmatter parsing
export default [
    {
        files: ["**/*.md"],
        plugins: { markdown },
        language: "markdown/gfm",
        languageOptions: {
            frontmatter: "json"
        }
    }
];

Language Context

Context object passed to language methods containing configuration and options.

/**
 * Context object for Markdown language operations
 */
interface MarkdownLanguageContext {
  /**
   * Language-specific options
   */
  languageOptions: MarkdownLanguageOptions;

  /**
   * File information
   */
  file?: {
    path: string;
  };
}

Parse Results

Result types returned by the language parser.

/**
 * Successful parse result containing AST
 */
interface OkParseResult<T> {
  ok: true;
  ast: T;
}

/**
 * Parse error result
 */
interface ErrorParseResult {
  ok: false;
  error: Error;
}

type ParseResult<T> = OkParseResult<T> | ErrorParseResult;

/**
 * Virtual file representation
 */
interface File {
  path: string;
  body: string | Uint8Array;
}

Types

AST Node Types

The language parser produces AST nodes following the mdast specification with extensions.

/**
 * Root AST node representing the entire document
 */
interface Root {
  type: "root";
  children: Array<BlockContent | DefinitionContent>;
}

/**
 * Heading node (# ## ### etc.)
 */
interface Heading {
  type: "heading";
  depth: 1 | 2 | 3 | 4 | 5 | 6;
  children: PhrasingContent[];
}

/**
 * Paragraph node
 */
interface Paragraph {
  type: "paragraph";
  children: PhrasingContent[];
}

/**
 * Code block node
 */
interface Code {
  type: "code";
  lang?: string;
  meta?: string;
  value: string;
}

/**
 * Link node
 */
interface Link {
  type: "link";
  url: string;
  title?: string;
  children: StaticPhrasingContent[];
}

/**
 * Image node
 */
interface Image {
  type: "image";
  url: string;
  title?: string;
  alt?: string;
}

/**
 * HTML node
 */
interface Html {
  type: "html";
  value: string;
}

/**
 * Table node (GFM extension)
 */
interface Table {
  type: "table";
  align?: ("left" | "right" | "center" | null)[];
  children: TableRow[];
}

/**
 * Table row node (GFM extension)
 */
interface TableRow {
  type: "tableRow";
  children: TableCell[];
}

/**
 * Table cell node (GFM extension)
 */
interface TableCell {
  type: "tableCell";
  children: PhrasingContent[];
}

/**
 * YAML frontmatter node
 */
interface Yaml {
  type: "yaml";
  value: string;
}

/**
 * TOML frontmatter node (custom extension)
 */
interface Toml {
  type: "toml";
  value: string;
  data?: TomlData;
}

/**
 * JSON frontmatter node (custom extension)
 */
interface Json {
  type: "json";
  value: string;
  data?: JsonData;
}

Content Types

type BlockContent =
  | Blockquote
  | Code
  | Heading
  | Html
  | List
  | Paragraph
  | Table
  | ThematicBreak;

type PhrasingContent =
  | Break
  | Emphasis
  | Html
  | Image
  | ImageReference
  | InlineCode
  | Link
  | LinkReference
  | Strong
  | Text;

type DefinitionContent = Definition | FootnoteDefinition;

interface TomlData {
  [key: string]: any;
}

interface JsonData {
  [key: string]: any;
}

Frontmatter Support

The plugin supports parsing frontmatter in three formats:

YAML Frontmatter

---
title: My Document
date: 2024-01-01
---

# Content here

TOML Frontmatter

+++
title = "My Document"
date = 2024-01-01
+++

# Content here

JSON Frontmatter

---
{
  "title": "My Document",
  "date": "2024-01-01"
}
---

# Content here