Skip to content

Commit f758801

Browse files
committed
Add JSON content extraction logic to DocumentsService
Added a new regex-based extraction method to handle JSON content wrapped in triple backticks, improving the robustness of content parsing. This ensures that JSON data is correctly identified and processed when present in the input string.
1 parent 2557f1e commit f758801

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/KoalaWiki/KoalaWarehouse/DocumentsService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ await dbContext.DocumentOverviews.AddAsync(new DocumentOverview()
223223
str.Clear();
224224
str.Append(extractedContent);
225225
}
226+
else
227+
{
228+
// 尝试使用```json
229+
var jsonRegex = new Regex(@"```json(.*?)```", RegexOptions.Singleline);
230+
var jsonMatch = jsonRegex.Match(str.ToString());
231+
if (jsonMatch.Success)
232+
{
233+
// 提取到的内容
234+
var extractedContent = jsonMatch.Groups[1].Value;
235+
str.Clear();
236+
str.Append(extractedContent);
237+
}
238+
}
226239

227240
try
228241
{

0 commit comments

Comments
 (0)