feat(packages): support cli:omit markers for llm-only doc content (#1466)

This commit is contained in:
Darius Cepulis
2026-04-24 14:56:44 -05:00
committed by GitHub
parent 89594292d4
commit 85e28a5920
6 changed files with 85 additions and 8 deletions
+5
View File
@@ -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');
}
+55 -1
View File
@@ -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');
});
});