Skip to content

Commit 8a5e8b9

Browse files
committed
fix(chatbot): extractIntroduction() plus robuste
gère les cas où le code est compact (titre collé à l'en-tête, titre de la première réponse collé au message initial)
1 parent e5c6769 commit 8a5e8b9

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

app/js/core/chatbot/parsers/extractIntroduction.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { detectChoiceOption } from "./detectChoiceOption.mjs";
22

33
export function extractIntroduction(mdWithoutYaml) {
44
// On récupère la séparation entre la première partie des données (titre + message principal) et la suite avec les réponses possibles
5+
mdWithoutYaml = mdWithoutYaml.trim();
56
const mdWithoutYamlAndWithoutH1 = mdWithoutYaml.substring(1);
67
const possibleTitles = ["# ", "## ", "### ", "#### ", "##### "];
78
const indexOfFirstTitles = possibleTitles
89
.map((title) => mdWithoutYamlAndWithoutH1.indexOf(title))
910
.filter((index) => index > 0);
10-
const indexEndIntroduction = Math.min(...indexOfFirstTitles);
11+
const indexEndIntroduction =
12+
indexOfFirstTitles.length > 0
13+
? Math.min(...indexOfFirstTitles) + 1
14+
: mdWithoutYaml.length;
1115
const chatbotIntroduction = mdWithoutYaml.substring(0, indexEndIntroduction);
1216
// Gestion du titre
1317
const chatbotTitleMatch = chatbotIntroduction.match(/# .*/);

app/script.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)