Color mode

QR Code

Renders ```qr fenced code blocks into inline SVG QR codes at build time.

日本語

Overview

qrCode() replaces each ```qr code block with a <figure class="rb-qr"> containing an inline <svg> QR code. Encoding happens entirely at build time in Node; nothing is shipped to the browser. The plugin runs with order: -10, before code-enhance and code-tabs.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { qrCode } from "@riebeckite/plugin-qr-code";
 
export default defineConfig({
  // ...
  plugins: [
    qrCode({
      level: "M",
      margin: 1,
      width: 160,
      dark: "#000000",
      light: "#ffffff",
    }),
  ],
});
md
```qr
# caption: Project page
https://example.com/
```

The fence body is the text or URL to encode (trimmed). An empty body leaves the code block untouched and reports a @riebeckite/plugin-qr-code diagnostic.

Behavior

Each block becomes:

html
<figure class="rb-qr" data-qr="rendered" data-qr-level="M" data-qr-margin="1" style="--rb-qr-size:160px">
  <div class="rb-qr__canvas" role="img" aria-label="QR code"><svg>…</svg></div>
  <figcaption class="rb-qr__caption">
    <span class="rb-qr__caption-text">…</span>
    <a class="rb-qr__source" href="…">…</a>
  </figcaption>
</figure>
  • data-qr is "rendered" on success and "error" when the encoder is unavailable or the block cannot be encoded.
  • The encoded payload is always rendered as plain text in figcaption.rb-qr__caption, so the value stays readable and copyable even without scanning the code. An http:, https:, mailto:, or tel: payload becomes an <a class="rb-qr__source">; anything else stays a <span>.
  • The card width follows the width option instead of the payload, so a long URL wraps rather than stretching the figure.
  • Errors and empty blocks report a snippet diagnostic with source: "@riebeckite/plugin-qr-code".

Encoder loading

The QR encoder (qrcode) is imported dynamically at build time, so bundlers never pull it into the site or client bundle. When the plugin is bundled into a temporary config module and the bare specifier no longer resolves, the loader falls back to node_modules discovered from process.cwd() and the pnpm virtual store.

Options

Option Type Default Description
level "L" | "M" | "Q" | "H" "M" Error-correction level
margin number 1 Quiet-zone size in modules
width number 160 Rendered size in pixels
size number — Alias of width
dark string "#000000" Dark-module colour
light string "#ffffff" Light-module colour
caption boolean true Show a caption from the title / # caption: line
className string "rb-qr" Figure CSS class
language string "qr" Fence language to intercept

The caption comes from the code-block title (code meta) or a leading # caption: … line. A leading caption line is removed from the encoded body.

Exports

  • qrCode(options?) — plugin factory
  • qrCodePlugin — alias of qrCode
  • resolveQrCodeOptions(options?) — normalise options
  • buildQrSvg(text, options) — encode text into an SVG string
  • Types: QrCodeOptions, ResolvedQrCodeOptions, QrCodeLevel, QrBuildResult

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/qr-code/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # QR Code
4 +
5 + Renders ` ```qr ` fenced code blocks into inline SVG QR codes at build time.
6 +
7 + [日本語](./qr-code.md)
8 +
9 + ## Overview
10 +
11 + `qrCode()` replaces each ` ```qr ` code block with a
12 + `<figure class="rb-qr">` containing an inline `<svg>` QR code. Encoding happens
13 + entirely at build time in Node; nothing is shipped to the browser. The plugin
14 + runs with `order: -10`, before `code-enhance` and `code-tabs`.
15 +
16 + ## Usage
17 +
18 + ```ts
19 + import { defineConfig } from "@riebeckite/core";
20 + import { qrCode } from "@riebeckite/plugin-qr-code";
21 +
22 + export default defineConfig({
23 + // ...
24 + plugins: [
25 + qrCode({
26 + level: "M",
27 + margin: 1,
28 + width: 160,
29 + dark: "#000000",
30 + light: "#ffffff",
31 + }),
32 + ],
33 + });
34 + ```
35 +
36 + ````md
37 + ```qr
38 + # caption: Project page
39 + https://example.com/
40 + ```
41 + ````
42 +
43 + The fence body is the text or URL to encode (trimmed). An empty body leaves the
44 + code block untouched and reports a `@riebeckite/plugin-qr-code` diagnostic.
45 +
46 + ## Behavior
47 +
48 + Each block becomes:
49 +
50 + ```html
51 + <figure class="rb-qr" data-qr="rendered" data-qr-level="M" data-qr-margin="1" style="--rb-qr-size:160px">
52 + <div class="rb-qr__canvas" role="img" aria-label="QR code"><svg>…</svg></div>
53 + <figcaption class="rb-qr__caption">
54 + <span class="rb-qr__caption-text">…</span>
55 + <a class="rb-qr__source" href="…">…</a>
56 + </figcaption>
57 + </figure>
58 + ```
59 +
60 + - `data-qr` is `"rendered"` on success and `"error"` when the encoder is
61 + unavailable or the block cannot be encoded.
62 + - The encoded payload is always rendered as plain text in
63 + `figcaption.rb-qr__caption`, so the value stays readable and copyable even
64 + without scanning the code. An `http:`, `https:`, `mailto:`, or `tel:` payload
65 + becomes an `<a class="rb-qr__source">`; anything else stays a `<span>`.
66 + - The card width follows the `width` option instead of the payload, so a long
67 + URL wraps rather than stretching the figure.
68 + - Errors and empty blocks report a snippet diagnostic with
69 + `source: "@riebeckite/plugin-qr-code"`.
70 +
71 + ### Encoder loading
72 +
73 + The QR encoder (`qrcode`) is imported dynamically at build time, so bundlers
74 + never pull it into the site or client bundle. When the plugin is bundled into a
75 + temporary config module and the bare specifier no longer resolves, the loader
76 + falls back to `node_modules` discovered from `process.cwd()` and the pnpm
77 + virtual store.
78 +
79 + ## Options
80 +
81 + | Option | Type | Default | Description |
82 + | ------ | ---- | ------- | ----------- |
83 + | `level` | `"L" \| "M" \| "Q" \| "H"` | `"M"` | Error-correction level |
84 + | `margin` | `number` | `1` | Quiet-zone size in modules |
85 + | `width` | `number` | `160` | Rendered size in pixels |
86 + | `size` | `number` | — | Alias of `width` |
87 + | `dark` | `string` | `"#000000"` | Dark-module colour |
88 + | `light` | `string` | `"#ffffff"` | Light-module colour |
89 + | `caption` | `boolean` | `true` | Show a caption from the title / `# caption:` line |
90 + | `className` | `string` | `"rb-qr"` | Figure CSS class |
91 + | `language` | `string` | `"qr"` | Fence language to intercept |
92 +
93 + The caption comes from the code-block `title` (code meta) or a leading
94 + `# caption: …` line. A leading caption line is removed from the encoded body.
95 +
96 + ## Exports
97 +
98 + - `qrCode(options?)` — plugin factory
99 + - `qrCodePlugin` — alias of `qrCode`
100 + - `resolveQrCodeOptions(options?)` — normalise options
101 + - `buildQrSvg(text, options)` — encode text into an SVG string
102 + - Types: `QrCodeOptions`, `ResolvedQrCodeOptions`, `QrCodeLevel`,
103 + `QrBuildResult`
104 +
105 + ## See also
106 +
107 + - [Plugin guide](../reference/plugin-api.en.md)
108 +