Skip to content

Commit 42eec4a

Browse files
committed
fix(drupal): Output HTML instead of markdown from simplify prompt
Update the simplify prompt template to explicitly request HTML output format instead of markdown. CKEditor needs HTML tags (<p>, <h3>, <ul>, <strong>) rather than markdown syntax (**, #, -). Also update JavaScript to use editor.setData() for proper HTML handling instead of insertText() which treats content as plain text.
1 parent 3cb0be0 commit 42eec4a

2 files changed

Lines changed: 23 additions & 30 deletions

File tree

cloudformation/scenarios/localgov-drupal/drupal/web/modules/custom/ndx_aws_ai/js/ai-toolbar-buttons.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
* @param {Object} editor
131131
* The CKEditor 5 instance.
132132
* @param {string} newContent
133-
* The new content to insert.
133+
* The new HTML content to insert.
134134
* @param {boolean} hasSelection
135135
* Whether to replace selection only or full content.
136136
*/
@@ -139,30 +139,19 @@
139139
return;
140140
}
141141

142-
editor.model.change(function (writer) {
143-
if (hasSelection) {
144-
// Replace selected text only.
142+
if (hasSelection) {
143+
// For selected text, strip HTML and insert as plain text.
144+
var plainText = newContent.replace(/<[^>]*>/g, '');
145+
editor.model.change(function (writer) {
145146
var selection = editor.model.document.selection;
146147
var range = selection.getFirstRange();
147148
writer.remove(range);
148-
writer.insertText(newContent, range.start);
149-
} else {
150-
// Replace full body content.
151-
var root = editor.model.document.getRoot();
152-
var rootRange = writer.createRangeIn(root);
153-
writer.remove(rootRange);
154-
155-
// Insert new content as paragraphs.
156-
var paragraphs = newContent.split('\n\n');
157-
paragraphs.forEach(function (para) {
158-
if (para.trim()) {
159-
var paragraph = writer.createElement('paragraph');
160-
writer.insertText(para.trim(), paragraph);
161-
writer.insert(paragraph, root, 'end');
162-
}
163-
});
164-
}
165-
});
149+
writer.insertText(plainText, range.start);
150+
});
151+
} else {
152+
// For full content replacement, use setData to handle HTML properly.
153+
editor.setData(newContent);
154+
}
166155

167156
editor.editing.view.focus();
168157
}

cloudformation/scenarios/localgov-drupal/drupal/web/modules/custom/ndx_aws_ai/prompts/simplify.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ system: |
3737
* "in respect of" → "about" or "for"
3838
* "prior to" → "before"
3939
40-
4. PRESERVE FORMATTING
41-
- Keep lists as lists (bullet points, numbered lists)
42-
- Keep headings as headings
43-
- Keep paragraphs as paragraphs
44-
- Do not add new formatting that wasn't there
45-
- Do not remove formatting that was there
40+
4. OUTPUT FORMAT - HTML
41+
- Output valid HTML, NOT markdown
42+
- Use <p> tags for paragraphs
43+
- Use <ul><li> for bullet lists
44+
- Use <ol><li> for numbered lists
45+
- Use <h3> for headings (or match the original heading level)
46+
- Use <strong> for bold, <em> for italic
47+
- Do NOT use markdown syntax like ** or * or #
48+
- Keep the same structure as the input (if input had headings, keep headings)
4649
4750
5. KEEP THE MEANING
4851
- The simplified text must mean exactly the same thing
@@ -59,9 +62,10 @@ user: |
5962
6063
Remember:
6164
- Target reading age 9
62-
- Keep any lists, bullet points, or headings in the same format
65+
- Output as HTML (use <p>, <ul>, <ol>, <h3>, <strong> tags)
66+
- Do NOT use markdown formatting like ** or #
6367
- Explain essential technical terms briefly in parentheses
64-
- Output only the simplified text, nothing else
68+
- Output only the simplified HTML, nothing else
6569
6670
parameters:
6771
maxTokens: 1024

0 commit comments

Comments
 (0)