From 534559b2e07989a46e1f51e8af701b5e2b269c7a Mon Sep 17 00:00:00 2001 From: Woody Date: Fri, 15 May 2026 10:46:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Phase=207.1=20=E2=80=94=20highlight?= =?UTF-8?q?=20prompt=20template=20+=20sequential=20citation=20[N]=20+=20hi?= =?UTF-8?q?ghlightTerms=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Backend: add ==term== highlighting instruction to _SEED_GENERATE_PER_SUBQ - Frontend: replaceFilename output with sequential [1] [2] [3] numbering - Frontend: add highlightTerms() to convert ==term== to HTML - Tests: 39 citation+highlight tests pass (28 updated + 11 new) - Fix: QueryInput partialText styling and disabled state --- backend/app/core/sqlite_db.py | 2 + frontend/package.json | 1 + frontend/pnpm-lock.yaml | 477 ++++-------------- frontend/src/components/QueryInput.tsx | 4 +- .../test/components/ResponsePanel.test.tsx | 2 +- .../src/test/utils/citationParser.test.ts | 19 +- .../src/test/utils/highlightParser.test.ts | 73 +++ frontend/src/utils/citationParser.ts | 14 +- 8 files changed, 213 insertions(+), 379 deletions(-) create mode 100644 frontend/src/test/utils/highlightParser.test.ts diff --git a/backend/app/core/sqlite_db.py b/backend/app/core/sqlite_db.py index a8b1e4e..d05ed52 100644 --- a/backend/app/core/sqlite_db.py +++ b/backend/app/core/sqlite_db.py @@ -48,6 +48,8 @@ _SEED_GENERATE_PER_SUBQ = ( "Copy the exact bracket labels shown in the document chunks — " "do not modify filenames or add/remove extensions.\n" "Place the citation at the end of each bullet point.\n" + "For monetary figures (e.g., HK$1,000,000), percentages (e.g., 35%), key statistics, " + "and dates (e.g., 1 January 2024, 2023), wrap them in ==double equals markers== for highlighting.\n" "{context_sections}\n\n" "Answer:" ) diff --git a/frontend/package.json b/frontend/package.json index 7bafc31..cb6c0b4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,6 +33,7 @@ "jsdom": "^20.0.3", "ts-node": "^10.9.1", "typescript": "^5.1.6", + "vite": "^4.4.0", "vitest": "^0.34.3" }, "pnpm": { diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 8d56454..61934a8 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -62,7 +62,7 @@ importers: version: 18.3.7(@types/react@18.3.28) '@vitejs/plugin-react': specifier: ^4.0.0 - version: 4.7.0(vite@5.4.21(@types/node@25.7.0)) + version: 4.7.0(vite@4.5.14(@types/node@25.7.0)) jsdom: specifier: ^20.0.3 version: 20.0.3 @@ -72,6 +72,9 @@ importers: typescript: specifier: ^5.1.6 version: 5.9.3 + vite: + specifier: ^4.4.0 + version: 4.5.14(@types/node@25.7.0) vitest: specifier: ^0.34.3 version: 0.34.6(jsdom@20.0.3) @@ -176,140 +179,134 @@ packages: resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} - '@esbuild/aix-ppc64@0.21.5': - resolution: {integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [aix] - - '@esbuild/android-arm64@0.21.5': - resolution: {integrity: sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==} + '@esbuild/android-arm64@0.18.20': + resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} engines: {node: '>=12'} cpu: [arm64] os: [android] - '@esbuild/android-arm@0.21.5': - resolution: {integrity: sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==} + '@esbuild/android-arm@0.18.20': + resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==} engines: {node: '>=12'} cpu: [arm] os: [android] - '@esbuild/android-x64@0.21.5': - resolution: {integrity: sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==} + '@esbuild/android-x64@0.18.20': + resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==} engines: {node: '>=12'} cpu: [x64] os: [android] - '@esbuild/darwin-arm64@0.21.5': - resolution: {integrity: sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==} + '@esbuild/darwin-arm64@0.18.20': + resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==} engines: {node: '>=12'} cpu: [arm64] os: [darwin] - '@esbuild/darwin-x64@0.21.5': - resolution: {integrity: sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==} + '@esbuild/darwin-x64@0.18.20': + resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==} engines: {node: '>=12'} cpu: [x64] os: [darwin] - '@esbuild/freebsd-arm64@0.21.5': - resolution: {integrity: sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==} + '@esbuild/freebsd-arm64@0.18.20': + resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==} engines: {node: '>=12'} cpu: [arm64] os: [freebsd] - '@esbuild/freebsd-x64@0.21.5': - resolution: {integrity: sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==} + '@esbuild/freebsd-x64@0.18.20': + resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==} engines: {node: '>=12'} cpu: [x64] os: [freebsd] - '@esbuild/linux-arm64@0.21.5': - resolution: {integrity: sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==} + '@esbuild/linux-arm64@0.18.20': + resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==} engines: {node: '>=12'} cpu: [arm64] os: [linux] - '@esbuild/linux-arm@0.21.5': - resolution: {integrity: sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==} + '@esbuild/linux-arm@0.18.20': + resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==} engines: {node: '>=12'} cpu: [arm] os: [linux] - '@esbuild/linux-ia32@0.21.5': - resolution: {integrity: sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==} + '@esbuild/linux-ia32@0.18.20': + resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==} engines: {node: '>=12'} cpu: [ia32] os: [linux] - '@esbuild/linux-loong64@0.21.5': - resolution: {integrity: sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==} + '@esbuild/linux-loong64@0.18.20': + resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==} engines: {node: '>=12'} cpu: [loong64] os: [linux] - '@esbuild/linux-mips64el@0.21.5': - resolution: {integrity: sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==} + '@esbuild/linux-mips64el@0.18.20': + resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==} engines: {node: '>=12'} cpu: [mips64el] os: [linux] - '@esbuild/linux-ppc64@0.21.5': - resolution: {integrity: sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==} + '@esbuild/linux-ppc64@0.18.20': + resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==} engines: {node: '>=12'} cpu: [ppc64] os: [linux] - '@esbuild/linux-riscv64@0.21.5': - resolution: {integrity: sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==} + '@esbuild/linux-riscv64@0.18.20': + resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==} engines: {node: '>=12'} cpu: [riscv64] os: [linux] - '@esbuild/linux-s390x@0.21.5': - resolution: {integrity: sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==} + '@esbuild/linux-s390x@0.18.20': + resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==} engines: {node: '>=12'} cpu: [s390x] os: [linux] - '@esbuild/linux-x64@0.21.5': - resolution: {integrity: sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==} + '@esbuild/linux-x64@0.18.20': + resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==} engines: {node: '>=12'} cpu: [x64] os: [linux] - '@esbuild/netbsd-x64@0.21.5': - resolution: {integrity: sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==} + '@esbuild/netbsd-x64@0.18.20': + resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==} engines: {node: '>=12'} cpu: [x64] os: [netbsd] - '@esbuild/openbsd-x64@0.21.5': - resolution: {integrity: sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==} + '@esbuild/openbsd-x64@0.18.20': + resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==} engines: {node: '>=12'} cpu: [x64] os: [openbsd] - '@esbuild/sunos-x64@0.21.5': - resolution: {integrity: sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==} + '@esbuild/sunos-x64@0.18.20': + resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==} engines: {node: '>=12'} cpu: [x64] os: [sunos] - '@esbuild/win32-arm64@0.21.5': - resolution: {integrity: sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==} + '@esbuild/win32-arm64@0.18.20': + resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==} engines: {node: '>=12'} cpu: [arm64] os: [win32] - '@esbuild/win32-ia32@0.21.5': - resolution: {integrity: sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==} + '@esbuild/win32-ia32@0.18.20': + resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==} engines: {node: '>=12'} cpu: [ia32] os: [win32] - '@esbuild/win32-x64@0.21.5': - resolution: {integrity: sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==} + '@esbuild/win32-x64@0.18.20': + resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==} engines: {node: '>=12'} cpu: [x64] os: [win32] @@ -451,144 +448,6 @@ packages: '@rolldown/pluginutils@1.0.0-beta.27': resolution: {integrity: sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==} - '@rollup/rollup-android-arm-eabi@4.60.3': - resolution: {integrity: sha512-x35CNW/ANXG3hE/EZpRU8MXX1JDN86hBb2wMGAtltkz7pc6cxgjpy1OMMfDosOQ+2hWqIkag/fGok1Yady9nGw==} - cpu: [arm] - os: [android] - - '@rollup/rollup-android-arm64@4.60.3': - resolution: {integrity: sha512-xw3xtkDApIOGayehp2+Rz4zimfkaX65r4t47iy+ymQB2G4iJCBBfj0ogVg5jpvjpn8UWn/+q9tprxleYeNp3Hw==} - cpu: [arm64] - os: [android] - - '@rollup/rollup-darwin-arm64@4.60.3': - resolution: {integrity: sha512-vo6Y5Qfpx7/5EaamIwi0WqW2+zfiusVihKatLvtN1VFVy3D13uERk/6gZLU1UiHRL6fDXqj/ELIeVRGnvcTE1g==} - cpu: [arm64] - os: [darwin] - - '@rollup/rollup-darwin-x64@4.60.3': - resolution: {integrity: sha512-D+0QGcZhBzTN82weOnsSlY7V7+RMmPuF1CkbxyMAGE8+ZHeUjyb76ZiWmBlCu//AQQONvxcqRbwZTajZKqjuOw==} - cpu: [x64] - os: [darwin] - - '@rollup/rollup-freebsd-arm64@4.60.3': - resolution: {integrity: sha512-6HnvHCT7fDyj6R0Ph7A6x8dQS/S38MClRWeDLqc0MdfWkxjiu1HSDYrdPhqSILzjTIC/pnXbbJbo+ft+gy/9hQ==} - cpu: [arm64] - os: [freebsd] - - '@rollup/rollup-freebsd-x64@4.60.3': - resolution: {integrity: sha512-KHLgC3WKlUYW3ShFKnnosZDOJ0xjg9zp7au3sIm2bs/tGBeC2ipmvRh/N7JKi0t9Ue20C0dpEshi8WUubg+cnA==} - cpu: [x64] - os: [freebsd] - - '@rollup/rollup-linux-arm-gnueabihf@4.60.3': - resolution: {integrity: sha512-DV6fJoxEYWJOvaZIsok7KrYl0tPvga5OZ2yvKHNNYyk/2roMLqQAbGhr78EQ5YhHpnhLKJD3S1WFusAkmUuV5g==} - cpu: [arm] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-arm-musleabihf@4.60.3': - resolution: {integrity: sha512-mQKoJAzvuOs6F+TZybQO4GOTSMUu7v0WdxEk24krQ/uUxXoPTtHjuaUuPmFhtBcM4K0ons8nrE3JyhTuCFtT/w==} - cpu: [arm] - os: [linux] - libc: [musl] - - '@rollup/rollup-linux-arm64-gnu@4.60.3': - resolution: {integrity: sha512-Whjj2qoiJ6+OOJMGptTYazaJvjOJm+iKHpXQM1P3LzGjt7Ff++Tp7nH4N8J/BUA7R9IHfDyx4DJIflifwnbmIA==} - cpu: [arm64] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-arm64-musl@4.60.3': - resolution: {integrity: sha512-4YTNHKqGng5+yiZt3mg77nmyuCfmNfX4fPmyUapBcIk+BdwSwmCWGXOUxhXbBEkFHtoN5boLj/5NON+u5QC9tg==} - cpu: [arm64] - os: [linux] - libc: [musl] - - '@rollup/rollup-linux-loong64-gnu@4.60.3': - resolution: {integrity: sha512-SU3kNlhkpI4UqlUc2VXPGK9o886ZsSeGfMAX2ba2b8DKmMXq4AL7KUrkSWVbb7koVqx41Yczx6dx5PNargIrEA==} - cpu: [loong64] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-loong64-musl@4.60.3': - resolution: {integrity: sha512-6lDLl5h4TXpB1mTf2rQWnAk/LcXrx9vBfu/DT5TIPhvMhRWaZ5MxkIc8u4lJAmBo6klTe1ywXIUHFjylW505sg==} - cpu: [loong64] - os: [linux] - libc: [musl] - - '@rollup/rollup-linux-ppc64-gnu@4.60.3': - resolution: {integrity: sha512-BMo8bOw8evlup/8G+cj5xWtPyp93xPdyoSN16Zy90Q2QZ0ZYRhCt6ZJSwbrRzG9HApFabjwj2p25TUPDWrhzqQ==} - cpu: [ppc64] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-ppc64-musl@4.60.3': - resolution: {integrity: sha512-E0L8X1dZN1/Rph+5VPF6Xj2G7JJvMACVXtamTJIDrVI44Y3K+G8gQaMEAavbqCGTa16InptiVrX6eM6pmJ+7qA==} - cpu: [ppc64] - os: [linux] - libc: [musl] - - '@rollup/rollup-linux-riscv64-gnu@4.60.3': - resolution: {integrity: sha512-oZJ/WHaVfHUiRAtmTAeo3DcevNsVvH8mbvodjZy7D5QKvCefO371SiKRpxoDcCxB3PTRTLayWBkvmDQKTcX/sw==} - cpu: [riscv64] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-riscv64-musl@4.60.3': - resolution: {integrity: sha512-Dhbyh7j9FybM3YaTgaHmVALwA8AkUwTPccyCQ79TG9AJUsMQqgN1DDEZNr4+QUfwiWvLDumW5vdwzoeUF+TNxQ==} - cpu: [riscv64] - os: [linux] - libc: [musl] - - '@rollup/rollup-linux-s390x-gnu@4.60.3': - resolution: {integrity: sha512-cJd1X5XhHHlltkaypz1UcWLA8AcoIi1aWhsvaWDskD1oz2eKCypnqvTQ8ykMNI0RSmm7NkTdSqSSD7zM0xa6Ig==} - cpu: [s390x] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-x64-gnu@4.60.3': - resolution: {integrity: sha512-DAZDBHQfG2oQuhY7mc6I3/qB4LU2fQCjRvxbDwd/Jdvb9fypP4IJ4qmtu6lNjes6B531AI8cg1aKC2di97bUxA==} - cpu: [x64] - os: [linux] - libc: [glibc] - - '@rollup/rollup-linux-x64-musl@4.60.3': - resolution: {integrity: sha512-cRxsE8c13mZOh3vP+wLDxpQBRrOHDIGOWyDL93Sy0Ga8y515fBcC2pjUfFwUe5T7tqvTvWbCpg1URM/AXdWIXA==} - cpu: [x64] - os: [linux] - libc: [musl] - - '@rollup/rollup-openbsd-x64@4.60.3': - resolution: {integrity: sha512-QaWcIgRxqEdQdhJqW4DJctsH6HCmo5vHxY0krHSX4jMtOqfzC+dqDGuHM87bu4H8JBeibWx7jFz+h6/4C8wA5Q==} - cpu: [x64] - os: [openbsd] - - '@rollup/rollup-openharmony-arm64@4.60.3': - resolution: {integrity: sha512-AaXwSvUi3QIPtroAUw1t5yHGIyqKEXwH54WUocFolZhpGDruJcs8c+xPNDRn4XiQsS7MEwnYsHW2l0MBLDMkWg==} - cpu: [arm64] - os: [openharmony] - - '@rollup/rollup-win32-arm64-msvc@4.60.3': - resolution: {integrity: sha512-65LAKM/bAWDqKNEelHlcHvm2V+Vfb8C6INFxQXRHCvaVN1rJfwr4NvdP4FyzUaLqWfaCGaadf6UbTm8xJeYfEg==} - cpu: [arm64] - os: [win32] - - '@rollup/rollup-win32-ia32-msvc@4.60.3': - resolution: {integrity: sha512-EEM2gyhBF5MFnI6vMKdX1LAosE627RGBzIoGMdLloPZkXrUN0Ckqgr2Qi8+J3zip/8NVVro3/FjB+tjhZUgUHA==} - cpu: [ia32] - os: [win32] - - '@rollup/rollup-win32-x64-gnu@4.60.3': - resolution: {integrity: sha512-E5Eb5H/DpxaoXH++Qkv28RcUJboMopmdDUALBczvHMf7hNIxaDZqwY5lK12UK1BHacSmvupoEWGu+n993Z0y1A==} - cpu: [x64] - os: [win32] - - '@rollup/rollup-win32-x64-msvc@4.60.3': - resolution: {integrity: sha512-hPt/bgL5cE+Qp+/TPHBqptcAgPzgj46mPcg/16zNUmbQk0j+mOEQV/+Lqu8QRtDV3Ek95Q6FeFITpuhl6OTsAA==} - cpu: [x64] - os: [win32] - '@sinclair/typebox@0.27.10': resolution: {integrity: sha512-MTBk/3jGLNB2tVxv6uLlFh1iu64iYOQ2PbdOSK3NW8JZsmlaOh2q6sdtKowBhfw8QFLmYNzTW4/oK4uATIi6ZA==} @@ -663,9 +522,6 @@ packages: '@types/estree-jsx@1.0.5': resolution: {integrity: sha512-52CcUVNFyfb1A2ALocQw/Dd1BQFNmSdkuC3BkZ6iqhdMfQz7JWOFRuJFloOzjk+6WijU56m9oKXFAXc7o3Towg==} - '@types/estree@1.0.8': - resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} - '@types/estree@1.0.9': resolution: {integrity: sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==} @@ -1058,8 +914,8 @@ packages: resolution: {integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==} engines: {node: '>= 0.4'} - esbuild@0.21.5: - resolution: {integrity: sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==} + esbuild@0.18.20: + resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==} engines: {node: '>=12'} hasBin: true @@ -1840,9 +1696,9 @@ packages: resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - rollup@4.60.3: - resolution: {integrity: sha512-pAQK9HalE84QSm4Po3EmWIZPd3FnjkShVkiMlz1iligWYkWQ7wHYd1PF/T7QZ5TVSD6uSTon5gBVMSM4JfBV+A==} - engines: {node: '>=18.0.0', npm: '>=8.0.0'} + rollup@3.30.0: + resolution: {integrity: sha512-kQvGasUgN+AlWGliFn2POSajRQEsULVYFGTvOZmK06d7vCD+YhZztt70kGk3qaeAXeWYL5eO7zx+rAubBc55eA==} + engines: {node: '>=14.18.0', npm: '>=8.0.0'} hasBin: true run-parallel@1.2.0: @@ -2085,16 +1941,15 @@ packages: engines: {node: '>=v14.18.0'} hasBin: true - vite@5.4.21: - resolution: {integrity: sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==} - engines: {node: ^18.0.0 || >=20.0.0} + vite@4.5.14: + resolution: {integrity: sha512-+v57oAaoYNnO3hIu5Z/tJRZjq5aHM2zDve9YZ8HngVHbhk66RStobhb1sqPMIPEleV6cNKYK4eGrAbE9Ulbl2g==} + engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: - '@types/node': ^18.0.0 || >=20.0.0 + '@types/node': '>= 14' less: '*' lightningcss: ^1.21.0 sass: '*' - sass-embedded: '*' stylus: '*' sugarss: '*' terser: ^5.4.0 @@ -2107,8 +1962,6 @@ packages: optional: true sass: optional: true - sass-embedded: - optional: true stylus: optional: true sugarss: @@ -2345,73 +2198,70 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@esbuild/aix-ppc64@0.21.5': + '@esbuild/android-arm64@0.18.20': optional: true - '@esbuild/android-arm64@0.21.5': + '@esbuild/android-arm@0.18.20': optional: true - '@esbuild/android-arm@0.21.5': + '@esbuild/android-x64@0.18.20': optional: true - '@esbuild/android-x64@0.21.5': + '@esbuild/darwin-arm64@0.18.20': optional: true - '@esbuild/darwin-arm64@0.21.5': + '@esbuild/darwin-x64@0.18.20': optional: true - '@esbuild/darwin-x64@0.21.5': + '@esbuild/freebsd-arm64@0.18.20': optional: true - '@esbuild/freebsd-arm64@0.21.5': + '@esbuild/freebsd-x64@0.18.20': optional: true - '@esbuild/freebsd-x64@0.21.5': + '@esbuild/linux-arm64@0.18.20': optional: true - '@esbuild/linux-arm64@0.21.5': + '@esbuild/linux-arm@0.18.20': optional: true - '@esbuild/linux-arm@0.21.5': + '@esbuild/linux-ia32@0.18.20': optional: true - '@esbuild/linux-ia32@0.21.5': + '@esbuild/linux-loong64@0.18.20': optional: true - '@esbuild/linux-loong64@0.21.5': + '@esbuild/linux-mips64el@0.18.20': optional: true - '@esbuild/linux-mips64el@0.21.5': + '@esbuild/linux-ppc64@0.18.20': optional: true - '@esbuild/linux-ppc64@0.21.5': + '@esbuild/linux-riscv64@0.18.20': optional: true - '@esbuild/linux-riscv64@0.21.5': + '@esbuild/linux-s390x@0.18.20': optional: true - '@esbuild/linux-s390x@0.21.5': + '@esbuild/linux-x64@0.18.20': optional: true - '@esbuild/linux-x64@0.21.5': + '@esbuild/netbsd-x64@0.18.20': optional: true - '@esbuild/netbsd-x64@0.21.5': + '@esbuild/openbsd-x64@0.18.20': optional: true - '@esbuild/openbsd-x64@0.21.5': + '@esbuild/sunos-x64@0.18.20': optional: true - '@esbuild/sunos-x64@0.21.5': + '@esbuild/win32-arm64@0.18.20': optional: true - '@esbuild/win32-arm64@0.21.5': + '@esbuild/win32-ia32@0.18.20': optional: true - '@esbuild/win32-ia32@0.21.5': - optional: true - - '@esbuild/win32-x64@0.21.5': + '@esbuild/win32-x64@0.18.20': optional: true '@jest/diff-sequences@30.4.0': {} @@ -2531,81 +2381,6 @@ snapshots: '@rolldown/pluginutils@1.0.0-beta.27': {} - '@rollup/rollup-android-arm-eabi@4.60.3': - optional: true - - '@rollup/rollup-android-arm64@4.60.3': - optional: true - - '@rollup/rollup-darwin-arm64@4.60.3': - optional: true - - '@rollup/rollup-darwin-x64@4.60.3': - optional: true - - '@rollup/rollup-freebsd-arm64@4.60.3': - optional: true - - '@rollup/rollup-freebsd-x64@4.60.3': - optional: true - - '@rollup/rollup-linux-arm-gnueabihf@4.60.3': - optional: true - - '@rollup/rollup-linux-arm-musleabihf@4.60.3': - optional: true - - '@rollup/rollup-linux-arm64-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-arm64-musl@4.60.3': - optional: true - - '@rollup/rollup-linux-loong64-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-loong64-musl@4.60.3': - optional: true - - '@rollup/rollup-linux-ppc64-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-ppc64-musl@4.60.3': - optional: true - - '@rollup/rollup-linux-riscv64-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-riscv64-musl@4.60.3': - optional: true - - '@rollup/rollup-linux-s390x-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-x64-gnu@4.60.3': - optional: true - - '@rollup/rollup-linux-x64-musl@4.60.3': - optional: true - - '@rollup/rollup-openbsd-x64@4.60.3': - optional: true - - '@rollup/rollup-openharmony-arm64@4.60.3': - optional: true - - '@rollup/rollup-win32-arm64-msvc@4.60.3': - optional: true - - '@rollup/rollup-win32-ia32-msvc@4.60.3': - optional: true - - '@rollup/rollup-win32-x64-gnu@4.60.3': - optional: true - - '@rollup/rollup-win32-x64-msvc@4.60.3': - optional: true - '@sinclair/typebox@0.27.10': {} '@sinclair/typebox@0.34.49': {} @@ -2697,8 +2472,6 @@ snapshots: dependencies: '@types/estree': 1.0.9 - '@types/estree@1.0.8': {} - '@types/estree@1.0.9': {} '@types/hast@3.0.4': @@ -2759,7 +2532,7 @@ snapshots: '@ungap/structured-clone@1.3.1': {} - '@vitejs/plugin-react@4.7.0(vite@5.4.21(@types/node@25.7.0))': + '@vitejs/plugin-react@4.7.0(vite@4.5.14(@types/node@25.7.0))': dependencies: '@babel/core': 7.29.0 '@babel/plugin-transform-react-jsx-self': 7.27.1(@babel/core@7.29.0) @@ -2767,7 +2540,7 @@ snapshots: '@rolldown/pluginutils': 1.0.0-beta.27 '@types/babel__core': 7.20.5 react-refresh: 0.17.0 - vite: 5.4.21(@types/node@25.7.0) + vite: 4.5.14(@types/node@25.7.0) transitivePeerDependencies: - supports-color @@ -3114,31 +2887,30 @@ snapshots: has-tostringtag: 1.0.2 hasown: 2.0.3 - esbuild@0.21.5: + esbuild@0.18.20: optionalDependencies: - '@esbuild/aix-ppc64': 0.21.5 - '@esbuild/android-arm': 0.21.5 - '@esbuild/android-arm64': 0.21.5 - '@esbuild/android-x64': 0.21.5 - '@esbuild/darwin-arm64': 0.21.5 - '@esbuild/darwin-x64': 0.21.5 - '@esbuild/freebsd-arm64': 0.21.5 - '@esbuild/freebsd-x64': 0.21.5 - '@esbuild/linux-arm': 0.21.5 - '@esbuild/linux-arm64': 0.21.5 - '@esbuild/linux-ia32': 0.21.5 - '@esbuild/linux-loong64': 0.21.5 - '@esbuild/linux-mips64el': 0.21.5 - '@esbuild/linux-ppc64': 0.21.5 - '@esbuild/linux-riscv64': 0.21.5 - '@esbuild/linux-s390x': 0.21.5 - '@esbuild/linux-x64': 0.21.5 - '@esbuild/netbsd-x64': 0.21.5 - '@esbuild/openbsd-x64': 0.21.5 - '@esbuild/sunos-x64': 0.21.5 - '@esbuild/win32-arm64': 0.21.5 - '@esbuild/win32-ia32': 0.21.5 - '@esbuild/win32-x64': 0.21.5 + '@esbuild/android-arm': 0.18.20 + '@esbuild/android-arm64': 0.18.20 + '@esbuild/android-x64': 0.18.20 + '@esbuild/darwin-arm64': 0.18.20 + '@esbuild/darwin-x64': 0.18.20 + '@esbuild/freebsd-arm64': 0.18.20 + '@esbuild/freebsd-x64': 0.18.20 + '@esbuild/linux-arm': 0.18.20 + '@esbuild/linux-arm64': 0.18.20 + '@esbuild/linux-ia32': 0.18.20 + '@esbuild/linux-loong64': 0.18.20 + '@esbuild/linux-mips64el': 0.18.20 + '@esbuild/linux-ppc64': 0.18.20 + '@esbuild/linux-riscv64': 0.18.20 + '@esbuild/linux-s390x': 0.18.20 + '@esbuild/linux-x64': 0.18.20 + '@esbuild/netbsd-x64': 0.18.20 + '@esbuild/openbsd-x64': 0.18.20 + '@esbuild/sunos-x64': 0.18.20 + '@esbuild/win32-arm64': 0.18.20 + '@esbuild/win32-ia32': 0.18.20 + '@esbuild/win32-x64': 0.18.20 escalade@3.2.0: {} @@ -4078,35 +3850,8 @@ snapshots: reusify@1.1.0: {} - rollup@4.60.3: - dependencies: - '@types/estree': 1.0.8 + rollup@3.30.0: optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.60.3 - '@rollup/rollup-android-arm64': 4.60.3 - '@rollup/rollup-darwin-arm64': 4.60.3 - '@rollup/rollup-darwin-x64': 4.60.3 - '@rollup/rollup-freebsd-arm64': 4.60.3 - '@rollup/rollup-freebsd-x64': 4.60.3 - '@rollup/rollup-linux-arm-gnueabihf': 4.60.3 - '@rollup/rollup-linux-arm-musleabihf': 4.60.3 - '@rollup/rollup-linux-arm64-gnu': 4.60.3 - '@rollup/rollup-linux-arm64-musl': 4.60.3 - '@rollup/rollup-linux-loong64-gnu': 4.60.3 - '@rollup/rollup-linux-loong64-musl': 4.60.3 - '@rollup/rollup-linux-ppc64-gnu': 4.60.3 - '@rollup/rollup-linux-ppc64-musl': 4.60.3 - '@rollup/rollup-linux-riscv64-gnu': 4.60.3 - '@rollup/rollup-linux-riscv64-musl': 4.60.3 - '@rollup/rollup-linux-s390x-gnu': 4.60.3 - '@rollup/rollup-linux-x64-gnu': 4.60.3 - '@rollup/rollup-linux-x64-musl': 4.60.3 - '@rollup/rollup-openbsd-x64': 4.60.3 - '@rollup/rollup-openharmony-arm64': 4.60.3 - '@rollup/rollup-win32-arm64-msvc': 4.60.3 - '@rollup/rollup-win32-ia32-msvc': 4.60.3 - '@rollup/rollup-win32-x64-gnu': 4.60.3 - '@rollup/rollup-win32-x64-msvc': 4.60.3 fsevents: 2.3.3 run-parallel@1.2.0: @@ -4403,23 +4148,22 @@ snapshots: mlly: 1.8.2 pathe: 1.1.2 picocolors: 1.1.1 - vite: 5.4.21(@types/node@25.7.0) + vite: 4.5.14(@types/node@25.7.0) transitivePeerDependencies: - '@types/node' - less - lightningcss - sass - - sass-embedded - stylus - sugarss - supports-color - terser - vite@5.4.21(@types/node@25.7.0): + vite@4.5.14(@types/node@25.7.0): dependencies: - esbuild: 0.21.5 + esbuild: 0.18.20 postcss: 8.5.14 - rollup: 4.60.3 + rollup: 3.30.0 optionalDependencies: '@types/node': 25.7.0 fsevents: 2.3.3 @@ -4447,7 +4191,7 @@ snapshots: strip-literal: 1.3.0 tinybench: 2.9.0 tinypool: 0.7.0 - vite: 5.4.21(@types/node@25.7.0) + vite: 4.5.14(@types/node@25.7.0) vite-node: 0.34.6(@types/node@25.7.0) why-is-node-running: 2.3.0 optionalDependencies: @@ -4456,7 +4200,6 @@ snapshots: - less - lightningcss - sass - - sass-embedded - stylus - sugarss - supports-color diff --git a/frontend/src/components/QueryInput.tsx b/frontend/src/components/QueryInput.tsx index 401d6f6..b26ebf0 100644 --- a/frontend/src/components/QueryInput.tsx +++ b/frontend/src/components/QueryInput.tsx @@ -49,11 +49,11 @@ export const QueryInput: React.FC = ({ onSubmit, onHalfQuestion } } - const isDisabled = isLoading || displayValue.trim() === '' + const isDisabled = isLoading || displayValue.trim() === '' || (!hasUserInput && !!partialText) const textareaClassName = [ 'w-full rounded border border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100 disabled:cursor-not-allowed', - '', + showPartialStyle ? 'text-gray-400 italic' : '', ].filter(Boolean).join(' ') return ( diff --git a/frontend/src/test/components/ResponsePanel.test.tsx b/frontend/src/test/components/ResponsePanel.test.tsx index 64cac2a..e4ebef8 100644 --- a/frontend/src/test/components/ResponsePanel.test.tsx +++ b/frontend/src/test/components/ResponsePanel.test.tsx @@ -197,7 +197,7 @@ describe('ResponsePanel', () => { /> ) - const citationLink = screen.getByRole('link', { name: /NEC4 ACC\.pdf, page 3/ }) + const citationLink = screen.getByRole('link', { name: '1' }) expect(citationLink).toBeInTheDocument() expect(citationLink).toHaveAttribute('target', '_blank') expect(citationLink).toHaveAttribute('href', expect.stringContaining('/pdf-viewer')) diff --git a/frontend/src/test/utils/citationParser.test.ts b/frontend/src/test/utils/citationParser.test.ts index fd10bf2..404c907 100644 --- a/frontend/src/test/utils/citationParser.test.ts +++ b/frontend/src/test/utils/citationParser.test.ts @@ -43,14 +43,14 @@ describe('processCitations', () => { const result = processCitations(text, mockSources) expect(result).toContain('](') expect(result).toContain('/pdf-viewer') - expect(result).toMatch(/\[NEC4 ACC\.pdf, page 3\]\([^)]+\)/) + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('handles filename-only citation for DOCX (no page)', () => { const text = 'Notes [meeting_notes.docx] from meeting.' const result = processCitations(text, mockSources) expect(result).toContain('/pdf-viewer') - expect(result).toContain('meeting_notes.docx') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('leaves unmatched citations as plain text', () => { @@ -64,26 +64,28 @@ describe('processCitations', () => { const result = processCitations(text, mockSources) const linkCount = (result.match(/\[.+?\]\(/g) || []).length expect(linkCount).toBe(2) + expect(result).toMatch(/\[1\]\([^)]+\)/) + expect(result).toMatch(/\[2\]\([^)]+\)/) }) it('does not break existing markdown links', () => { const text = 'See [label](http://example.com) and [NEC4 ACC.pdf, page 3].' const result = processCitations(text, mockSources) expect(result).toContain('[label](http://example.com)') - expect(result).toContain('/pdf-viewer') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('does not break markdown images', () => { const text = '![diagram](http://example.com/img.png) and [NEC4 ACC.pdf, page 3].' const result = processCitations(text, mockSources) expect(result).toContain('![diagram]') - expect(result).toContain('/pdf-viewer') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('matches case-insensitively', () => { const text = 'Cite [nec4 acc.pdf, page 3] lowercase.' const result = processCitations(text, mockSources) - expect(result).toContain('/pdf-viewer') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('leaves plain bracket text without matching source', () => { @@ -107,6 +109,7 @@ describe('processCitations', () => { const text = 'Source [no_path.pdf, page 1] with document link.' const result = processCitations(text, sourcesWithoutPath) expect(result).toContain('/rag-database?document=doc-fallback') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('remains plain text when both chunk_file_path and document_id are null', () => { @@ -130,19 +133,19 @@ describe('processCitations', () => { const text = 'See [NEC4 ACC, page 3] without .pdf extension.' const result = processCitations(text, mockSources) expect(result).toContain('/pdf-viewer') - expect(result).toContain('NEC4 ACC, page 3') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('fuzzy matches citation with different case and without extension', () => { const text = 'Cite [nec4 acc] lowercase no extension.' const result = processCitations(text, mockSources) - expect(result).toContain('/pdf-viewer') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) it('fuzzy matches filename-only citation without extension', () => { const text = 'Notes [meeting_notes] from meeting (no .docx).' const result = processCitations(text, mockSources) - expect(result).toContain('/pdf-viewer') + expect(result).toMatch(/\[1\]\([^)]+\)/) }) }) diff --git a/frontend/src/test/utils/highlightParser.test.ts b/frontend/src/test/utils/highlightParser.test.ts new file mode 100644 index 0000000..0a295bd --- /dev/null +++ b/frontend/src/test/utils/highlightParser.test.ts @@ -0,0 +1,73 @@ +import { describe, it, expect } from 'vitest' +import { highlightTerms } from '../../utils/citationParser' + +describe('highlightTerms', () => { + it('converts single ==term== to mark element', () => { + const input = 'This is ==important== text.' + const result = highlightTerms(input) + expect(result).toBe('This is important text.') + }) + + it('converts multiple ==term== markers in one string', () => { + const input = '==First== and ==second== highlight.' + const result = highlightTerms(input) + expect(result).toBe( + 'First and second highlight.' + ) + }) + + it('returns text unchanged when no markers present', () => { + const input = 'This text has no highlights.' + const result = highlightTerms(input) + expect(result).toBe(input) + }) + + it('returns empty string for empty input', () => { + const result = highlightTerms('') + expect(result).toBe('') + }) + + it('handles numeric values like ==HK$1,000,000==', () => { + const input = 'Amount: ==HK$1,000,000==' + const result = highlightTerms(input) + expect(result).toBe('Amount: HK$1,000,000') + }) + + it('handles percentage values like ==35%==', () => { + const input = 'Rate: ==35%==' + const result = highlightTerms(input) + expect(result).toBe('Rate: 35%') + }) + + it('handles date values like ==1 January 2024==', () => { + const input = 'Date: ==1 January 2024==' + const result = highlightTerms(input) + expect(result).toBe('Date: 1 January 2024') + }) + + it('handles adjacent markers ==foo== ==bar==', () => { + const input = '==foo== ==bar==' + const result = highlightTerms(input) + expect(result).toBe( + 'foo bar' + ) + }) + + it('does not highlight markers inside backtick code spans', () => { + const input = 'Code: `==code==` and ==highlight==' + const result = highlightTerms(input) + expect(result).toBe('Code: `==code==` and highlight') + }) + + it('does not highlight markers adjacent to backticks', () => { + const input = '`==not me==` ==but me== `==also not==`' + const result = highlightTerms(input) + expect(result).toBe('`==not me==` but me `==also not==`') + }) + + it('passes through plain markdown text without markers unchanged', () => { + const input = '## Heading\n\n- Bullet one\n- **Bold text**\n\n[A link](http://example.com)' + const result = highlightTerms(input) + expect(result).toBe(input) + }) +}) diff --git a/frontend/src/utils/citationParser.ts b/frontend/src/utils/citationParser.ts index d472564..abb78d1 100644 --- a/frontend/src/utils/citationParser.ts +++ b/frontend/src/utils/citationParser.ts @@ -108,6 +108,7 @@ function replaceCitationPatterns( highlightKeys?: Set ): string { const citationPattern = /(? { const trimmed = content.trim() @@ -122,7 +123,8 @@ function replaceCitationPatterns( } const url = buildCitationUrl(source, isReady) if (url) { - return `[${trimmed}](${url})` + refCounter++ + return `[${refCounter}](${url})` } } @@ -160,3 +162,13 @@ export function extractCitedSources(answerText: string, sources: SourceMetadata[ return result } + +export function highlightTerms(markdown: string): string { + const parts = markdown.split(/(`[^`]*`)/) + return parts + .map((part, index) => { + if (index % 2 === 1) return part + return part.replace(/(?$1') + }) + .join('') +} From e78f53b687263d15e5b7eb25b3331cc30db77e23 Mon Sep 17 00:00:00 2001 From: Woody Date: Fri, 15 May 2026 10:51:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20Phase=207.2=20=E2=80=94=20wire=20hi?= =?UTF-8?q?ghlightTerms=20into=20ResponsePanel=20+=20mark=20CSS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add HighlightMark component rendering - Call highlightTerms() in SubQuestionSection and FlatResponse before ReactMarkdown - Add mark: HighlightMark to ReactMarkdown components in both paths - Add .prose mark CSS rule (yellow-200 bg, rounded, px-0.5) - Tests: 56/56 pass (citation + highlight + ResponsePanel) --- frontend/src/components/ResponsePanel.tsx | 16 +++++++++++----- frontend/src/styles.css | 5 +++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/ResponsePanel.tsx b/frontend/src/components/ResponsePanel.tsx index b93c6ba..067b599 100644 --- a/frontend/src/components/ResponsePanel.tsx +++ b/frontend/src/components/ResponsePanel.tsx @@ -3,7 +3,7 @@ import { MessageSquare, AlertCircle, Copy, ChevronDown, ChevronRight } from 'luc import ReactMarkdown from 'react-markdown' import type { SourceMetadata, SubQuestionSources } from '../types' import { getPdfViewerUrl } from '../lib/api' -import { processCitations, processCitationsForSubq, extractCitedSources } from '../utils/citationParser' +import { processCitations, processCitationsForSubq, extractCitedSources, highlightTerms } from '../utils/citationParser' import { bulletizeMarkdown } from '../utils/citationParser' function getHighlightUrl(document_id: string, chunk_index: number, sub_question: string): string { @@ -32,6 +32,10 @@ const CitationLink = ({ href, children }: { href?: string; children?: React.Reac ) +const HighlightMark = ({ children }: { children?: React.ReactNode }) => ( + {children} +) + function parseAnswerSections(answer: string): string[] { const sections = answer.split(/## Sub-question \d+:[^\n]*\n/) if (sections.length <= 1) return [bulletizeMarkdown(answer)] @@ -107,6 +111,7 @@ function SubQuestionSection({ sq.sources.map(s => ({ ...s, sub_question_text: sq.sub_question_text })) ) const processedAnswer = processCitations(answerSection, allSources, highlightReadyKeys) + const highlightedAnswer = highlightTerms(processedAnswer) return (
- - {processedAnswer} + + {highlightedAnswer}
@@ -353,6 +358,7 @@ function FlatResponse({ const safeSources = sources ?? [] const processedAnswer = answer ? processCitations(answer, safeSources) : answer ?? '' + const highlightedAnswer = processedAnswer ? highlightTerms(processedAnswer) : processedAnswer const handleCopyAnswer = async (): Promise => { if (answer) { @@ -454,9 +460,9 @@ function FlatResponse({
- {processedAnswer} + {highlightedAnswer}
diff --git a/frontend/src/styles.css b/frontend/src/styles.css index 3a03ad5..b994a85 100644 --- a/frontend/src/styles.css +++ b/frontend/src/styles.css @@ -10,3 +10,8 @@ list-style: decimal !important; padding-left: 1.5rem !important; } +.prose mark { + background-color: #FEF08A; + border-radius: 0.125rem; + padding: 0 0.125rem; +}