@bernierllc/validators-content
v1.0.2
Published
Content quality validation - composite validator combining link integrity, image optimization, editorial style, and markdown structure validation
Readme
@bernierllc/validators-content
Content quality validation - composite validator combining link integrity, image optimization, editorial style, and markdown structure validation.
Overview
The validators-content package is a domain validator that orchestrates multiple primitive validators to provide comprehensive content quality assurance. It validates links, images, editorial style, and markdown structure in a single operation.
Installation
npm install @bernierllc/validators-contentFeatures
- Link Integrity: Validates broken links, anchor targets, redirect chains, and protocol consistency
- Image Assets: Checks alt text, image format, file size, dimensions, and srcset
- Editorial Style: Validates inclusive language, brand terms, tone, and readability
- Markdown Structure: Verifies heading hierarchy, link references, list formatting, and code blocks
- Flexible Configuration: Enable/disable individual validators as needed
- Multiple Content Types: Supports markdown, HTML, and plain text
Usage
Basic Example
import { validateContent } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';
const utils = createSharedUtils();
const content = {
markdown: `
# Welcome
Check out [our site](https://example.com)!

`.trim(),
};
const result = await validateContent(content, {}, utils);
if (result.problems.length === 0) {
console.log('Content is valid!');
} else {
result.problems.forEach(problem => {
console.log(`${problem.severity}: ${problem.message}`);
});
}With Custom Options
import { validateContent } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';
const utils = createSharedUtils();
const content = {
html: '<h1>Title</h1><p>Some content with <a href="/docs">link</a></p>',
baseUrl: 'https://mysite.com',
};
const result = await validateContent(content, {
validateLinks: true,
validateImages: true,
validateEditorialStyle: false, // Skip editorial validation
validateMarkdownStructure: false, // Skip markdown validation
maxContentLength: 10000, // Warn if content exceeds 10KB
skipExternalLinks: true, // Don't check external links
}, utils);Using the Validator Factory
import { createContentValidator } from '@bernierllc/validators-content';
import { createSharedUtils } from '@bernierllc/validators-utils';
const utils = createSharedUtils();
// Create a configured validator
const validator = createContentValidator({
validateLinks: true,
validateImages: true,
validateEditorialStyle: true,
validateMarkdownStructure: true,
});
// Get metadata
const meta = validator.getMeta();
console.log('Validator:', meta.name);
console.log('Enabled rules:', meta.enabledRules);
// Validate content
const content = {
text: 'Check out this link: https://example.com',
};
const result = await validator.validate(content, utils);
console.log('Problems found:', result.problems.length);API
validateContent(content, options?, utils)
Validates content using configured validators.
Parameters:
content(ContentInput): Content to validatetext?: string- Plain text contenthtml?: string- HTML contentmarkdown?: string- Markdown contentbaseUrl?: string- Base URL for resolving relative linksfilePath?: string- Source file path (for context)
options?(ContentValidationOptions): Validation optionsvalidateLinks?: boolean- Validate link integrity (default: true)validateImages?: boolean- Validate image assets (default: true)validateEditorialStyle?: boolean- Validate editorial style (default: true)validateMarkdownStructure?: boolean- Validate markdown structure (default: true)severity?: Severity- Severity level for problems (default: 'warn')linkOptions?: Partial<LinkIntegrityOptions>- Options for link validationskipExternalLinks?: boolean- Skip external link checking (default: false)maxContentLength?: number- Maximum content length (default: unlimited)
utils(SharedUtils): Shared utilities from@bernierllc/validators-utils
Returns: Promise<ValidationResult>
createContentValidator(options?)
Creates a configured content validator instance.
Parameters:
options?(ContentValidationOptions): Validation configuration
Returns: Object with:
validate(content, utils)- Validation functiongetMeta()- Metadata function
Content Types
The validator supports three content types:
Markdown Content
const content = {
markdown: '# Title\n\n[Link](https://example.com)\n\n',
};For markdown content:
- Links are extracted from
[text](url)syntax - Images are extracted from
syntax - Markdown structure is validated if enabled
HTML Content
const content = {
html: '<h1>Title</h1><p><a href="https://example.com">Link</a></p>',
};For HTML content:
- Links are extracted from
<a href="...">tags - Images are extracted from
<img src="...">tags - HTML structure is validated through editorial rules
Plain Text Content
const content = {
text: 'Plain text content with no markup.',
};For plain text content:
- Editorial style validation is performed
- Links and images are not extracted
Composed Validators
This domain validator composes four primitive validators:
1. Link Integrity (@bernierllc/validators-link-integrity)
Validates:
- Broken links
- Anchor targets
- Redirect chains
- Protocol consistency
2. Image Asset (@bernierllc/validators-image-asset)
Validates:
- Missing alt text
- Inefficient image format
- Excessive file size
- Excessive dimensions
- Missing srcset
3. Editorial Style (@bernierllc/validators-editorial-style)
Validates:
- Inclusive language
- Brand terms
- Prohibited terms
- Tone validation
- Readability score
4. Markdown Structure (@bernierllc/validators-markdown-structure)
Validates:
- Heading hierarchy
- Link references
- List formatting
- Code block syntax
Configuration Examples
Strict Link Checking
const result = await validateContent(content, {
validateLinks: true,
linkOptions: {
checkBrokenLinks: true,
checkAnchorTargets: true,
checkRedirectChains: true,
checkProtocolConsistency: true,
},
}, utils);Content Length Limits
const result = await validateContent(content, {
maxContentLength: 5000, // Warn if content exceeds 5KB
severity: 'error', // Treat warnings as errors
}, utils);Selective Validation
// Only validate links and images
const result = await validateContent(content, {
validateLinks: true,
validateImages: true,
validateEditorialStyle: false,
validateMarkdownStructure: false,
}, utils);Integration Status
- Logger Integration: Not applicable - Pure validation function with no runtime logging requirements
- Docs-Suite: Ready - Exports markdown documentation
- NeverHub Integration: Not applicable - Stateless validator with no service discovery or event bus requirements
Dependencies
BernierLLC Packages:
@bernierllc/validators-core- Core validation framework@bernierllc/validators-runner- Validation runner@bernierllc/validators-utils- Shared utilities@bernierllc/validators-link-integrity- Link integrity validation@bernierllc/validators-image-asset- Image asset validation@bernierllc/validators-editorial-style- Editorial style validation@bernierllc/validators-markdown-structure- Markdown structure validation
Related Packages
@bernierllc/validators-email- Email content validation@bernierllc/validators-web- Web page validation@bernierllc/validators-api- API specification validation
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
