mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(packages): support cli:omit markers for llm-only doc content (#1466)
This commit is contained in:
@@ -2,3 +2,8 @@ export function replaceMarker(markdown: string, id: string, replacement: string)
|
||||
const re = new RegExp(`<!-- cli:replace ${id} -->\\n[\\s\\S]*?\\n<!-- /cli:replace ${id} -->`);
|
||||
return markdown.replace(re, () => replacement);
|
||||
}
|
||||
|
||||
export function stripOmitMarkers(markdown: string): string {
|
||||
const re = /\n?<!-- cli:omit \S+ -->\n[\s\S]*?\n<!-- \/cli:omit \S+ -->\n?/g;
|
||||
return markdown.replace(re, '\n');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { replaceMarker } from '../replace.js';
|
||||
import { replaceMarker, stripOmitMarkers } from '../replace.js';
|
||||
|
||||
describe('replaceMarker', () => {
|
||||
it('replaces content between markers', () => {
|
||||
@@ -63,3 +63,57 @@ end`;
|
||||
expect(result).toBe('start\nsingle line\nend');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stripOmitMarkers', () => {
|
||||
it('removes content between omit markers', () => {
|
||||
const markdown = `# Title
|
||||
|
||||
<!-- cli:omit installation -->
|
||||
CLI-only hint
|
||||
<!-- /cli:omit installation -->
|
||||
|
||||
## Footer`;
|
||||
|
||||
const result = stripOmitMarkers(markdown);
|
||||
expect(result).not.toContain('CLI-only hint');
|
||||
expect(result).not.toContain('cli:omit');
|
||||
expect(result).toContain('# Title');
|
||||
expect(result).toContain('## Footer');
|
||||
});
|
||||
|
||||
it('returns unchanged markdown when no markers are present', () => {
|
||||
const markdown = '# Title\n\nSome content';
|
||||
expect(stripOmitMarkers(markdown)).toBe(markdown);
|
||||
});
|
||||
|
||||
it('removes multiple omit blocks with different ids', () => {
|
||||
const markdown = `before
|
||||
<!-- cli:omit one -->
|
||||
alpha
|
||||
<!-- /cli:omit one -->
|
||||
middle
|
||||
<!-- cli:omit two -->
|
||||
beta
|
||||
<!-- /cli:omit two -->
|
||||
after`;
|
||||
|
||||
const result = stripOmitMarkers(markdown);
|
||||
expect(result).not.toContain('alpha');
|
||||
expect(result).not.toContain('beta');
|
||||
expect(result).toContain('before');
|
||||
expect(result).toContain('middle');
|
||||
expect(result).toContain('after');
|
||||
});
|
||||
|
||||
it('handles multiline content inside an omit block', () => {
|
||||
const markdown = `start
|
||||
<!-- cli:omit multi -->
|
||||
line 1
|
||||
line 2
|
||||
line 3
|
||||
<!-- /cli:omit multi -->
|
||||
end`;
|
||||
|
||||
expect(stripOmitMarkers(markdown)).toBe('start\nend');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user