feat: slash menu navigation, removed gutter button, fixed AI richtext format, added image resize
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 44s

This commit is contained in:
2026-05-02 23:31:40 +02:00
parent 6d6e12ba05
commit e4ca7ba497
4 changed files with 107 additions and 52 deletions

View File

@@ -67,7 +67,8 @@ export class ParagraphRefactorService {
*/
async refactor(
content: string,
mode: RefactorMode
mode: RefactorMode,
format: 'html' | 'markdown' = 'markdown'
): Promise<RefactorResult> {
// Validate word count
const wordCount = content.split(/\s+/).length
@@ -82,8 +83,8 @@ export class ParagraphRefactorService {
try {
// Build prompts
const systemPrompt = this.getSystemPrompt(mode)
const userPrompt = this.getUserPrompt(mode, content, language)
const systemPrompt = this.getSystemPrompt(mode, format)
const userPrompt = this.getUserPrompt(mode, content, language, format)
// Get AI provider from factory
const config = await getSystemConfig()
@@ -210,25 +211,29 @@ IMPORTANT: Provide all 3 versions in ${language}. No English, no explanations.`
/**
* Get mode-specific system prompt
*/
private getSystemPrompt(mode: RefactorMode): string {
private getSystemPrompt(mode: RefactorMode, format: 'html' | 'markdown' = 'markdown'): string {
const formatInstruction = format === 'html'
? "\nCRITICAL FORMAT RULE: You MUST return your response as valid HTML fragments (e.g., using <p>, <strong>, <em>, <ul>, etc.) without markdown symbols. Do not wrap in a markdown code block."
: "\nCRITICAL FORMAT RULE: You MUST return your response as plain text or Markdown."
const prompts = {
clarify: `You are an expert at making text clearer and more understandable.
Your goal: Rewrite the text to eliminate ambiguity, add necessary context, and improve clarity.
CRITICAL LANGUAGE RULE: You MUST respond in the EXACT SAME LANGUAGE as the input text. If input is French, output MUST be French. If input is German, output MUST be German. NEVER translate to English.
Maintain the original meaning and tone, just make it clearer.`,
Maintain the original meaning and tone, just make it clearer.${formatInstruction}`,
shorten: `You are an expert at concise writing.
Your goal: Reduce the text length by 30-50% while preserving ALL key information and meaning.
CRITICAL LANGUAGE RULE: You MUST respond in the EXACT SAME LANGUAGE as the input text. If input is French, output MUST be French. If input is German, output MUST be German. NEVER translate to English.
Remove fluff, repetition, and unnecessary words, but keep the substance.`,
Remove fluff, repetition, and unnecessary words, but keep the substance.${formatInstruction}`,
improveStyle: `You are an expert editor with a focus on readability and flow.
Your goal: Enhance the text's style, vocabulary, sentence structure, and overall quality.
CRITICAL LANGUAGE RULE: You MUST respond in the EXACT SAME LANGUAGE as the input text. If input is French, output MUST be French. If input is German, output MUST be German. NEVER translate to English.
Maintain similar length but make it sound more professional and polished.`
Maintain similar length but make it sound more professional and polished.${formatInstruction}`
}
return prompts[mode]
@@ -237,7 +242,7 @@ Maintain similar length but make it sound more professional and polished.`
/**
* Get mode-specific user prompt
*/
private getUserPrompt(mode: RefactorMode, content: string, language: string): string {
private getUserPrompt(mode: RefactorMode, content: string, language: string, format: 'html' | 'markdown' = 'markdown'): string {
const instructions = {
clarify: `IMPORTANT: The text below is in ${language}. Your response MUST be in ${language}. Do NOT translate to English.
@@ -256,12 +261,12 @@ Please improve the style and readability of this ${language} text:`
${content}
CRITICAL: Respond ONLY with the refactored text in ${language}. No explanations, no meta-commentary, no English.`
CRITICAL: Respond ONLY with the refactored text in ${language}. No explanations, no meta-commentary, no English. Format strictly as ${format === 'html' ? 'HTML tags' : 'Markdown'}.`
}
/**
* Extract refactored text from AI response
* Handles JSON, markdown code blocks, or plain text
* Handles JSON, markdown code blocks, or HTML/plain text
*/
private extractRefactoredText(response: string): string {
// Try JSON first
@@ -275,12 +280,18 @@ CRITICAL: Respond ONLY with the refactored text in ${language}. No explanations,
}
}
// Try markdown code block
const codeBlockMatch = response.match(/```(?:markdown)?\n([\s\S]+?)\n```/)
// Try markdown code block (HTML or Markdown)
const codeBlockMatch = response.match(/```(?:markdown|html)?\n([\s\S]+?)\n```/)
if (codeBlockMatch) {
return codeBlockMatch[1].trim()
}
// Try bare HTML if wrapped in a single code block
const genericCodeBlockMatch = response.match(/```\n([\s\S]+?)\n```/)
if (genericCodeBlockMatch) {
return genericCodeBlockMatch[1].trim()
}
// Fallback: trim whitespace and quotes
return response.trim().replace(/^["']|["']$/g, '')
}