Extractor Plugins
Extractor plugins are the core components that extract documentation content from source files. They provide flexible ways to identify and extract documentation using different methods.
Table of Contents
Built-in Plugins Documentation
Source Code Links
- /src/simple-docs-scraper/plugins/TagExtractorPlugin.ts
- /src/simple-docs-scraper/plugins/RegexExtractorPlugin.ts
- /src/simple-docs-scraper/plugins/CallbackExtractorPlugin.ts
- /src/simple-docs-scraper/plugins/CopyContentsPlugin.ts
Example Builder Pattern Configuration
const service = SimpleDocExtractor
.create(process.cwd())
.target((target) => {
target.plugins([
new TagExtractorPlugin({
tag: 'docs',
searchAndReplace: '%docs%'
})
])
})
.buildService();
await service.start();
Using Extractor Plugins Directly
Plugins are used through the DocumentContentExtractor
class:
import { DocumentContentExtractor } from 'simple-docs-scraper/extractors';
import { TagExtractorPlugin } from 'simple-docs-scraper/extractors';
// Single plugin
const extractor = new DocumentContentExtractor([
new TagExtractorPlugin({
tag: 'docs',
searchAndReplace: '<!-- DOCS -->'
})
]);
// Multiple plugins
const extractor = new DocumentContentExtractor([
new TagExtractorPlugin({
tag: 'docs',
searchAndReplace: '<!-- DOCS -->'
}),
new RegexExtractorPlugin({
pattern: /\/\*\*([\s\S]*?)\*\//g,
searchAndReplace: '/* DOCS */'
})
]);
// Extract from file
const results = await extractor.extractFromFile('example.js');
// Extract from string
const results = await extractor.extractFromString(fileContent);