@markdown-code-assist/core
v0.1.0
Published
Core engine for scanning, linting, and formatting fenced code blocks inside Markdown files.
Maintainers
Readme
@markdown-code-assist/core
Editor-independent engine for scanning, linting, and formatting fenced code blocks inside Markdown files.
This is the core engine that powers the @markdown-code-assist/cli package and can be embedded in any Node.js program, editor extension, LSP adapter, or CI pipeline.
Installation
npm install @markdown-code-assist/coreUsage
import { lintMarkdown, formatMarkdown, analyzeMarkdown } from '@markdown-code-assist/core';
const source = `
# Guide
\`\`\`python
def greet(name)
print("Hello, " + name)
\`\`\`
\`\`\`python
x = [1, 2, 3
print(x)
\`\`\`
`;
// Lint — returns diagnostics with Markdown-level positions
const { diagnostics } = lintMarkdown(source);
// [{ language: 'python', message: 'SyntaxError: invalid syntax', line: 4, column: 15, severity: 'error' }]
// Format — returns the full Markdown with code blocks reformatted
const { formattedMarkdown, changed } = formatMarkdown(source);
// Analyze — returns block metadata + diagnostics + diffs in one call
const { blocks, diagnostics: all } = analyzeMarkdown(source);API
lintMarkdown(source: string, config?: CoreConfig): LintMarkdownResult
Scans all fenced code blocks and returns diagnostics. Positions are in Markdown document coordinates.
formatMarkdown(source: string, config?: CoreConfig): FormatMarkdownResult
Returns the full Markdown source with every formattable code block reformatted. The original source is unchanged if changed is false.
analyzeMarkdown(source: string, config?: CoreConfig): AnalyzeMarkdownResult
Combined call — returns discovered blocks, diagnostics, and formatting diffs in one pass.
Supported languages
| Language | Diagnostics | Formatting |
|---|---|---|
| JSON | ✅ | ✅ |
| YAML | ✅ | ✅ |
| JavaScript | ✅ syntax + no-undef | ✅ |
| TypeScript | ✅ syntax + no-undef | ✅ |
| Shell / Bash | ✅ | ✅ safe-only |
| Python | ✅ via Tree-sitter | ✅ safe-only |
| HTML | ✅ via Tree-sitter | ✅ safe-only |
| CSS | ✅ via Tree-sitter | ✅ safe-only |
Configuration
import { lintMarkdown } from '@markdown-code-assist/core';
const result = lintMarkdown(source, {
formatting: { tabSize: 2, insertFinalNewline: true },
languages: {
python: { diagnosticsEnabled: true, formattingEnabled: true },
json: { diagnosticsEnabled: true, formattingEnabled: true },
},
});Links
License
MIT © Faouzi Boussad
