File tree Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change 11import { svg } from '../svg.js' ;
22
3- export function renderCodeCopy ( ) {
4- const els = document . querySelectorAll ( '.markup .code-block code' ) ;
5- if ( ! els . length ) return ;
6-
3+ export function makeCodeCopyButton ( ) {
74 const button = document . createElement ( 'button' ) ;
85 button . classList . add ( 'code-copy' , 'ui' , 'button' ) ;
96 button . innerHTML = svg ( 'octicon-copy' ) ;
7+ return button ;
8+ }
9+
10+ export function renderCodeCopy ( ) {
11+ const els = document . querySelectorAll ( '.markup .code-block code' ) ;
12+ if ( ! els . length ) return ;
1013
1114 for ( const el of els ) {
12- const btn = button . cloneNode ( true ) ;
15+ const btn = makeCodeCopyButton ( ) ;
1316 btn . setAttribute ( 'data-clipboard-text' , el . textContent ) ;
1417 el . after ( btn ) ;
1518 }
Original file line number Diff line number Diff line change 11import { isDarkTheme } from '../utils.js' ;
2+ import { makeCodeCopyButton } from './codecopy.js' ;
3+
24const { mermaidMaxSourceCharacters} = window . config ;
35
46const iframeCss = `
@@ -58,7 +60,13 @@ export async function renderMermaid() {
5860 iframe . sandbox = 'allow-scripts' ;
5961 iframe . style . height = `${ Math . ceil ( parseFloat ( heightStr ) ) } px` ;
6062 iframe . srcdoc = `<html><head><style>${ iframeCss } </style></head><body>${ svgStr } </body></html>` ;
61- el . closest ( 'pre' ) . replaceWith ( iframe ) ;
63+ const mermaidBlock = document . createElement ( 'div' ) ;
64+ mermaidBlock . classList . add ( 'mermaid-block' ) ;
65+ mermaidBlock . append ( iframe ) ;
66+ const btn = makeCodeCopyButton ( ) ;
67+ btn . setAttribute ( 'data-clipboard-text' , source ) ;
68+ mermaidBlock . append ( btn ) ;
69+ el . closest ( 'pre' ) . replaceWith ( mermaidBlock ) ;
6270 } ) ;
6371 } catch ( err ) {
6472 displayError ( el , err ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export function createTippy(target, opts = {}) {
66 placement : target . getAttribute ( 'data-placement' ) || 'top-start' ,
77 animation : false ,
88 allowHTML : false ,
9+ hideOnClick : false ,
910 interactiveBorder : 30 ,
1011 ignoreAttributes : true ,
1112 maxWidth : 500 , // increase over default 350px
@@ -46,7 +47,7 @@ export function showTemporaryTooltip(target, content) {
4647 }
4748
4849 tippy . setContent ( content ) ;
49- tippy . show ( ) ;
50+ if ( ! tippy . state . isShown ) tippy . show ( ) ;
5051 tippy . setProps ( {
5152 onHidden : ( tippy ) => {
5253 if ( oldContent ) {
Original file line number Diff line number Diff line change 1- .markup .code-block {
1+ .markup .code-block ,
2+ .markup .mermaid-block {
23 position : relative ;
34}
45
2627 background : var (--color-secondary-dark-1 ) !important ;
2728}
2829
29- .markup .code-block :hover .code-copy {
30+ .markup .code-block :hover .code-copy ,
31+ .markup .mermaid-block :hover .code-copy {
3032 visibility : visible ;
3133 animation : fadein .2s both ;
3234}
You can’t perform that action at this time.
0 commit comments