File tree 4 files changed +23
-9
lines changed
4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { svg } from '../svg.js' ;
2
2
3
- export function renderCodeCopy ( ) {
4
- const els = document . querySelectorAll ( '.markup .code-block code' ) ;
5
- if ( ! els . length ) return ;
6
-
3
+ export function makeCodeCopyButton ( ) {
7
4
const button = document . createElement ( 'button' ) ;
8
5
button . classList . add ( 'code-copy' , 'ui' , 'button' ) ;
9
6
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 ;
10
13
11
14
for ( const el of els ) {
12
- const btn = button . cloneNode ( true ) ;
15
+ const btn = makeCodeCopyButton ( ) ;
13
16
btn . setAttribute ( 'data-clipboard-text' , el . textContent ) ;
14
17
el . after ( btn ) ;
15
18
}
Original file line number Diff line number Diff line change 1
1
import { isDarkTheme } from '../utils.js' ;
2
+ import { makeCodeCopyButton } from './codecopy.js' ;
3
+
2
4
const { mermaidMaxSourceCharacters} = window . config ;
3
5
4
6
const iframeCss = `
@@ -58,7 +60,13 @@ export async function renderMermaid() {
58
60
iframe . sandbox = 'allow-scripts' ;
59
61
iframe . style . height = `${ Math . ceil ( parseFloat ( heightStr ) ) } px` ;
60
62
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 ) ;
62
70
} ) ;
63
71
} catch ( err ) {
64
72
displayError ( el , err ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export function createTippy(target, opts = {}) {
6
6
placement : target . getAttribute ( 'data-placement' ) || 'top-start' ,
7
7
animation : false ,
8
8
allowHTML : false ,
9
+ hideOnClick : false ,
9
10
interactiveBorder : 30 ,
10
11
ignoreAttributes : true ,
11
12
maxWidth : 500 , // increase over default 350px
@@ -46,7 +47,7 @@ export function showTemporaryTooltip(target, content) {
46
47
}
47
48
48
49
tippy . setContent ( content ) ;
49
- tippy . show ( ) ;
50
+ if ( ! tippy . state . isShown ) tippy . show ( ) ;
50
51
tippy . setProps ( {
51
52
onHidden : ( tippy ) => {
52
53
if ( oldContent ) {
Original file line number Diff line number Diff line change 1
- .markup .code-block {
1
+ .markup .code-block ,
2
+ .markup .mermaid-block {
2
3
position : relative ;
3
4
}
4
5
26
27
background : var (--color-secondary-dark-1 ) !important ;
27
28
}
28
29
29
- .markup .code-block :hover .code-copy {
30
+ .markup .code-block :hover .code-copy ,
31
+ .markup .mermaid-block :hover .code-copy {
30
32
visibility : visible ;
31
33
animation : fadein .2s both ;
32
34
}
You can’t perform that action at this time.
0 commit comments