Enhanced Fence Component - Test Page

Enhanced Fence Component Test

This page demonstrates all the new features added to the Fence component.


1. Basic Code Block (Backward Compatible)

Standard code block without any enhancements:

function greet(name) {
console.log(`Hello, ${name}!`)
return `Welcome to the docs!`
}
greet('Developer')

2. Code Block with Line Numbers

Use showLineNumbers to display line numbers:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3
4const umi = createUmi('https://api.devnet.solana.com')
5
6const asset = await create(umi, {
7 name: 'My NFT',
8 uri: 'https://example.com/metadata.json'
9}).sendAndConfirm(umi)
10
11console.log('Created:', asset.publicKey)

3. Highlight Specific Lines

Use highlightLines to highlight important lines:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4
5const umi = createUmi('https://api.devnet.solana.com').use(mplCore())
6
7const asset = await create(umi, {
8 name: 'My NFT',
9 uri: 'https://example.com/metadata.json'
10}).sendAndConfirm(umi)
11
12console.log('Created:', asset.publicKey)

Lines 3 and 7-9 are highlighted!


4. Show Only Specific Lines (Line Range)

Use showLines to display only certain lines:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4}).sendAndConfirm(umi)
5

Only showing lines 1-3 and 10-11 (with proper line numbers maintained)!


5. Code Block with Title

Use title to show a filename or description:

src/examples/create-nft.js
1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3
4const umi = createUmi('https://api.devnet.solana.com')
5
6const asset = await create(umi, {
7 name: 'My NFT',
8 uri: 'https://example.com/metadata.json'
9}).sendAndConfirm(umi)

6. All Features Combined

Title + Line Numbers + Highlighting + Line Range:

config/setup.js
10
11// Generate a new keypair for the asset
12const assetSigner = generateSigner(umi)
13
14// Create the asset with all metadata
15const asset = await create(umi, {
16 asset: assetSigner,
17 name: 'My Amazing NFT',
18 uri: 'https://arweave.net/my-metadata.json',
19 collection: collectionAddress,
20}).sendAndConfirm(umi)

Showing lines 10-20 with lines 15-17 highlighted!


7. Rust Example with Features

programs/my-program/src/lib.rs
1use anchor_lang::prelude::*;
2use mpl_core::instructions::TransferV1;
3
4declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
5
6#[program]
7pub mod transfer_asset {
8 use super::*;
9
10 pub fn transfer(ctx: Context<TransferAsset>) -> Result<()> {
11 let asset = &mut ctx.accounts.asset;
12 asset.owner = ctx.accounts.new_owner.key();
13 Ok(())
14 }
15}

Feature Summary

Line Numbers - showLineNumbers=true Line Highlighting - highlightLines="1,3-5,10" Line Range - showLines="1-10,15-20" Title/Filename - title="path/to/file.js" Copy Button - Already included by default Backward Compatible - All existing code blocks still work!


Usage in Markdown

```javascript ,
// Your code here
```

The Fence component now supports professional code documentation! 🎉


Integration with Tabbed Code Examples

The enhanced Fence features also work with multi-framework code tabs!

8. Basic Tabbed Code (Copy with Context)

Standard tabbed code with Snippet/Full toggle:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4
5// Initialize UMI
6const umi = createUmi('https://api.devnet.solana.com')
7 .use(mplCore())
8
9// Create a new NFT asset
10const asset = await create(umi, {
11 name: 'My NFT',
12 uri: 'https://example.com/metadata.json'
13}).sendAndConfirm(umi)
14
15console.log('Asset created:', asset.publicKey)

9. Tabbed Code with Line Numbers

Add line numbers to all tabs:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4
5// Initialize UMI
6const umi = createUmi('https://api.devnet.solana.com')
7 .use(mplCore())
8
9// Create a new NFT asset
10const asset = await create(umi, {
11 name: 'My NFT',
12 uri: 'https://example.com/metadata.json'
13}).sendAndConfirm(umi)
14
15console.log('Asset created:', asset.publicKey)

10. Tabbed Code with Highlighting

Highlight important lines across all tabs:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { transfer } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4import { publicKey } from '@metaplex-foundation/umi'
5
6// Initialize UMI
7const umi = createUmi('https://api.devnet.solana.com')
8 .use(mplCore())
9
10// Transfer an existing NFT asset to a new owner
11const result = await transfer(umi, {
12 asset: publicKey('AssetAddressHere...'),
13 newOwner: publicKey('RecipientAddressHere...'),
14}).sendAndConfirm(umi)
15
16console.log('Asset transferred:', result.signature)

Lines 6-9 are highlighted in each framework!


11. All Features Together in Tabs

Line numbers + highlighting + Snippet/Full toggle:

1import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
2import { create } from '@metaplex-foundation/mpl-core'
3import { mplCore } from '@metaplex-foundation/mpl-core'
4
5// Initialize UMI
6const umi = createUmi('https://api.devnet.solana.com')
7 .use(mplCore())
8
9// Create a new NFT asset
10const asset = await create(umi, {
11 name: 'My NFT',
12 uri: 'https://example.com/metadata.json'
13}).sendAndConfirm(umi)
14
15console.log('Asset created:', asset.publicKey)

Complete Feature Matrix

FeatureStandalone CodeTabbed CodeExample
Line NumbersshowLineNumbers=true
Line HighlightinghighlightLines="1-5,7"
Line RangeshowLines="1-10,15-20"
Title/Filename⚠️ Per-tab onlytitle="file.js"
Copy ButtonshowCopy=true
Snippet/Full ToggleAutomatic in tabs
Multi-Frameworkcode-tabs-imported

Combined Power! 💪

Now you can:

  1. Show multi-framework examples with tabs (Kit, Umi, Shank, Anchor)
  2. Toggle between Snippet and Full code with one click
  3. Display line numbers for easy reference
  4. Highlight important lines to focus attention
  5. Show only relevant lines with line ranges
  6. Add titles to provide context
  7. Sync preferences across all code blocks on the page!

This makes the documentation professional, beginner-friendly, and developer-focused all at once! 🎉