fix(sources-footer): emit [N] format so cite-wide can convert to hex citations

The previous footer used ordered-list style ("1. [Title](URL)"), which
cite-wide's LLM citation parser ignores. Cite-wide's REFDEF_NUM_RE expects
each line to start with [N] (square-bracketed digit), optionally followed by
a colon, then the link.

New format per source:
  [1] [Title](URL)
  [2] [Title](URL)

This matches cite-wide/src/services/llmCitationParserService.ts:91 verbatim,
so running cite-wide's "convert numeric citations to hex" command on a file
generated by this plugin now picks up the footer references and rewrites
them to the project's [^hexId] form.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mpstaton 2026-05-09 16:31:28 -05:00
parent f6fa7e2deb
commit 3575dc168f

View file

@ -63,12 +63,14 @@ function wrapThinkBlocks(text: string): string {
function buildSourcesFooter(sources: PerplexitySource[]): string {
if (!sources.length) return '';
// Format matches cite-wide's REFDEF_NUM_RE (`[N] <content>`) so the
// existing "convert to hex citations" command can process this footer.
// See cite-wide/src/services/llmCitationParserService.ts.
const lines = sources.map((s, i) => {
const n = i + 1;
const title = (typeof s.title === 'string' && s.title) ? s.title : (s.url ?? 'Source');
const url = s.url ?? '';
const date = (typeof s.date === 'string' && s.date) ? ` (${s.date})` : '';
return url ? `${n}. [${title}](${url})${date}` : `${n}. ${title}${date}`;
return url ? `[${n.toString()}] [${title}](${url})` : `[${n.toString()}] ${title}`;
});
return '\n\n## Sources\n\n' + lines.join('\n') + '\n';
}