=== Berq Markdown – Markdown Pages for AI & LLM Crawlers ===
Contributors: berqwp, thevisionofhamza
Tags: markdown, llm, ai, seo, sitemap
Requires at least: 6.6
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.1.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Serve any WordPress page or post as a clean Markdown file optimized for AI and LLM crawlers by appending .md to the URL.

== Description ==

Berq Markdown makes your WordPress content instantly consumable by AI assistants, LLM crawlers (GPTBot, ClaudeBot, Googlebot-AI), and Markdown-aware tools — without duplicating your content or creating separate pages.

Appending `.md` to any public page or post URL (e.g. `https://example.com/about.md`) returns a clean, structured Markdown file with YAML frontmatter. The plugin handles content from all common sources: Gutenberg blocks, classic editor, shortcodes, and custom PHP templates.

**How it works**

When a visitor or crawler requests `/about.md`, the plugin intercepts the request, finds the matching WordPress post, converts the HTML content to Markdown, and serves it with the correct `Content-Type: text/markdown` header — all without creating any new database entries or files.

**Key Features**

* **Automatic .md URLs** — any public post or page URL + `.md` returns clean Markdown
* **YAML frontmatter** — every .md file includes `title`, `description`, `url`, `date_modified`, `author`, and `language`
* **Full content compatibility** — works with Gutenberg blocks, classic editor, shortcodes, and custom PHP page templates
* **HTML to Markdown conversion** — pure PHP, no external dependencies; handles headings, paragraphs, lists, links, images, tables, code blocks, and more
* **Internal link rewriting** — links to internal pages are rewritten to their `.md` equivalent automatically
* **URL exclusions with wildcards** — exclude specific URL patterns using `*` as a wildcard (e.g. `/cart/*`, `*/checkout*`)
* **Post type selection** — choose which post types (posts, pages, custom post types) are served as Markdown
* **Transient caching** — optional cache with configurable TTL to reduce server load at scale
* **`<link>` tag injection** — injects a `<link rel="alternate" type="text/markdown">` tag in every page's `<head>` so crawlers can discover the .md version
* **`[btrmd313_md_link]` shortcode** — renders a link to the current page's `.md` file, opens in a new tab
* **Multilingual support** — detects language via Polylang or WPML, adds `language` and `alternates` to frontmatter and emits `hreflang` link tags
* **Public content rendering** — always renders content as a non-logged-in visitor, so member-only sections are not exposed
* **Admin settings page** — all options configurable under Settings > Berq Markdown, with a Settings link on the Plugins page

== Installation ==

1. Upload the `berq-markdown` folder to `/wp-content/plugins/`
2. Activate the plugin through the **Plugins** menu in WordPress
3. Go to **Settings > Permalinks** and click **Save Changes** to flush rewrite rules (required once after activation)
4. Visit any page URL with `.md` appended — e.g. `https://yoursite.com/about.md`
5. Optionally configure the plugin under **Settings > Berq Markdown**

== Frequently Asked Questions ==

= Does this create duplicate content? =

No. The `.md` URLs are separate endpoints that return `Content-Type: text/markdown` — search engines treat them differently from HTML pages. The plugin also sends `X-Robots-Tag: noindex, follow` by default to prevent indexing of the Markdown versions.

= Will it work with my page builder? =

Yes. The plugin renders content the same way WordPress does for a logged-out visitor — using the full `the_content` filter chain, which includes Gutenberg blocks and most page builders. For pages using custom PHP templates with no `post_content`, it falls back to output-buffering the template and extracting the body content.

= How do I exclude certain pages from .md serving? =

Go to **Settings > Berq Markdown > URL Exclusions** and enter one URL pattern per line. Use `*` as a wildcard. Examples: `/cart/*`, `*/checkout*`, `/my-account/`.

= Does it work with Yoast SEO? =

Yes. When Yoast SEO is active, the plugin registers as a custom sitemap provider so your `.md` URLs appear in the Yoast sitemap index. It also reads Yoast's meta description for the frontmatter `description` field.

= Does it support custom post types? =

Yes. Go to **Settings > Berq Markdown > Post Types** and check any registered public post type you want to include.

= Is caching enabled by default? =

No — caching is disabled by default so you always see fresh content during development. Enable it under **Settings > Berq Markdown > Cache** when you are ready to scale.

= What shortcode is available? =

`[btrmd313_md_link]` — outputs a link to the current page's `.md` version, opening in a new tab.

Optional attributes:
* `text` — link label (default: "View as Markdown")
* `class` — additional CSS class(es)

Example: `[btrmd313_md_link text="Read as Markdown" class="my-button"]`

= Does it support multilingual sites? =

Yes. The plugin detects language via Polylang or WPML. It adds a `language` field to the frontmatter and an `alternates` block listing all translated `.md` URLs. It also emits `<link rel="alternate" hreflang="...">` tags in the HTML `<head>`.

= Does it work with caching plugins? =

Yes. The plugin serves `.md` files before WordPress loads any theme template. Cache plugins that operate at the HTTP level (e.g. full-page caching) may cache `.md` responses — this is fine and actually beneficial for performance.

== Screenshots ==

1. Settings page — General, Post Types, Exclusions, Cache, Headers, Advanced

== Changelog ==

= 1.1.0 =
* Fix: MD files now served with correct 200 HTTP status (WordPress was setting 404 before template_redirect fired)
* Fix: Home page `.md` URL corrected — `/index.md` instead of broken `site.local.md`
* Fix: `url_to_postid()` trailing slash sensitivity — now tries URL both with and without trailing slash
* Fix: PHP template pages with empty `post_content` now rendered correctly via output buffer
* Fix: HTML comments (including Gutenberg block delimiters) stripped from Markdown output
* Fix: Heading whitespace normalized — multi-line headings collapse to a single line
* Fix: Inline tags inside headings stripped to plain text
* Fix: Description frontmatter field no longer wrapped in unnecessary quotes
* Fix: Cache disabled by default — opt-in instead of opt-out
* Fix: WordPress Plugin Check compliance — text domain corrected, `parse_url` → `wp_parse_url`, `strip_tags` → `wp_strip_all_tags`, variable prefixing in uninstall
* Feature: Post type selection — choose which post types are served as `.md` files
* Feature: Multilingual support — `language` and `alternates` frontmatter fields, `hreflang` link tags (Polylang and WPML)
* Feature: Internal links inside Markdown output rewritten to `.md` equivalents automatically
* Feature: `[btrmd313_md_link]` shortcode — renders a link to the current page's `.md` file
* Feature: Template pages rendered as non-logged-in visitor for accurate public content
* Feature: Admin bar suppressed during template output buffering

= 1.0.0 =
* Initial release
* .md URL serving with YAML frontmatter
* HTML to Markdown conversion (pure PHP, DOMDocument)
* Gutenberg block, shortcode, and custom template support
* URL exclusions with wildcard support
* Post type selection
* Transient cache with configurable TTL
* `<link rel="alternate">` injection in HTML head
* `[btrmd313_md_link]` shortcode
* Yoast SEO sitemap integration + generic md-sitemap.xml fallback
* Multilingual support (Polylang, WPML) — language frontmatter + hreflang tags
* Internal link rewriting to .md equivalents
* Non-logged-in rendering for accurate public content
* Admin settings page under Settings > Berq Markdown

== Upgrade Notice ==

= 1.0.0 =
Initial release. After activation, visit Settings > Permalinks and click Save to flush rewrite rules.
