=== Nahnu Code & API Block ===
Contributors: ja1me4
Tags: code block, api documentation, syntax highlighting, gutenberg, rest api
Requires at least: 6.3
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A block suite for developer documentation: syntax-highlighted code snippets plus a full set of API-documentation blocks.

== Description ==

Nahnu Code & API Block gives the block editor everything a developer-facing site needs to document code and APIs: a polished syntax-highlighted code block, and a matching family of blocks purpose-built for API reference pages — endpoints, parameter tables, tabbed request/response examples, status code tables, authentication headers, and a live try-it console.

**The code block**

* Syntax highlighting for 20+ languages, powered by Prism.js and bundled with the plugin (no external CDN requests).
* Automatic light/dark mode: follows the visitor's OS preference, and can also follow a dark-mode class or attribute your theme or another plugin already sets on `<html>` or `<body>` (filterable).
* An optional per-block toggle button so visitors can flip a single code block between light and dark themes manually.
* Long snippets collapse to a configurable preview height with a "View all code" button that opens the complete snippet in a modal.
* One-click Copy button, optional line numbers.

**The API-documentation blocks**

* **Endpoint** — HTTP method badge, path, summary, version badge, and an optional deprecation notice.
* **Parameters** — a name / type / required-optional / description table.
* **Request / Response** — tabbed code examples per language (cURL, JavaScript, Python, PHP, and more), each with Request and Response sub-tabs. Language selection is synced and remembered across every Request/Response block on the same page.
* **Status Codes** — a table of the HTTP status codes your API returns, color-coded by class (2xx/3xx/4xx/5xx), with an optional collapsible example response body.
* **Authentication** — shows the exact header a client needs to send (Bearer token, API key, Basic auth, or OAuth 2.0), with a copy button.
* **Try It Console** — a live request form visitors can edit (URL, headers, body) and send directly from their own browser to see a real response. This performs a genuine client-side request; it never proxies or issues the call from your WordPress server.

All blocks share the same visual language and the same light/dark theming, so a full API reference page looks consistent throughout.

= External services and data =

Nahnu Code & API Block does not connect to any external service, API, or CDN at runtime, and does not collect, transmit, or store any personal data. The Prism.js syntax-highlighting library is bundled with the plugin files (MIT licensed) rather than loaded from a third-party server. The Try It Console block is the one exception worth being explicit about: when a site visitor clicks "Send request" on that block, their own browser makes a direct HTTP request to whatever URL is shown in that block (which the page author configured, and the visitor can edit). That request comes from the visitor's browser, not from your WordPress server, and nothing about it is seen by this plugin's author or by Nahnu.

== Installation ==

1. Upload the `nahnu-code-block` folder to `/wp-content/plugins/`, or install the plugin through the **Plugins → Add New** screen in your WordPress admin.
2. Activate the plugin through the **Plugins** screen.
3. Edit any post or page, add a new block, and search for "Nahnu" to see the full set of code and API blocks.
4. Configure each block from its sidebar settings.

== Frequently Asked Questions ==

= Does this send my code anywhere? =

No. Everything is rendered on your own server and in the visitor's browser. The plugin makes no external network requests, with the one exception noted above for the Try It Console, which is a request the visitor themselves chooses to send.

= Will this conflict with my theme's or another plugin's dark mode switcher? =

It's designed to cooperate rather than compete. By default it follows the visitor's OS-level light/dark preference. You can also use the `nahnu_code_block_dark_mode_selectors` filter to tell it which CSS selector your existing dark-mode plugin toggles (for example `body.dark-mode`), so the code block switches along with the rest of your site.

= Can I integrate my own dark-mode toggle with this plugin? =

Yes. If your theme or plugin already sets a class or attribute for dark mode (like `body.dark-mode`), add it via the `nahnu_code_block_dark_mode_selectors` PHP filter and it works automatically, with no JavaScript required. If your toggle is JavaScript-driven, call `window.NahnuCodeBlock.setTheme('dark' | 'light' | 'auto')` from your own click handler. Full details, including how to rebrand the actual colors, are in `HOOKS.md` in the plugin folder.

= Can I change the syntax highlighting or table colors? =

Yes. All colors are exposed as CSS custom properties scoped to `.nahnu-code-block` (for example `--nahnu-code-block-token-string`), so they can be overridden from your theme's stylesheet without touching plugin files.

= Is the Try It Console safe to use? =

It only ever performs a request from the visitor's own browser to a URL you configure (and the visitor can see and edit before sending). It does not run on, or route through, your WordPress server, so it can't be used to make your server call arbitrary internal or external URLs.

= Does it work with the Classic Editor? =

No. These are blocks for the block editor (Gutenberg).

== Screenshots ==

1. An Endpoint block and a code block together on a documentation page.
2. The "View all code" modal, opened from a collapsed code block.
3. The Try It Console alongside Authentication, Endpoint, and Parameters blocks.
4. Editing an Endpoint block's settings in the block editor.

== Changelog ==

= 1.0.0 =
* First public WP.org version.

== Upgrade Notice ==

= 1.0.0 =
First public WP.org version.
