@@ -32,7 +32,7 @@ const CSS_FILES = [
32
32
`${ appPath } /node_modules/codemirror/lib/codemirror.css`
33
33
]
34
34
35
- function buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme ) {
35
+ function buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme , allowCustomCSS , customCSS ) {
36
36
return `
37
37
@font-face {
38
38
font-family: 'Lato';
@@ -52,7 +52,19 @@ function buildStyle (fontFamily, fontSize, codeBlockFontFamily, lineNumber, scro
52
52
font-weight: 700;
53
53
text-rendering: optimizeLegibility;
54
54
}
55
+ @font-face {
56
+ font-family: 'Material Icons';
57
+ font-style: normal;
58
+ font-weight: 400;
59
+ src: local('Material Icons'),
60
+ local('MaterialIcons-Regular'),
61
+ url('${ appPath } /resources/fonts/MaterialIcons-Regular.woff2') format('woff2'),
62
+ url('${ appPath } /resources/fonts/MaterialIcons-Regular.woff') format('woff'),
63
+ url('${ appPath } /resources/fonts/MaterialIcons-Regular.ttf') format('truetype');
64
+ }
65
+ ${ allowCustomCSS ? customCSS : '' }
55
66
${ markdownStyle }
67
+
56
68
body {
57
69
font-family: '${ fontFamily . join ( "','" ) } ';
58
70
font-size: ${ fontSize } px;
@@ -132,7 +144,6 @@ export default class MarkdownPreview extends React.Component {
132
144
this . mouseUpHandler = ( e ) => this . handleMouseUp ( e )
133
145
this . DoubleClickHandler = ( e ) => this . handleDoubleClick ( e )
134
146
this . scrollHandler = _ . debounce ( this . handleScroll . bind ( this ) , 100 , { leading : false , trailing : true } )
135
- this . anchorClickHandler = ( e ) => this . handlePreviewAnchorClick ( e )
136
147
this . checkboxClickHandler = ( e ) => this . handleCheckboxClick ( e )
137
148
this . saveAsTextHandler = ( ) => this . handleSaveAsText ( )
138
149
this . saveAsMdHandler = ( ) => this . handleSaveAsMd ( )
@@ -153,22 +164,6 @@ export default class MarkdownPreview extends React.Component {
153
164
} )
154
165
}
155
166
156
- handlePreviewAnchorClick ( e ) {
157
- e . preventDefault ( )
158
- e . stopPropagation ( )
159
-
160
- const anchor = e . target . closest ( 'a' )
161
- const href = anchor . getAttribute ( 'href' )
162
- if ( _ . isString ( href ) && href . match ( / ^ # / ) ) {
163
- const targetElement = this . refs . root . contentWindow . document . getElementById ( href . substring ( 1 , href . length ) )
164
- if ( targetElement != null ) {
165
- this . getWindow ( ) . scrollTo ( 0 , targetElement . offsetTop )
166
- }
167
- } else {
168
- shell . openExternal ( href )
169
- }
170
- }
171
-
172
167
handleCheckboxClick ( e ) {
173
168
this . props . onCheckboxClick ( e )
174
169
}
@@ -216,9 +211,9 @@ export default class MarkdownPreview extends React.Component {
216
211
217
212
handleSaveAsHtml ( ) {
218
213
this . exportAsDocument ( 'html' , ( noteContent , exportTasks ) => {
219
- const { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme} = this . getStyleParams ( )
214
+ const { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS , customCSS } = this . getStyleParams ( )
220
215
221
- const inlineStyles = buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme )
216
+ const inlineStyles = buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme , allowCustomCSS , customCSS )
222
217
let body = this . markdown . render ( escapeHtmlCharacters ( noteContent ) )
223
218
224
219
const files = [ this . GetCodeThemeLink ( codeBlockTheme ) , ...CSS_FILES ]
@@ -343,6 +338,7 @@ export default class MarkdownPreview extends React.Component {
343
338
if ( prevProps . value !== this . props . value ) this . rewriteIframe ( )
344
339
if ( prevProps . smartQuotes !== this . props . smartQuotes ||
345
340
prevProps . sanitize !== this . props . sanitize ||
341
+ prevProps . smartArrows !== this . props . smartArrows ||
346
342
prevProps . breaks !== this . props . breaks ) {
347
343
this . initMarkdown ( )
348
344
this . rewriteIframe ( )
@@ -354,14 +350,16 @@ export default class MarkdownPreview extends React.Component {
354
350
prevProps . lineNumber !== this . props . lineNumber ||
355
351
prevProps . showCopyNotification !== this . props . showCopyNotification ||
356
352
prevProps . theme !== this . props . theme ||
357
- prevProps . scrollPastEnd !== this . props . scrollPastEnd ) {
353
+ prevProps . scrollPastEnd !== this . props . scrollPastEnd ||
354
+ prevProps . allowCustomCSS !== this . props . allowCustomCSS ||
355
+ prevProps . customCSS !== this . props . customCSS ) {
358
356
this . applyStyle ( )
359
357
this . rewriteIframe ( )
360
358
}
361
359
}
362
360
363
361
getStyleParams ( ) {
364
- const { fontSize, lineNumber, codeBlockTheme, scrollPastEnd, theme } = this . props
362
+ const { fontSize, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS , customCSS } = this . props
365
363
let { fontFamily, codeBlockFontFamily } = this . props
366
364
fontFamily = _ . isString ( fontFamily ) && fontFamily . trim ( ) . length > 0
367
365
? fontFamily . split ( ',' ) . map ( fontName => fontName . trim ( ) ) . concat ( defaultFontFamily )
@@ -370,14 +368,14 @@ export default class MarkdownPreview extends React.Component {
370
368
? codeBlockFontFamily . split ( ',' ) . map ( fontName => fontName . trim ( ) ) . concat ( defaultCodeBlockFontFamily )
371
369
: defaultCodeBlockFontFamily
372
370
373
- return { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme}
371
+ return { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS , customCSS }
374
372
}
375
373
376
374
applyStyle ( ) {
377
- const { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme} = this . getStyleParams ( )
375
+ const { fontFamily, fontSize, codeBlockFontFamily, lineNumber, codeBlockTheme, scrollPastEnd, theme, allowCustomCSS , customCSS } = this . getStyleParams ( )
378
376
379
377
this . getWindow ( ) . document . getElementById ( 'codeTheme' ) . href = this . GetCodeThemeLink ( codeBlockTheme )
380
- this . getWindow ( ) . document . getElementById ( 'style' ) . innerHTML = buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme )
378
+ this . getWindow ( ) . document . getElementById ( 'style' ) . innerHTML = buildStyle ( fontFamily , fontSize , codeBlockFontFamily , lineNumber , scrollPastEnd , theme , allowCustomCSS , customCSS )
381
379
}
382
380
383
381
GetCodeThemeLink ( theme ) {
@@ -390,9 +388,6 @@ export default class MarkdownPreview extends React.Component {
390
388
}
391
389
392
390
rewriteIframe ( ) {
393
- _ . forEach ( this . refs . root . contentWindow . document . querySelectorAll ( 'a' ) , ( el ) => {
394
- el . removeEventListener ( 'click' , this . anchorClickHandler )
395
- } )
396
391
_ . forEach ( this . refs . root . contentWindow . document . querySelectorAll ( 'input[type="checkbox"]' ) , ( el ) => {
397
392
el . removeEventListener ( 'click' , this . checkboxClickHandler )
398
393
} )
@@ -401,7 +396,7 @@ export default class MarkdownPreview extends React.Component {
401
396
el . removeEventListener ( 'click' , this . linkClickHandler )
402
397
} )
403
398
404
- const { theme, indentSize, showCopyNotification, storagePath } = this . props
399
+ const { theme, indentSize, showCopyNotification, storagePath, noteKey } = this . props
405
400
let { value, codeBlockTheme } = this . props
406
401
407
402
this . refs . root . contentWindow . document . body . setAttribute ( 'data-theme' , theme )
@@ -413,18 +408,15 @@ export default class MarkdownPreview extends React.Component {
413
408
} )
414
409
}
415
410
let renderedHTML = this . markdown . render ( value )
411
+ attachmentManagement . migrateAttachments ( renderedHTML , storagePath , noteKey )
416
412
this . refs . root . contentWindow . document . body . innerHTML = attachmentManagement . fixLocalURLS ( renderedHTML , storagePath )
417
413
418
- _ . forEach ( this . refs . root . contentWindow . document . querySelectorAll ( 'a' ) , ( el ) => {
419
- this . fixDecodedURI ( el )
420
- el . addEventListener ( 'click' , this . anchorClickHandler )
421
- } )
422
-
423
414
_ . forEach ( this . refs . root . contentWindow . document . querySelectorAll ( 'input[type="checkbox"]' ) , ( el ) => {
424
415
el . addEventListener ( 'click' , this . checkboxClickHandler )
425
416
} )
426
417
427
418
_ . forEach ( this . refs . root . contentWindow . document . querySelectorAll ( 'a' ) , ( el ) => {
419
+ this . fixDecodedURI ( el )
428
420
el . addEventListener ( 'click' , this . linkClickHandler )
429
421
} )
430
422
@@ -475,7 +467,7 @@ export default class MarkdownPreview extends React.Component {
475
467
el . innerHTML = ''
476
468
diagram . drawSVG ( el , opts )
477
469
_ . forEach ( el . querySelectorAll ( 'a' ) , ( el ) => {
478
- el . addEventListener ( 'click' , this . anchorClickHandler )
470
+ el . addEventListener ( 'click' , this . linkClickHandler )
479
471
} )
480
472
} catch ( e ) {
481
473
console . error ( e )
@@ -491,7 +483,7 @@ export default class MarkdownPreview extends React.Component {
491
483
el . innerHTML = ''
492
484
diagram . drawSVG ( el , { theme : 'simple' } )
493
485
_ . forEach ( el . querySelectorAll ( 'a' ) , ( el ) => {
494
- el . addEventListener ( 'click' , this . anchorClickHandler )
486
+ el . addEventListener ( 'click' , this . linkClickHandler )
495
487
} )
496
488
} catch ( e ) {
497
489
console . error ( e )
@@ -598,10 +590,12 @@ MarkdownPreview.propTypes = {
598
590
onDoubleClick : PropTypes . func ,
599
591
onMouseUp : PropTypes . func ,
600
592
onMouseDown : PropTypes . func ,
593
+ onContextMenu : PropTypes . func ,
601
594
className : PropTypes . string ,
602
595
value : PropTypes . string ,
603
596
showCopyNotification : PropTypes . bool ,
604
597
storagePath : PropTypes . string ,
605
598
smartQuotes : PropTypes . bool ,
599
+ smartArrows : PropTypes . bool ,
606
600
breaks : PropTypes . bool
607
601
}
0 commit comments