Linux 软件免费装
Banner图

Nahnu Code & API Block

开发者 ja1me4
更新时间 2026年9月20日 13:10
PHP版本: 7.4 及以上
WordPress版本: 7.1
版权: GPLv2 or later
版权网址: 版权信息

标签

gutenberg syntax highlighting rest api code block api documentation

下载

1.0.0 1.0.1 1.0.2

详情介绍:

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 The API-documentation blocks See every block with a live, interactive demo at wpcodeapiblock.com/all-blocks, or browse the full block-by-block reference at wpcodeapiblock.com/docs/main/blocks. All blocks share the same visual language and the same light/dark theming, so a full API reference page looks consistent throughout. Site-wide colors can be set visually under Settings → Nahnu Code Block — no code required — and any single block can still override just its own colors for one-off branding. Using blocks outside the block editor Every block can also be rendered from a [nahnu_code_block block="..."] shortcode (for widgets, page builders, or classic-editor content) or directly from PHP via nahnu_code_block_render() (for theme templates) — see INTEGRATION.md. Both support the same per-instance color overrides as the settings page. 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.

安装:

  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.

屏幕截图:

  • The "View all code" modal, opened from a collapsed code block.
  • The Try It Console alongside Authentication, Endpoint, and Parameters blocks.
  • Editing an Endpoint block's settings in the block editor.

升级注意事项:

1.0.2 Adds nahnu_code_block_render()/nahnu_code_block_the() and a [nahnu_code_block] shortcode for rendering blocks outside post content, a Settings → Nahnu Code Block colors page, per-instance color overrides, a WordPress Shortcode code-block language with a live-preview toggle, and a fix for example shortcodes shown in a code block sometimes being executed by WordPress instead of displayed as inert text. No breaking changes. 1.0.1 Six new blocks (Response Body, Error Codes, Events, API Navigation, Servers, plus a significantly expanded Parameters block), deep-link anchors, and a security fix. No breaking changes. 1.0.0 First public WP.org version.

常见问题:

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, not by adding a block through the Classic Editor's UI. You can still place any block on a Classic Editor page (or anywhere else outside the block editor) using the [nahnu_code_block block="..."] shortcode, or by calling nahnu_code_block_render() from a template if you're a developer — see "Can I render a block from PHP or a theme template?" below.

Can I render a block from PHP or a theme template?

Yes. Since version 1.0.2, nahnu_code_block_render( 'endpoint', array( 'method' => 'GET', 'path' => '/v1/users' ) ) (and its echoing counterpart nahnu_code_block_the()) renders any of this plugin's blocks straight to HTML from a theme template, a widget, or a page-builder module — no post content or block editor required. The same thing is available as a [nahnu_code_block block="..."] shortcode for places that only accept shortcodes. Full details, including how to pass each block's attributes, are in INTEGRATION.md.

Can I customize the colors without writing code?

Yes. Settings → Nahnu Code Block has a color picker for each core color (accent, text, background, header/footer background, muted text, border) in both light and dark mode — every block on your site picks these up automatically, however it was added to the page, including blocks placed with the [nahnu_code_block] shortcode. A single block or shortcode instance can also override just its own colors (e.g. one partner-branded endpoint) without changing the site-wide palette — see HOOKS.md for the shortcode attributes and the equivalent PHP filter.

更新日志:

1.0.2 1.0.1 1.0.0