File tree 3 files changed +31
-21
lines changed
3 files changed +31
-21
lines changed Original file line number Diff line number Diff line change 65
65
}
66
66
} ;
67
67
68
- if ( pre . hasAttribute ( 'data-download-link' ) && Prism . plugins . toolbar ) {
69
- Prism . plugins . toolbar . registerButton ( 'download-file' , function ( ) {
70
- var a = document . createElement ( 'a' ) ;
71
- a . textContent = pre . getAttribute ( 'data-download-link-label' ) || 'Download' ;
72
- a . setAttribute ( 'download' , '' ) ;
73
- a . href = src ;
74
- return a ;
75
- } ) ;
76
- }
77
-
78
68
xhr . send ( null ) ;
79
69
} ) ;
80
70
71
+ if ( Prism . plugins . toolbar ) {
72
+ Prism . plugins . toolbar . registerButton ( 'download-file' , function ( env ) {
73
+ var pre = env . element . parentNode ;
74
+ if ( ! pre || ! / p r e / i. test ( pre . nodeName ) || ! pre . hasAttribute ( 'data-src' ) || ! pre . hasAttribute ( 'data-download-link' ) ) {
75
+ return ;
76
+ }
77
+ var src = pre . getAttribute ( 'data-src' ) ;
78
+ var a = document . createElement ( 'a' ) ;
79
+ a . textContent = pre . getAttribute ( 'data-download-link-label' ) || 'Download' ;
80
+ a . setAttribute ( 'download' , '' ) ;
81
+ a . href = src ;
82
+ return a ;
83
+ } ) ;
84
+ }
85
+
81
86
} ;
82
87
83
88
document . addEventListener ( 'DOMContentLoaded' , self . Prism . fileHighlight ) ;
Original file line number Diff line number Diff line change @@ -849,19 +849,24 @@ Prism.languages.js = Prism.languages.javascript;
849
849
}
850
850
} ;
851
851
852
- if ( pre . hasAttribute ( 'data-download-link' ) && Prism . plugins . toolbar ) {
853
- Prism . plugins . toolbar . registerButton ( 'download-file' , function ( ) {
854
- var a = document . createElement ( 'a' ) ;
855
- a . textContent = pre . getAttribute ( 'data-download-link-label' ) || 'Download' ;
856
- a . setAttribute ( 'download' , '' ) ;
857
- a . href = src ;
858
- return a ;
859
- } ) ;
860
- }
861
-
862
852
xhr . send ( null ) ;
863
853
} ) ;
864
854
855
+ if ( Prism . plugins . toolbar ) {
856
+ Prism . plugins . toolbar . registerButton ( 'download-file' , function ( env ) {
857
+ var pre = env . element . parentNode ;
858
+ if ( ! pre || ! / p r e / i. test ( pre . nodeName ) || ! pre . hasAttribute ( 'data-src' ) || ! pre . hasAttribute ( 'data-download-link' ) ) {
859
+ return ;
860
+ }
861
+ var src = pre . getAttribute ( 'data-src' ) ;
862
+ var a = document . createElement ( 'a' ) ;
863
+ a . textContent = pre . getAttribute ( 'data-download-link-label' ) || 'Download' ;
864
+ a . setAttribute ( 'download' , '' ) ;
865
+ a . href = src ;
866
+ return a ;
867
+ } ) ;
868
+ }
869
+
865
870
} ;
866
871
867
872
document . addEventListener ( 'DOMContentLoaded' , self . Prism . fileHighlight ) ;
You can’t perform that action at this time.
0 commit comments