Generate a markdown version of (formatted) text field values
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3574004. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
>>>
<p>[Tracker]<br>
<strong>Update Summary: </strong>[One-line status update for stakeholders]<br>
<strong>Short Description: </strong>[One-line issue summary for stakeholders]<br>
<strong>Check-in Date: </strong>MM/DD/YYYY<br>
<em>Metadata is used by the <a href="https://www.drupalstarforge.ai/" title="AI Tracker">AI Tracker.</a> Docs and additional fields <a href="https://www.drupalstarforge.ai/ai-dashboard/docs" title="AI Issue Tracker Documentation">here</a>.</em><br>
[/Tracker]</p>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>AI Automator currently strips HTML tags from formatted text fields when processing content in <code>\Drupal\ai_automators\PluginBaseClasses\RuleBase::generateTokens()</code>. This results in the loss of important semantic meaning, particularly for structured content like tables, lists, and other formatted elements that convey critical information to AI models.</p>
<p>When formatted text fields are passed to AI providers, the HTML structure is removed entirely, which can significantly reduce the quality and context of the content being processed. This affects the AI's ability to understand the relationships between different pieces of content and properly interpret structured data.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Please provide information like AI modules enabled, which AI provider, browser, etc.</p>
<ol>
<li>Create a content type with a formatted text field (e.g., Body field with Full HTML format)</li>
<li>Add an AI Automator to another field on the same content type, using the formatted text field as the base field or in a token</li>
<li>Add content to the formatted text field that includes HTML tables, lists, or other structured markup</li>
<li>Save the entity and observe that the AI Automator processes the content without the HTML structure</li>
<li>Expected result: The structured content (tables, lists, etc.) should be preserved in a format that maintains semantic meaning for AI processing</li>
<li>Actual result: HTML tags are stripped, causing tables and other structured content to lose their formatting and context</li>
</ol>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Convert HTML content to Markdown format instead of stripping tags entirely. The AI module already depends on the <code>league/html-to-markdown</code> library, which is used in multiple places throughout the module. Leveraging this existing dependency in <code>RuleBase::generateTokens()</code> would preserve semantic structure while providing AI models with clean, well-formatted content.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
<h3 id="summary-ai-usage">AI usage (if applicable)</h3>
<p>[ ] AI Assisted Issue<br>
This issue was generated with AI assistance, but was reviewed and refined by the creator.</p>
<p>[ ] AI Assisted Code<br>
This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision.</p>
<p>[ ] AI Generated Code<br>
This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human.</p>
<p>[ ] Vibe Coded<br>
This code was generated by an AI and has only been functionally tested.</p>
issue