mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-29 01:41:47 +00:00
fix: preserve indented code citations
Signed-off-by: pragnyanramtha <pragnyanramtha@gmail.com>
This commit is contained in:
parent
c525c41051
commit
d524035863
1 changed files with 26 additions and 3 deletions
|
|
@ -90,10 +90,33 @@
|
|||
let sourceIds = [];
|
||||
$: getSourceIds(sources);
|
||||
|
||||
const citationMarkerRegex = /\s*(\[(?:\d+(?:#[^,\]\s]+)?(?:,\s*\d+(?:#[^,\]\s]+)?)*)\])+/g;
|
||||
const indentedCodeLineRegex = /^(?: {4}|\t)/;
|
||||
|
||||
const removeCitationMarkers = (content) => {
|
||||
return replaceOutsideCode(content, (segment) =>
|
||||
segment.replace(/\s*(\[(?:\d+(?:#[^,\]\s]+)?(?:,\s*\d+(?:#[^,\]\s]+)?)*)\])+/g, '')
|
||||
);
|
||||
let result = '';
|
||||
let prose = '';
|
||||
|
||||
const flushProse = () => {
|
||||
if (!prose) return;
|
||||
result += replaceOutsideCode(prose, (segment) => segment.replace(citationMarkerRegex, ''));
|
||||
prose = '';
|
||||
};
|
||||
|
||||
for (const line of content.match(/[^\n]*(?:\n|$)/g) ?? []) {
|
||||
if (!line) continue;
|
||||
|
||||
if (indentedCodeLineRegex.test(line)) {
|
||||
flushProse();
|
||||
result += line;
|
||||
continue;
|
||||
}
|
||||
|
||||
prose += line;
|
||||
}
|
||||
|
||||
flushProse();
|
||||
return result;
|
||||
};
|
||||
|
||||
const getSourceIds = (sources) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue