copy:redact

The copy:redact boolean global attribute replaces the element with a comment when the source is copied to the clipboard from the editor. It keeps a block out of the text you paste into chats, tickets and other tools.

Syntax

html
<script copy:redact>const demoKey = "not-for-clipboards"</script>
<div copy:redact>Internal notes</div>

Value

Boolean

The attribute needs no value: its presence turns redaction on for the element.

Description

When you copy or cut in the input editor, and the copied text contains copy:redact, every element that carries the attribute is replaced by a comment: <!--REDACTED, the line breaks of the element minus one, then -->. There is no space after <!--, and the line count is kept.

When

On copy or cut, while the editor has text focus and the copied text matches copy:redact. The copied text is all selections joined; an empty selection contributes its whole line.

What is copied

The copied text is parsed as an HTML fragment and written back with RTCode's serializer, as plain text. All other clipboard formats are cleared, and a toast with a shield icon says redact.

The start tag

Redaction needs the element's start tag in the copied text. Copying text from inside the element without its <… copy:redact> tag copies it as it is.

No element

If the attribute text occurs but no element carries the attribute, for example inside a comment, the original text is copied unchanged.

The editor mask

While the input contains copy:redact, every <script … copy:redact …> block is drawn as solid grey bars with transparent text. The mask lifts while a cursor is inside the block or a selection covers only part of it; a block that is fully selected or untouched stays masked. Only script blocks are masked.

CodeLens
📜🛡️ marks a copy:redact script and ⚙️🛡️ a copy:redact worker, with the tooltip redact on copy.

Usage notes

It is not protection

copy:redact has no effect on deploy. The element and its content are served publicly, and the attribute is kept: the served page writes copy:redact="". It also does not affect the playground URL, which carries the source, File Sync's 📄.html, versions or the deployed source.

Warning: To keep content out of the served page, use edge:redact or edge:remove. To keep a value private, see Keeping secrets out.

Copies are rewritten

The copied fragment is written back with the same serializer that Input: Fetch [i:] uses, so its formatting can change. Elements with an empty oi:exclude, and the children of oi:exclude=subtree elements, are left out of the copied text. Copy from a selection that holds neither when you need all the content.

Copying with a command

Input: Copy (Selection) to Clipboard, in Playground ▸ Input ▸ Code ▸ Copy, copies the selections, or the whole input when nothing is selected, with every copy:redact element redacted. It does not need editor focus. The editor's own Ctrl+C and Ctrl+X (⌘+C and ⌘+X on macOS) redact in the same way. See Commands.

Experimental The i.redacted getter returns the same text for the selection, and it may change. See Playground API.

Examples

A demo key that stays out of copies

html
<h1>Report</h1>
<script copy:redact>const demoKey = "not-for-clipboards"</script>
<p copy:redact>Internal notes: do not share.</p>

Select all in the editor, copy, and paste into any text field. The script block is masked in the editor until you put the cursor inside it.

What the clipboard holds

After you copy everything in that source, the clipboard holds:

plain
<h1>Report</h1>
<!--REDACTED-->
<!--REDACTED-->

Specifications

Not part of any specification. copy:redact is an RTCode.io editor feature.

It builds on these standards:

Specification
Clipboard API and events
HTML Standard: Comments

Availability

FeaturePlaygroundRTEdge.netNotes
Redaction on copy and cutYesNoThe input editor.
Editor mask and CodeLensYesNoScript blocks and workers.
Effect on the deployed pageNoneNoneThe element and the attribute are served as written.
Agent File Sync (Agent Folder Share)YesNo📄.html holds the content unredacted. Chrome or Edge on desktop.

See also