Skip to content

fix: prevent markdown code fences in AI-generated post content - #1

Merged
jonathanbossenger merged 2 commits into
wptrainingteam:trunkfrom
EdithAllison:html
May 28, 2026
Merged

jonathanbossenger merged 2 commits into
wptrainingteam:trunkfrom
EdithAllison:html

Conversation

@EdithAllison

@EdithAllison EdithAllison commented Apr 10, 2026 •

Copy link
Copy Markdown
Contributor

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 or closer in case the model ignores the instruction
The 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

@jonathanbossenger

Copy link
Copy Markdown
Collaborator

@EdithAllison looks good to me, I'm going to ask CoPilot to review as well.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_replace calls in the documented wp_ai_workshop_generate_content() example to strip opening/closing fences.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread WORKSHOP.md
Comment thread WORKSHOP.md Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jonathanbossenger
jonathanbossenger merged commit f626b5e into wptrainingteam:trunk May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants