From e89657380fbc8227f8f4fa60f5d3fc1a100f5c2b Mon Sep 17 00:00:00 2001 From: Jean Schmitz Date: Tue, 5 Mar 2024 11:26:54 +0100 Subject: [PATCH] Fix for transformer markdown --- .../transformers/MarkdownTextTransformer.java | 35 +++++++++++++++++++ .../transformers/MessageProcessor.java | 1 + 2 files changed, 36 insertions(+) create mode 100644 backend/src/main/java/com/talkforgeai/backend/transformers/MarkdownTextTransformer.java diff --git a/backend/src/main/java/com/talkforgeai/backend/transformers/MarkdownTextTransformer.java b/backend/src/main/java/com/talkforgeai/backend/transformers/MarkdownTextTransformer.java new file mode 100644 index 00000000..fc0b1088 --- /dev/null +++ b/backend/src/main/java/com/talkforgeai/backend/transformers/MarkdownTextTransformer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023-2024 Jean Schmitz. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.talkforgeai.backend.transformers; + +import com.talkforgeai.backend.transformers.dto.TransformerContext; +import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MarkdownTextTransformer implements Transformer { + + public static final Logger LOGGER = LoggerFactory.getLogger(MarkdownTextTransformer.class); + final Pattern boldRegEx = Pattern.compile("\\*\\*(.*)\\*\\*"); + + @Override + public String process(String content, TransformerContext context) { + return boldRegEx.matcher(content).replaceAll("$1"); + } + + +} diff --git a/backend/src/main/java/com/talkforgeai/backend/transformers/MessageProcessor.java b/backend/src/main/java/com/talkforgeai/backend/transformers/MessageProcessor.java index af818e43..bd74ef0a 100644 --- a/backend/src/main/java/com/talkforgeai/backend/transformers/MessageProcessor.java +++ b/backend/src/main/java/com/talkforgeai/backend/transformers/MessageProcessor.java @@ -44,6 +44,7 @@ public MessageProcessor(FileStorageService fileStorageService, transformers.add(new CodePhraseTransformer()); transformers.add(new MarkdownHeaderTransformer()); transformers.add(new MarkdownListTransformer()); + transformers.add(new MarkdownTextTransformer()); transformers.add(new NewLineTransformer()); transformers.add(new ImageDownloadTransformer(openAiService));