Repository navigation
fix: prevent markdown code fences in AI-generated post content - #1
Merged
Merged
Conversation
Collaborator
|
@EdithAllison looks good to me, I'm going to ask CoPilot to review as well. |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the workshop instructions to reduce the chance that AI-generated post HTML is wrapped in Markdown code fences, and adds a defensive fallback to strip fences if they still appear.
Changes:
- Extend the content-generation prompt to explicitly forbid Markdown code fences.
- Add two
preg_replacecalls in the documentedwp_ai_workshop_generate_content()example to strip opening/closing fences.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Strip markdown code fences from AI-generated post content
When generating post content, the AI model occasionally wraps its response in a markdown code fence (
html ...), which gets saved verbatim into the post instead of the actual HTML.This PR fixes that in two ways:
Prompt update — instructs the model not to wrap the response in code fences
Fallback strip — uses preg_replace to remove any
html opener orcloser in case the model ignores the instructionThe defensive fallback is intentional: LLMs don't always follow prompt instructions reliably, so the regex ensures the bug can't reappear even if the model regresses.
File changed: includes/content.php
Code fix generated by Claude Code AI