mirror of
https://github.com/willchen96/mike.git
synced 2026-07-06 22:12:10 +02:00
Add local repo contents
This commit is contained in:
parent
65739ef1ce
commit
d9690965b5
176 changed files with 68998 additions and 0 deletions
26
frontend/src/app/components/tabular/citation-utils.ts
Normal file
26
frontend/src/app/components/tabular/citation-utils.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"use client";
|
||||
|
||||
const PAGE_CITATION_RE = /\[\[page:(\d+)\|\|(?:quote:)?((?:[^\[\]]|\[[^\]]*\])+)\]\]/gi;
|
||||
|
||||
export interface ParsedCitation {
|
||||
page: number;
|
||||
quote: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces [[page:n||quote:...]] markers with `§idx§` placeholders.
|
||||
* Returns the processed string and an ordered array of extracted citation data.
|
||||
*/
|
||||
export function preprocessCitations(text: string): {
|
||||
processed: string;
|
||||
citations: ParsedCitation[];
|
||||
} {
|
||||
const citations: ParsedCitation[] = [];
|
||||
PAGE_CITATION_RE.lastIndex = 0;
|
||||
const processed = text.replace(PAGE_CITATION_RE, (_, page, quote) => {
|
||||
const idx = citations.length;
|
||||
citations.push({ page: parseInt(page, 10), quote: quote.trim() });
|
||||
return `§${idx}§`;
|
||||
});
|
||||
return { processed, citations };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue