diff --git a/lib/node_modules/@stdlib/_tools/markdown/to-html/lib/post_process.js b/lib/node_modules/@stdlib/_tools/markdown/to-html/lib/post_process.js index 57b4bcbc1cd7..fd0dac4d2f78 100644 --- a/lib/node_modules/@stdlib/_tools/markdown/to-html/lib/post_process.js +++ b/lib/node_modules/@stdlib/_tools/markdown/to-html/lib/post_process.js @@ -28,6 +28,7 @@ var replace = require( '@stdlib/string/replace' ); var RE_VIEW_BOX = /(?:(view-box)(=".*?"))/g; var RE_CLIP_PATH_OPEN = /(?:<(clip-path)(.*?>))/g; var RE_CLIP_PATH_CLOSE = /<\/clip-path>/g; +var RE_CODE_BLOCKS = /
\s*\s*([\s\S]*?)\s*<\/code>\s*<\/pre>/g;
// MAIN //
@@ -53,9 +54,38 @@ function postProcess( html ) {
html = replace( html, RE_VIEW_BOX, 'viewBox$2' );
html = replace( html, RE_CLIP_PATH_OPEN, '' );
+ html = replace( html, RE_CODE_BLOCKS, injectCopyButton );
+ html += getCopyButtonStyles();
return html;
}
+/**
+* Injects a "Copy" button into a code block.
+*
+* This function wraps a `` block in a container div and inserts a
+* "Copy" button above it. The button uses the Clipboard API to copy the visible
+* text content (`innerText`) of the `` element when clicked.
+*
+* @private
+* @param {string} match The entire matched HTML
+* @param {string} lang The language class
+* @param {string} code The raw HTML contents of the code block
+* @returns {string} copy button HTML
+*/
+function injectCopyButton( match, lang, code ) {
+ return '' + code + '
';
+}
+
+/**
+* Returns copy button styles.
+*
+* @private
+* @returns {string} copy button styles
+*/
+function getCopyButtonStyles() {
+ return '';
+}
+
// EXPORTS //