Overview
Adding a copy to clipboard button to codeblocks in software documentation can help users perform a task more quickly, reliably, and safely.
For most formats, this procedure requires the ability to insert HTML in content. For exceptions, see Examples.
Procedure
- Open content to edit.
-
Add a
<pre>element, and give it theft-copy-blockclass.For example:
<pre class="ft-copy-block"><code>console.log("Hello, World!");</code></pre>Do not insert spaces or line breaks between
<pre>and<code>. They can appear in the published content of the codeblock. -
Publish the document to a Fluid Topics portal.
Result:
console.log("Hello, World!");
It is possible to use the <pre class="ft-copy-block"> element and to enable syntax highlighting in code examples.
Styling
To style copy to clipboard codeblocks, use the following CSS properties:
--ft-copy-block-background-color--ft-copy-block-border-color--ft-copy-block-border-radius--ft-copy-block-border-style--ft-copy-block-border-width--ft-copy-block-button-height--ft-copy-block-spacing
For example, add the following to the portal's Content styles:
ft-copy-block {
--ft-copy-block-background-color: rgb(230, 230, 234);
--ft-copy-block-border-color: indigo;
--ft-copy-block-border-style: dotted;
--ft-copy-block-border-width: 5px;
}
Examples
DITA
It is possible to use the outputclass attribute to assign the ft-copy-block HTML class to a <codeblock> element in DITA.
For example:
<codeblock outputclass="ft-copy-block">console.log("Hello, World!");</codeblock>
Microsoft Word
It is possible to use the style map feature to assign the ft-copy-block HTML class to parts of a Microsoft Word document.
For example, for an code style paragraph, use the following style map:
pre.ft-copy-block:
- code
Paligo
It is possible to use the role attribute to assign the ft-copy-block HTML class to a <programlisting> element in Paligo.
For example:
<programlisting role="ft-copy-block">console.log("Hello, World!");</programlisting>