HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<pre id="logs"></pre>
<script type="text/javascript">
class C {
bold(s) {
return `<b>${s}</b>`
}
italic(s) {
return `<i>${s}</i>`
}
get dim() {
return this
}
}
var c = new C()
function log(x) {
const logEl = document.getElementById("logs")
if (typeof x !== 'string') {
x = JSON.stringify(x, null, 2)
}
logEl.innerHTML = `${logEl.innerHTML}\n${x}`;
}
console.log = log
function error(x) {
const logEl = document.getElementById("logs")
if (typeof x !== 'string') {
x = JSON.stringify(x, null, 2)
}
logEl.innerHTML = `ERROR: ${logEl.innerHTML}\n${x}`;
}
console.error = error;
function assert(expr, message) {
if (!expr) {
console.log(`ASSERTION ERROR: ${message ?? 'unknown assertion error'}`)
}
}
function printAccountInfo(
accountInfo,
opts
) {
const {
includeData = false
} = opts ?? {}
const {
owner,
data,
...rest
} = accountInfo
console.log({
owner: owner.toBase58(),
data: includeData ? data.toString() : `<${data.length} bytes>`,
...rest,
})
}
async function ensureBackend(luzid) {
try {
const res = await luzid.ping.ping()
return luzid
} catch (err) {
console.log('Please start the "luzid" backend in a local terminal')
return false
}
}
function printSolanaExplorerAccountUrl(accountAddr, opts) {
const { tab = null } = opts ?? {}
let url = `https://explorer.solana.com/address/${accountAddr}`
if (tab != null) url += `/${tab}`
console.log(`${url}?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899`)
}
</script>
import { Buffer } from "https://esm.sh/buffer"
import { LuzidSdk, Cluster, AccountModification } from "https://esm.sh/@luzid/sdk";
import * as web3 from "https://esm.sh/@solana/web3.js"
// The program accounts we will clone and interact with
const programAddr = 'SoLXmnP9JvL6vJ7TN1VqtTxqsc2izmPfF9CsMDEuRzJ'
const postAddr = '5ZspQX4nw95meJHpXBF425NytnNTDgtLBBGVDK9EWmRy'
const BPF_LOADER_UPGRADABLE_PROGRAM_ID = new web3.PublicKey(
'BPFLoaderUpgradeab1e11111111111111111111111'
)
async function main() {
const luzid = await ensureBackend(new LuzidSdk())
if (luzid == null) return
const conn = new web3.Connection(Cluster.Development.apiUrl)
// 1. Clone a Devnet account of the program which is holding a post
{
console.log(
c.bold('\n1. Cloning an account of the SolX program from devnet...')
)
await luzid.mutator.cloneAccount(Cluster.Devnet, postAddr, {
commitment: 'confirmed',
})
const acc = await conn.getAccountInfo(new web3.PublicKey(postAddr))
printAccountInfo(acc)
console.log(
'\nThe account was cloned. View it in the Solana Explorer at this URL:\n'
)
printSolanaExplorerAccountUrl(postAddr, { tab: 'anchor-account' })
console.log(
c.dim.italic(
'\nNotice that it is not showing any anchor data (parsed data) yet.'
)
)
// Assertions (you can safely ignore these)
{
assert(
acc.owner.equals(new web3.PublicKey(programAddr)),
'owner is solx program'
)
assert(acc.lamports > 9000000, 'lamports > 9000000')
assert(acc.data.length >= 1000, 'data was cloned')
}
}
// 2. Clone the account of the program itself which will auto-clone the IDL account as well
{
console.log(c.bold('\n2. Cloning the SolX program account from devnet...'))
await luzid.mutator.cloneAccount(Cluster.Devnet, programAddr, {
commitment: 'confirmed',
})
const programAcc = await conn.getAccountInfo(
new web3.PublicKey(programAddr)
)
printAccountInfo(programAcc)
console.log(
c.dim.italic(
'The program account was cloned and you can refresh the Solana explorer and should see anchor data' +
' for the first account we cloned since now it can access its IDL.'
)
)
// Assertions (you can safely ignore these)
{
// Assert the program account itself was properly cloned
assert(programAcc.lamports > 1000000, 'lamports > 1000000')
assert(programAcc.data.length >= 36, 'data was cloned')
assert(
programAcc.owner.equals(BPF_LOADER_UPGRADABLE_PROGRAM_ID),
'owner is bpf loader upgradable'
)
assert(programAcc.executable, 'executable')
// Assert the account holding the executable data was properly cloned
const execDataAddr = 'J1ct2BY6srXCDMngz5JxkX3sHLwCqGPhy9FiJBc8nuwk'
const execDataAcc = await conn.getAccountInfo(
new web3.PublicKey(execDataAddr)
)
assert(execDataAcc.lamports > 2000000000, 'lamports > 2000000000')
assert(execDataAcc.data.length >= 400000, 'data was cloned')
assert(
execDataAcc.owner.equals(BPF_LOADER_UPGRADABLE_PROGRAM_ID),
'owner is bpf loader upgradable'
)
assert(!execDataAcc.executable, 'not executable')
// Assert the account holding the IDL was properly cloned
const idlAddr = 'EgrsyMAsGYMKjcnTvnzmpJtq3hpmXznKQXk21154TsaS'
const idlAcc = await conn.getAccountInfo(new web3.PublicKey(idlAddr))
assert(idlAcc.lamports > 6000000, 'lamports > 6000000')
assert(idlAcc.data.length >= 700, 'data was cloned')
assert(
idlAcc.owner.equals(new web3.PublicKey(programAddr)),
'owner is solx program'
)
assert(!execDataAcc.executable, 'not executable')
}
}
// 3. Now for fun let's modify the account data of the first account we cloned
{
console.log(
c.bold('\n3. Modifying the account data of the first account...')
)
const acc = await conn.getAccountInfo(new web3.PublicKey(postAddr))
// Let's UPPER CASE the first word (the message starts at offset 52)
const data = acc.data
data[52] = data[52] - 32
data[53] = data[53] - 32
data[54] = data[54] - 32
data[55] = data[55] - 32
data[56] = data[56] - 32
await luzid.mutator.modifyAccount(
AccountModification.forAddr(postAddr).setData(data),
{ commitment: 'confirmed' }
)
const msgUtf8 = data.subarray(52, 74).toString('utf8')
console.log(`\nModified message: ${msgUtf8}`)
console.log(
'\nRefresh the Solana explorer and you should see the change:\n'
)
printSolanaExplorerAccountUrl(postAddr, { tab: 'anchor-account' })
// Assertions (you can safely ignore these)
{
assert(
acc.owner.equals(new web3.PublicKey(programAddr)),
'owner is still solx program'
)
assert(msgUtf8.startsWith('HELLO'), 'data was modified to upper case')
}
}
}
main()
.catch((err: any) => {
console.error(err.toString())
})
Also see: Tab Triggers