Advanced Integrations for an AI Content Analyzer
Posted on By Carl Cruz | Last updated on | In Editor, General
In the last post, we introduced our internal content analyzer. That tool is great for a high-level score, but its “input-process-output” model is just the beginning. The real opportunity is to build a more dynamic and integrated experience.
This article is for developers who saw that analyzer and thought, “What’s next?” We’ll explore three practical ways to evolve a content analysis tool using the Froala editor’s deeper API features.
Key Takeaways
- Embed AI suggestions directly into the editor text using
html.set(). - Use the official Froala Filestack plugin to handle direct
.docxfile uploads. - Leverage the plugin’s events to create a custom document-to-HTML workflow.
- Use the editor’s
contentChangedevent to create a “live linting” experience. - Debounce editor events to ensure optimal application performance.
Embed Feedback Directly into the Text
A common limitation of analyzer tools is the separation of feedback from the content itself. We can fix this by putting the AI’s suggestions right where they belong, transforming static text into interactive annotations.
The API Implementation
After your application gets a response from the AI, it can parse the suggestions and programmatically rewrite the editor’s content. By wrapping the targeted text in a custom <span> tag using html.set(), you can highlight the area and use a title attribute to show the AI’s note on hover.
/**
* A hypothetical function after receiving AI feedback.
* Applies suggestions to the Froala Editor's content,
* highlighting the original text with feedback as a tooltip.
*/
function applySuggestions(suggestions) {
let modifiedContent = froalaEditor.html.get();
// Your logic to find and replace text would go here
suggestions.forEach(suggestion => {
modifiedContent = modifiedContent.replace(
suggestion.originalText,
`<span class="suggestion" title="${suggestion.feedback}">${suggestion.originalText}</span>`
);
});
froalaEditor.html.set(modifiedContent);
}
Integrate a Document Upload Workflow
Writers work in document editors. A professional tool should handle .docx files directly, not force a copy-paste workflow. Instead of building a custom uploader, we can use the official Froala Filestack plugin to handle this.
The goal is to use the plugin to upload a .docx file, but instead of inserting a link to that file, we will intercept the upload, convert the document to HTML on our backend, and then load that HTML into the editor.
The API Implementation
This approach relies on using the plugin’s built-in filestack.uploadedToFilestack event. We configure the plugin with our API key and then use the event to trigger our custom conversion logic.
- The user clicks the ‘Insert File’ button, which is now powered by Filestack.
- They upload a
.docxfile using the Filestack picker. - The
filestack.uploadedToFilestackevent fires, providing the URL of the uploaded file. - Our custom logic sends this URL to a backend service for conversion.
- The editor’s
html.set()method is called to insert the final, converted HTML.
/**
* Initializes the Froala Editor with the Filestack plugin,
* configured for a custom DOCX workflow.
*/
new FroalaEditor('#editor', {
// Ensure the 'insertFile' button is available in the toolbar.
toolbarButtons: ['bold', 'italic', '|', 'insertFile'],
// Basic Filestack plugin configuration.
filestackOptions: {
filestackAPI: 'YOUR_FILESTACK_API_KEY', // Replace with your actual Filestack API key.
pickerOptions: {
accept: ['.docx', '.doc'] // Only allow .docx and .doc files to be picked.
}
},
events: {
// This plugin event is crucial for our custom workflow.
// It triggers after a file has been successfully uploaded to Filestack.
'filestack.uploadedToFilestack': function (response) {
// The plugin has handled the file upload; now we take over.
const fileUrl = response.filesUploaded[0].url; // Get the URL of the uploaded file.
const editorInstance = this; // 'this' refers to the Froala editor instance.
// This would be your function that calls a backend service
// to convert the document at the given URL into HTML.
convertDocxToHtml(fileUrl).then(html => {
// Once the HTML is received, set it as the editor's content.
editorInstance.html.set(html);
});
// Return 'false' to prevent the default behavior of the Filestack plugin,
// which would typically insert a link to the uploaded file.
return false;
}
}
});
Build Real-Time Analysis with Editor Events
A manual “Analyze” button is useful, but we can provide more immediate value with real-time feedback. The goal is to create a “live linting” experience that offers suggestions as the user writes.
The Froala Events API is the foundation for this feature.
The API Implementation
You can listen for the contentChanged event to trigger actions whenever the user types. To avoid performance issues, you must “debounce” this event so your analysis function only runs after the user has paused typing for a moment.
// Assumes you have a debounce utility function from a library like Lodash.
// This function delays the execution of 'updateRealtimeFeedback'
// until 1.5 seconds after the user stops typing or making changes.
const debouncedAnalysis = debounce(() => {
let currentContent = froalaEditor.html.get();
// Run your lightweight, real-time content analysis here.
updateRealtimeFeedback(currentContent);
}, 1500); // 1.5 second delay
// Attach the debounced analysis function to the 'contentChanged' event of the editor.
froalaEditor.events.on('contentChanged', debouncedAnalysis);
Wrapping up the improvements
A basic content analyzer is a great start, but it’s just one possibility. These examples show how a rich editor with a deep API is not just an input field but a platform for building integrated and powerful applications. By using the API to handle content manipulation, custom UI, and events, you can move beyond simple analysis and create tools that actively improve a writer’s workflow.
Carl Cruz
Carl is a Product Marketing Manager at Froala with four years of hands-on experience in React, JavaScript, Django, and Python. He bridges the gap between product and developer, breaking down how Froala’s rich text editor works under the hood into content that’s genuinely useful for the engineers integrating it. His writing covers custom plugin development, framework integrations, and real-world implementation patterns, written from the perspective of someone who has built with these tools firsthand.
No comment yet, add your voice below!