@@ -21,6 +21,7 @@ import yaml from 'js-yaml'
21
21
import { render } from 'react-dom'
22
22
import Carousel from 'react-image-carousel'
23
23
import ConfigManager from '../main/lib/ConfigManager'
24
+ import i18n from 'browser/lib/i18n'
24
25
25
26
const { remote, shell } = require ( 'electron' )
26
27
const attachmentManagement = require ( '../main/lib/dataApi/attachmentManagement' )
@@ -63,7 +64,8 @@ function buildStyle (opts) {
63
64
scrollPastEnd,
64
65
theme,
65
66
allowCustomCSS,
66
- customCSS
67
+ customCSS,
68
+ RTL
67
69
} = opts
68
70
return `
69
71
@font-face {
@@ -100,11 +102,14 @@ ${markdownStyle}
100
102
body {
101
103
font-family: '${ fontFamily . join ( "','" ) } ';
102
104
font-size: ${ fontSize } px;
105
+
103
106
${ scrollPastEnd ? `
104
107
padding-bottom: 90vh;
105
108
box-sizing: border-box;
106
109
`
107
110
: '' }
111
+ ${ RTL ? 'direction: rtl;' : '' }
112
+ ${ RTL ? 'text-align: right;' : '' }
108
113
}
109
114
@media print {
110
115
body {
@@ -114,6 +119,8 @@ body {
114
119
code {
115
120
font-family: '${ codeBlockFontFamily . join ( "','" ) } ';
116
121
background-color: rgba(0,0,0,0.04);
122
+ text-align: left;
123
+ direction: ltr;
117
124
}
118
125
.lineNumber {
119
126
${ lineNumber && 'display: block !important;' }
@@ -245,6 +252,7 @@ export default class MarkdownPreview extends React.Component {
245
252
this . saveAsHtmlHandler = ( ) => this . handleSaveAsHtml ( )
246
253
this . saveAsPdfHandler = ( ) => this . handleSaveAsPdf ( )
247
254
this . printHandler = ( ) => this . handlePrint ( )
255
+ this . resizeHandler = _ . throttle ( this . handleResize . bind ( this ) , 100 )
248
256
249
257
this . linkClickHandler = this . handleLinkClick . bind ( this )
250
258
this . initMarkdown = this . initMarkdown . bind ( this )
@@ -335,7 +343,8 @@ export default class MarkdownPreview extends React.Component {
335
343
scrollPastEnd,
336
344
theme,
337
345
allowCustomCSS,
338
- customCSS
346
+ customCSS,
347
+ RTL
339
348
} = this . getStyleParams ( )
340
349
341
350
const inlineStyles = buildStyle ( {
@@ -346,9 +355,10 @@ export default class MarkdownPreview extends React.Component {
346
355
scrollPastEnd,
347
356
theme,
348
357
allowCustomCSS,
349
- customCSS
358
+ customCSS,
359
+ RTL
350
360
} )
351
- let body = this . markdown . render ( noteContent )
361
+ let body = this . refs . root . contentWindow . document . body . innerHTML
352
362
body = attachmentManagement . fixLocalURLS (
353
363
body ,
354
364
this . props . storagePath
@@ -368,7 +378,7 @@ export default class MarkdownPreview extends React.Component {
368
378
369
379
let styles = ''
370
380
files . forEach ( file => {
371
- styles += `<link rel="stylesheet" href="css/${ path . basename ( file ) } ">`
381
+ styles += `<link rel="stylesheet" href="../ css/${ path . basename ( file ) } ">`
372
382
} )
373
383
374
384
return `<html>
@@ -423,7 +433,8 @@ export default class MarkdownPreview extends React.Component {
423
433
. then ( res => {
424
434
dialog . showMessageBox ( remote . getCurrentWindow ( ) , {
425
435
type : 'info' ,
426
- message : `Exported to ${ filename } `
436
+ message : `Exported to ${ filename } ` ,
437
+ buttons : [ i18n . __ ( 'Ok' ) ]
427
438
} )
428
439
} )
429
440
. catch ( err => {
@@ -538,6 +549,10 @@ export default class MarkdownPreview extends React.Component {
538
549
'scroll' ,
539
550
this . scrollHandler
540
551
)
552
+ this . refs . root . contentWindow . addEventListener (
553
+ 'resize' ,
554
+ this . resizeHandler
555
+ )
541
556
eventEmitter . on ( 'export:save-text' , this . saveAsTextHandler )
542
557
eventEmitter . on ( 'export:save-md' , this . saveAsMdHandler )
543
558
eventEmitter . on ( 'export:save-html' , this . saveAsHtmlHandler )
@@ -576,6 +591,10 @@ export default class MarkdownPreview extends React.Component {
576
591
'scroll' ,
577
592
this . scrollHandler
578
593
)
594
+ this . refs . root . contentWindow . removeEventListener (
595
+ 'resize' ,
596
+ this . resizeHandler
597
+ )
579
598
eventEmitter . off ( 'export:save-text' , this . saveAsTextHandler )
580
599
eventEmitter . off ( 'export:save-md' , this . saveAsMdHandler )
581
600
eventEmitter . off ( 'export:save-html' , this . saveAsHtmlHandler )
@@ -608,7 +627,8 @@ export default class MarkdownPreview extends React.Component {
608
627
prevProps . theme !== this . props . theme ||
609
628
prevProps . scrollPastEnd !== this . props . scrollPastEnd ||
610
629
prevProps . allowCustomCSS !== this . props . allowCustomCSS ||
611
- prevProps . customCSS !== this . props . customCSS
630
+ prevProps . customCSS !== this . props . customCSS ||
631
+ prevProps . RTL !== this . props . RTL
612
632
) {
613
633
this . applyStyle ( )
614
634
needsRewriteIframe = true
@@ -632,7 +652,8 @@ export default class MarkdownPreview extends React.Component {
632
652
scrollPastEnd,
633
653
theme,
634
654
allowCustomCSS,
635
- customCSS
655
+ customCSS,
656
+ RTL
636
657
} = this . props
637
658
let { fontFamily, codeBlockFontFamily } = this . props
638
659
fontFamily = _ . isString ( fontFamily ) && fontFamily . trim ( ) . length > 0
@@ -658,7 +679,8 @@ export default class MarkdownPreview extends React.Component {
658
679
scrollPastEnd,
659
680
theme,
660
681
allowCustomCSS,
661
- customCSS
682
+ customCSS,
683
+ RTL
662
684
}
663
685
}
664
686
@@ -672,7 +694,8 @@ export default class MarkdownPreview extends React.Component {
672
694
scrollPastEnd,
673
695
theme,
674
696
allowCustomCSS,
675
- customCSS
697
+ customCSS,
698
+ RTL
676
699
} = this . getStyleParams ( )
677
700
678
701
this . getWindow ( ) . document . getElementById (
@@ -686,7 +709,8 @@ export default class MarkdownPreview extends React.Component {
686
709
scrollPastEnd,
687
710
theme,
688
711
allowCustomCSS,
689
- customCSS
712
+ customCSS,
713
+ RTL
690
714
} )
691
715
}
692
716
@@ -995,6 +1019,15 @@ export default class MarkdownPreview extends React.Component {
995
1019
}
996
1020
}
997
1021
1022
+ handleResize ( ) {
1023
+ _ . forEach (
1024
+ this . refs . root . contentWindow . document . querySelectorAll ( 'svg[ratio]' ) ,
1025
+ el => {
1026
+ el . setAttribute ( 'height' , el . clientWidth / el . getAttribute ( 'ratio' ) )
1027
+ }
1028
+ )
1029
+ }
1030
+
998
1031
focus ( ) {
999
1032
this . refs . root . focus ( )
1000
1033
}
0 commit comments