Nahnu Code & API Block

Опис

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, a short summary plus an optional longer description, version badge, an optional deprecation notice, an „Auth Required“ indicator, an „Operation ID“ for a stable deep-link anchor, a „See also“ list of related endpoints, and a copy-link icon for deep-linking directly to this endpoint.
  • Parameters — a name / type / location (query, path, header, cookie, body) / format / default value / example value / allowed values / validation range and pattern / nullable / read-only or write-only / required-optional / deprecated / description table, with support for nested object parameters (e.g. an address parameter with its own line1, city, etc.), linkable type references (e.g. „array of ProgramResponseDto“ linking to another Parameters block set up as that named schema), and a copy-link icon on each row for deep-linking to a specific parameter.
  • 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.
  • Response Body — a „Returns“ description, optional response headers shown as a persistent table, and one or more real response bodies grouped by status code, shown as an expandable accordion with syntax highlighting and its own copy button per response. An optional „Show Schema“ toggle switches a response between its real example and a lightweight type-shape table. Complements the Status Codes block: Status Codes is the quick-scan summary table, Response Body is the rich single-response view.
  • 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.
  • Error Codes — document your API’s error types and codes (e.g. invalid_request_error / parameter_missing), distinct from HTTP status codes, each with an optional expandable example error body.
  • Events — list the webhook/event names a resource can emit (e.g. customer.created), each with a description, an optional expandable example payload, and a copy-link icon.
  • API Navigation — auto-generates a jump-list of every Endpoint block on the current page. No manual list to keep in sync as you add or reorder endpoints; scans this page only, never your whole site.
  • Servers — list an API’s base URLs (production, sandbox, regional) each with a label and a copy button. Maps onto OpenAPI’s servers array, including server variable templating like {region}.

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.

Снимци екрана

Блокови

Овај додатак пружа 12 блокова.

  • API Request / Response Tabbed request and response code examples per language, synced across every request/response block on the page.
  • API Servers List an API's base URLs — production, sandbox, regional endpoints — each with a label and a copy button. Maps onto OpenAPI's 'servers' array.
  • API Response Body Show what an API endpoint actually returns: a 'Returns' description, response headers, and one or more real response bodies grouped by status code, each expandable with its own copy button and an optional 'Show Schema' toggle for the type shape.
  • API Endpoint Show an API endpoint's HTTP method, path, a short summary, and a longer description — with an optional deprecation notice and an auth-required indicator.
  • API Navigation Auto-generates a jump-list of every Endpoint block on this page — no manual list to keep in sync. Scans this page only, not your whole site.
  • API Parameters A parameters table for API documentation: name, type, location, format, default value, example value, allowed values, validation constraints, nullable, read-only/write-only, required/optional, deprecated, description, nested object fields, and linkable type references. Can also act as a named, linkable schema definition itself.
  • API Try It Console A live request console visitors can use to call your API directly from their browser and see the real response.
  • Nahnu Code Block A professional, syntax-highlighted code snippet block with light/dark mode, a collapsible preview, a copy button, and a full-code modal.
  • API Status Codes A table of HTTP status codes your API returns, with meaning, description, and an optional example body.
  • API Events List the webhook/event names a resource can emit (e.g. customer.created), each with a description and an optional example payload.
  • API Authentication Show how to authenticate against an API: bearer token, API key, basic auth, or OAuth 2.0.
  • API Error Codes Document your API's error types and codes (e.g. invalid_request_error / parameter_missing) — distinct from HTTP status codes, which are transport-level.

Постављање

  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.

ЧПП

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).

Прегледи

Нема рецензија за овај додатак.

Сарадници и градитељи

„Nahnu Code & API Block“ је софтвер отвореног кода. Следећи људи су допринели овом додатку.

Сарадници

Преведите „Nahnu Code & API Block“ на свој језик.

Заинтересовани сте за градњу?

Прегледајте код, проверите SVN складиште или се пријавите на белешку градње преко RSS-а.

Белешка о изменама

1.0.1

  • Added six new blocks: Response Body (status-code accordion with real response JSON), Error Codes (API-level error taxonomy, distinct from HTTP status codes), Events (webhook/event names), API Navigation (auto-generated jump-list of Endpoint blocks on the page), and Servers (base URLs, maps onto OpenAPI’s servers array).
  • Parameters block: added Format and Default value badges, support for nested object parameters (e.g. an address parameter with its own line1/city fields), parameter location (query/path/header/cookie/body, matching OpenAPI’s in field), a per-parameter Deprecated flag, and an Allowed-values (enum) field.
  • Added deep-linkable anchors: a copy-link icon on Parameters rows, Endpoint blocks, Error Codes, and Events, each generating a stable, page-unique URL you can share directly to that specific item.
  • Added nahnu_code_block_build_block_markup() — lets another plugin (e.g. a docs platform importing an OpenAPI spec) generate any of this plugin’s blocks programmatically, with correct WordPress block markup and sensible attribute defaults. Documented in the new INTEGRATION.md.
  • Added the nahnu_code_block_pre_attributes filter, for third-party plugins that scan the page and inject their own UI into <pre> elements (with a real example for WP Super Docs, which was colliding with this plugin’s own copy button and language label).
  • Security: filter-derived theme CSS is now stripped of characters that could break out of the <style> element it’s printed inside, following a WordPress.org review finding.
  • Fixed the Copy button not correctly scoping to the clicked item when a block has multiple independent code panels open at once (surfaced by the new Response Body block’s accordion).
  • Fixed two buttons (Auth and Request/Response) left referencing a CSS class removed during an earlier redesign, which meant they rendered with no styling at all.
  • Fixed table titles on the Parameters and Status Codes blocks losing their styling after the same redesign.
  • Corrected the Plugin URI in the plugin header, which pointed at a URL that didn’t resolve.

1.0.0

  • First public WP.org version.