=== Morick Markdown Layer for AI ===
Contributors: moricktokyo
Tags: markdown, ai, llms-txt, llm, agents
Requires at least: 5.3
Tested up to: 7.1
Requires PHP: 7.2
Stable tag: 1.4.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Adds an AI-agent-friendly Markdown layer to your existing site: ?ai=1 URLs, Accept header negotiation, /llms.txt, and alternate links.

== Description ==

AI assistants and crawlers (GPTBot, ClaudeBot, Perplexity, and others) increasingly read the web to answer users' questions. HTML pages built for humans are heavy and noisy for them: navigation, scripts, and styling bury the actual content.

Morick Markdown Layer for AI adds a lightweight, machine-friendly **Markdown layer** on top of your existing site - without changing your theme, your URLs, or anything your human visitors see.

= What it does =

* **Markdown version of every page.** Append `?ai=1` to any post, page, or archive URL and the plugin returns clean Markdown (with YAML frontmatter: title, description, canonical URL, dates, categories) instead of HTML.
* **Content negotiation.** Clients that send an `Accept: text/markdown` header receive Markdown at the normal URL - no query parameter needed.
* **/llms.txt generation.** The plugin dynamically serves an `llms.txt` index: your site name, description, and a link list of all Markdown-enabled pages, so AI agents can discover your content in one request.
* **Alternate link tags.** Each HTML page advertises its Markdown version via `<link rel="alternate" type="text/markdown">` in the head, which is how AI crawlers actually discover and follow the Markdown layer.
* **Admin checklist.** A dashboard screen lists every target page with its status (Auto / Manual / Excluded), body length, sortable columns, status filters, and title search.
* **Manual Markdown override.** For template-driven landing pages whose HTML converts poorly, write Markdown by hand per page. Manual Markdown always wins over auto conversion.
* **Automatic exclusion.** Pages whose converted body falls below a configurable length threshold are excluded automatically (thin content is worse than no content for AI consumption).
* **No dependencies.** The HTML-to-Markdown converter is a self-contained DOM walker. No Composer packages, no external services, no API calls, no data leaves your server.

= How conversion is resolved =

For each Markdown request the plugin resolves in this order:

1. Manual Markdown exists for the page - serve it (threshold ignored).
2. Otherwise, if the auto-converted body meets the length threshold - serve the auto conversion.
3. Otherwise the page is excluded: no Markdown is served and no alternate link is printed.

= SEO safety =

The Markdown response sends a `Link: <original-url>; rel="canonical"` HTTP header pointing back to the HTML page, plus `Cache-Control: no-store`, so the Markdown layer does not compete with your HTML pages in search engines.

= Performance =

Converted Markdown is cached per page in transients and invalidated automatically when the post is saved. The archive (`llms.txt`) and page lists are capped and filterable via the `mdlai_post_types` and `mdlai_list_limit` hooks.

== Installation ==

1. Upload the `morick-markdown-layer-ai` folder to `/wp-content/plugins/`, or install through the WordPress Plugins screen.
2. Activate the plugin.
3. Open the **Markdown Layer** menu in your dashboard.
4. Choose the target post types and taxonomies, set the body length threshold, and save.
5. Verify: open any page with `?ai=1` appended, and open `/llms.txt`.

== Frequently Asked Questions ==

= Does this change what human visitors see? =

No. Regular visitors receive your normal HTML. Markdown is only served when a client explicitly asks for it (`?ai=1` or an `Accept: text/markdown` header).

= Will the Markdown pages hurt my SEO? =

The Markdown response carries a canonical HTTP header pointing to the original HTML URL and a no-store cache policy. Search engines are directed to treat the HTML page as the canonical version.

= Do AI crawlers actually use this? =

In our production measurements, AI crawlers discovered the Markdown layer through the alternate link tags within days of release and began fetching Markdown versions directly - in some cases skipping the HTML entirely. Adoption varies by vendor and grows over time.

= What happens to pages with very little content? =

Pages whose converted body is shorter than the threshold (default 20 characters) are excluded: no Markdown version, no alternate link. You can still serve them by writing manual Markdown on the checklist screen.

= Where is manual Markdown stored? =

In post meta / term meta on your own database (`_mdlai_manual`). Uninstalling the plugin removes its settings and caches but intentionally preserves your manual Markdown, so you do not lose hand-written content if you reinstall. Delete the meta keys manually if you want a complete wipe.

= Does the plugin call any external service? =

No. Everything runs locally. Nothing is sent anywhere.

== Changelog ==

= 1.4.1 =
* Renamed to "Morick Markdown Layer for AI" (distinctive branding). Text domain updated.
* Removed bundled translation files (translations will be served via translate.wordpress.org).

= 1.4.0 =
* First public release on WordPress.org.
* Internationalization: all admin strings are translatable; Japanese translation bundled.
* Hardened input sanitization (`REQUEST_URI`, `HTTP_ACCEPT`, list table parameters).
* llms.txt intro line is now translatable.

= 1.3.0 =
* Manual Markdown save date is reflected in the frontmatter `modified` field.
* Editor textarea now pre-fills with the auto-converted draft when no manual Markdown exists.
* Images are normalized to one per line.

= 1.2.0 =
* Admin checklist rebuilt on WP_List_Table: sortable columns, status filter views, title search, pagination.

= 1.1.0 =
* Accept header negotiation, llms.txt generation, alternate link output.

= 1.0.0 =
* Initial internal release: ?ai=1 Markdown serving with automatic HTML-to-Markdown conversion.

== Upgrade Notice ==

= 1.4.0 =
First WordPress.org release. Admin UI language is now English with a bundled Japanese translation.
