Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions GUI/src/components/Markdowify/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ const LinkPreview: React.FC<{

const hasSpecialFormat = (m: string) => m.includes('\n\n') && m.indexOf('.') > 0 && m.indexOf(':') > m.indexOf('.');

function formatMessage(message?: string): string {
if (!message) return '';

const filteredMessage = message
.replaceAll(/\\?\$b\w*/g, '')
.replaceAll(/\\?\$v\w*/g, '')
.replaceAll(/\\?\$g\w*/g, '');

return filteredMessage
.replaceAll(/&#x([0-9A-Fa-f]+);/g, (_, hex: string) => String.fromCharCode(parseInt(hex, 16)))
.replaceAll(/(^|\n)(\d{4})\.\s/g, (match, prefix, year) => {
const remainingText = filteredMessage.substring(filteredMessage.indexOf(match) + match.length);
const sentenceEnd = remainingText.indexOf('\n\n');
if (sentenceEnd !== -1) {
const currentSentence = remainingText.substring(0, sentenceEnd);
if (currentSentence.trim().endsWith(':')) {
return `${prefix}${year}. `;
}
}
return `${prefix}${year}\\. `;
})
.replace(/(?<=\n)\d+\.\s/g, hasSpecialFormat(filteredMessage) ? '\n\n$&' : '$&');
}

const Markdownify: React.FC<MarkdownifyProps> = ({ message, sanitizeLinks = false }) => (
<div className={'reset'}>
<Markdown
Expand All @@ -58,9 +82,7 @@ const Markdownify: React.FC<MarkdownifyProps> = ({ message, sanitizeLinks = fals
disableParsingRawHTML: true,
}}
>
{message
?.replaceAll(/&#x([0-9A-Fa-f]+);/g, (_, hex: string) => String.fromCodePoint(Number.parseInt(hex, 16)))
?.replaceAll(/(?<=\n)\d+\.\s/g, hasSpecialFormat(message) ? '\n\n$&' : '$&') ?? ''}
{formatMessage(message)}
</Markdown>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion GUI/src/services/service-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export function getYamlContent(
}

if (parentNode.data.stepType === StepType.MultiChoiceQuestion) {
return handleMultiChoiceQuestion(finishedFlow, parentStepName, parentNode, childNode);
return handleMultiChoiceQuestion(finishedFlow, parentStepName, parentNode, childNode, name);
}

if (parentNode.data.stepType === StepType.DynamicChoices) {
Expand Down Expand Up @@ -711,7 +711,12 @@ function handleMultiChoiceQuestion(
parentStepName: string,
parentNode: Node<NodeDataProps>,
childNode: Node<NodeDataProps> | undefined,
serviceName: string,
) {
parentNode.data.multiChoiceQuestion?.buttons.forEach(
(b) => (b.payload = b.payload.replaceAll('/_mcq_', `/${serviceName}_mcq_`)),
);

return finishedFlow.set(parentStepName, {
assign: {
buttons: parentNode?.data?.multiChoiceQuestion?.buttons ?? [],
Expand Down