summaryrefslogtreecommitdiff
path: root/python-sphinxcontrib-drawio.spec
blob: 5dea3e4b7440ebbcadfc4f755140d0074ca6f5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
%global _empty_manifest_terminate_build 0
Name:		python-sphinxcontrib-drawio
Version:	0.0.16
Release:	1
Summary:	Sphinx Extension to include draw.io files
License:	MIT
URL:		https://github.com/Modelmat/sphinxcontrib-drawio
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/73/17/c50b51a5336911ddf84dc0182c58b8b7e64d759382d5934e4725fa88c2be/sphinxcontrib-drawio-0.0.16.tar.gz
BuildArch:	noarch

Requires:	python3-sphinx

%description
# sphinxcontrib-drawio

Sphinx Extension adding the `drawio-image` and `drawio-figure` directives.
These are equivalent to the standard `image` and `figure` directives, but
accept the path to a `.drawio` file and additional options to control
exporting of the diagram to a suitable image format. 

These directives replace the `drawio` directive which is now deprecated, and
for which support will be dropped in version 1.0. Deprecation warnings are 
output when a `drawio` directive is encountered. Please replace these with
`drawio-image` orand `drawio-figure`, taking into account these differences:

- the *drawio_output_format* conf.py option has been removed; the draw.io
  diagram is exported to the Sphinx builder's preferred image format (eg. SVG
  for HTML, PDF for LaTeX). The *drawio_builder_export_format* configuration
  variable allows setting another default export format for each builder. Note
  that this can still be overridden for individual `drawio-image` and
  `drawio-figure` directives. See below for details.
- the *scale*, *width* and *height* options have been renamed, respectively, to
  *export-scale*, *export-width* and *export-height* so as not to conflict with
  the options inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *export-scale* option now takes an integer percentage; i.e. a value of 100
  means no scaling. This was changed to allow non-integer scaling and offer
  consistency with the `scale` option inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *drawio_default_scale* conf.py option has been replaced by the
  *drawio_default_export_scale* option, also accepting a integer percentage
  value.

**Important:** This extension does not work on readthedocs as RTD does not allow
packages (e.g. drawio) to be installed. If you only require diagrams in a single
format, you can consider using editable SVGs or PNGs, accessible through
draw.io's File > Export menu.

The drawio-desktop package does not run without an x-server (e.g. when in a CI
environment), see [this issue](https://github.com/jgraph/drawio-desktop/issues/146).
The workaround is to install `xvfb` and set the `drawio_headless` configuration
option to `auto`.

If any other of the `draw.io` CLI tool's options are wanted, please file an
issue.

## Installation

1. `python3 -m pip install sphinxcontrib-drawio`
2. In your sphinx config, add:

    ```python
    extensions = [
        "sphinxcontrib.drawio"
    ]
    ```

3. Add the draw.io binary to `$PATH`. See [Options: Binary Path](#binary-path)
   for more details and alternative solutions.

4. If running headless, install Xvfb, e.g. via `$ sudo apt install xvfb`.

## Options
These values are placed in the `conf.py` of your sphinx project.

### Binary Path
- *Formal Name*: `drawio_binary_path`
- *Default Value*: `None`

This allows for a specific override for the binary location. By default, this
chooses the `drawio` (or `draw.io.exe`) binary accessible in `$PATH`. However,
if this file does not exist, it picks the platform-appropriate path:

- Windows: `C:\Program Files\draw.io\draw.io.exe`
- Linux: `/opt/drawio/drawio` or `/opt/draw.io/drawio` (older versions)
- MacOS: `/Applications/draw.io.app/Contents/MacOS/draw.io`.

### Headless Mode
- *Formal Name*: `drawio_headless`
- *Default Value*: `"auto"`
- *Possible Values*: `True`, `False`, or `"auto"`

This config option controls the behaviour of running the Xvfb server. It is
necessary because `draw.io` will not work without an X-server, see
[this issue](https://github.com/jgraph/drawio-desktop/issues/146).

The `auto` mode will detect whether the program is running in a headless
environment through the `$DISPLAY` environment variable, and act as if it were
set to `True`. If not running on Linux, or the `$DISPLAY` environment variable
contains some value (i.e. running in an X-server on a developer's machine), it
will act as it it were set to `False`.

Setting the value to `True` will start a virtual X framebuffer through the
`Xvfb` command before running any `draw.io` commands, and stop it afterwards.

Setting the value to `False` will run the `draw.io` binary as normal.

### Default Output Format
- *Formal Name*: `drawio_builder_export_format`
- *Default Value*: `{}`

This config option controls the default export file format for each Sphinx
builder. It accepts a dictionary mapping builder names to image formats. The
builder name should match the name of a [Sphinx builder](https://www.sphinx-doc.org/en/master/usage/builders/index.html)
(e.g., `"html"`, `"latex"`). Accepted values for the export format are `"png"`,
`"jpg"`, `"svg"` and `"pdf"`. If no format is set for a given builder, its
preferred image format is used, that is, the first format listed in a builder's
_supported_image_types_ that draw.io is capable of exporting to (eg. SVG for
HTML, PDF for LaTeX). 

### Default Export Scale
- *Formal Name*: `drawio_default_export_scale`
- *Default Value*: `100`
- *Possible Values*: any positive integer

This config option sets the default export scale for all diagrams. This scales
the size of the diagram. So if you take a diagram that by default would output 
a image with a resolution of 50x50 pixels and a scale of 200, you will obtain an
image with a resolution that is approximately 100x100 pixels. By default draw.io
*usually* outputs relatively low resolution images, so this setting can be used
to remedy that. 

This setting will get automatically overridden if the `scale` is set for a
individual diagram in the directive. If either `export-width` or `export-height`
are set for an image, this option will have no effect on the generated image.

### Default Transparency
- *Formal Name*: `drawio_default_transparency`
- *Default Value*:  `False`
- *Possible Values*: `True` or `False`

This changes the background transparency for diagrams exported in *png* format. 
This will be overridden if the transparency is set for a individual diagram in
the directive. If the output format isn't *png*, it will not affect the image
exported.

### Disable Verbose Electron
- *Formal Name*: `drawio_disable_verbose_electron`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

Electron's verbose logging is turned on by default to help troubleshoot certain
errors produced by the drawio app, but can be disabled if it causes a logging
conflict. This option only affects the output when the drawio app errors. See the
[Electron docs](https://www.electronjs.org/docs/latest/api/command-line-switches#--enable-loggingfile)
for more info.

### No Sandbox
- *Formal Name*: `drawio_no_sandbox`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

This option may be needed to work in a docker container. You should probably
only enable it if you are experiencing issues. See https://github.com/jgraph/drawio-desktop/issues/144 
for more info. 

## Usage
The extension can be used through the `drawio-image` directive. For example:
```
.. drawio-image:: example.drawio
   :export-scale: 150
```

There's also a `drawio-figure` directive that mimics the `figure` directive:
```
.. drawio-figure:: example.drawio
   :format: png

   An example diagram
```

The directives can be configured with options to control the export of the
draw.io diagram to a bitmap or vector image. These options are documented below.

Additionally, `drawio-image` accepts all of the options supported by the
[image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
These options apply to the image as exported by draw.io. Similarly,
`drawio-figure` accepts all options supported by the [figure directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure).

### Format
- *Formal Name*: `:format:`
- *Default Value*: `"png"`
- *Possible Values*: `"png"`, `"jpg"`, `"svg"` or `"pdf"`

This option controls the output file format of *this specific* directive.

### Page Index
- *Formal Name*: `:page-index:`
- *Default Value*: `0`
- *Possible Values*: any integer

This option allows you to select a particular page from a draw.io file to
export. Note that an invalid page-index will revert to one of the other valid
pages (draw.io binary functionality).

### Export Scale
- *Formal Name*: `:export-scale:`
- *Default Value*: `drawio_default_export_scale` set in conf.py
- *Possible Values*: any positive integer

This scales the size of the output image. So if you take a diagram that by
default would output a image with a resolution of 50x50 pixels and a scale of
200, you will obtain an image with a resolution that is approximately 100x100 
pixels. By default draw.io *usually* outputs relatively low-resolution images,
so this setting can be used to remedy that. This overrides the
`drawio_default_export_scale` set in conf.py for this specific diagram. If
either `export-width` or `export-height` are set for a given image,
`export-scale` will have no effect on the generated image.

### Export Width
- *Formal Name*: `:export-width:`
- *Possible Values*: any positive integer

This fits the generated image into the specified width, preserving aspect ratio.
When exporting to a bitmap image, this specifies the width in pixels. For PDF,
a value of 100 corresponds to 1.00 inches.

### Export Height
- *Formal Name*: `:export-height:`
- *Possible Values*: any positive integer

This fits the generated image into the specified height, preserving aspect
ratio. When exporting to a bitmap image, this specifies the height in pixels.
For PDF, a value of 100 corresponds to 1.00 inches.

### Transparency
- *Formal Name*: `:transparency:`
- *Default Value*: `drawio_default_transparency` set in conf.py
- *Possible Values*: `"true"` or `"false"`

This changes the background transparency for diagrams exported to `png` files.
Will override `drawio_default_transparency` which was set in conf.py for this
specific diagram. If this setting is specified while the output format is not
`png` it will have no effect on the generated image




%package -n python3-sphinxcontrib-drawio
Summary:	Sphinx Extension to include draw.io files
Provides:	python-sphinxcontrib-drawio
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-sphinxcontrib-drawio
# sphinxcontrib-drawio

Sphinx Extension adding the `drawio-image` and `drawio-figure` directives.
These are equivalent to the standard `image` and `figure` directives, but
accept the path to a `.drawio` file and additional options to control
exporting of the diagram to a suitable image format. 

These directives replace the `drawio` directive which is now deprecated, and
for which support will be dropped in version 1.0. Deprecation warnings are 
output when a `drawio` directive is encountered. Please replace these with
`drawio-image` orand `drawio-figure`, taking into account these differences:

- the *drawio_output_format* conf.py option has been removed; the draw.io
  diagram is exported to the Sphinx builder's preferred image format (eg. SVG
  for HTML, PDF for LaTeX). The *drawio_builder_export_format* configuration
  variable allows setting another default export format for each builder. Note
  that this can still be overridden for individual `drawio-image` and
  `drawio-figure` directives. See below for details.
- the *scale*, *width* and *height* options have been renamed, respectively, to
  *export-scale*, *export-width* and *export-height* so as not to conflict with
  the options inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *export-scale* option now takes an integer percentage; i.e. a value of 100
  means no scaling. This was changed to allow non-integer scaling and offer
  consistency with the `scale` option inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *drawio_default_scale* conf.py option has been replaced by the
  *drawio_default_export_scale* option, also accepting a integer percentage
  value.

**Important:** This extension does not work on readthedocs as RTD does not allow
packages (e.g. drawio) to be installed. If you only require diagrams in a single
format, you can consider using editable SVGs or PNGs, accessible through
draw.io's File > Export menu.

The drawio-desktop package does not run without an x-server (e.g. when in a CI
environment), see [this issue](https://github.com/jgraph/drawio-desktop/issues/146).
The workaround is to install `xvfb` and set the `drawio_headless` configuration
option to `auto`.

If any other of the `draw.io` CLI tool's options are wanted, please file an
issue.

## Installation

1. `python3 -m pip install sphinxcontrib-drawio`
2. In your sphinx config, add:

    ```python
    extensions = [
        "sphinxcontrib.drawio"
    ]
    ```

3. Add the draw.io binary to `$PATH`. See [Options: Binary Path](#binary-path)
   for more details and alternative solutions.

4. If running headless, install Xvfb, e.g. via `$ sudo apt install xvfb`.

## Options
These values are placed in the `conf.py` of your sphinx project.

### Binary Path
- *Formal Name*: `drawio_binary_path`
- *Default Value*: `None`

This allows for a specific override for the binary location. By default, this
chooses the `drawio` (or `draw.io.exe`) binary accessible in `$PATH`. However,
if this file does not exist, it picks the platform-appropriate path:

- Windows: `C:\Program Files\draw.io\draw.io.exe`
- Linux: `/opt/drawio/drawio` or `/opt/draw.io/drawio` (older versions)
- MacOS: `/Applications/draw.io.app/Contents/MacOS/draw.io`.

### Headless Mode
- *Formal Name*: `drawio_headless`
- *Default Value*: `"auto"`
- *Possible Values*: `True`, `False`, or `"auto"`

This config option controls the behaviour of running the Xvfb server. It is
necessary because `draw.io` will not work without an X-server, see
[this issue](https://github.com/jgraph/drawio-desktop/issues/146).

The `auto` mode will detect whether the program is running in a headless
environment through the `$DISPLAY` environment variable, and act as if it were
set to `True`. If not running on Linux, or the `$DISPLAY` environment variable
contains some value (i.e. running in an X-server on a developer's machine), it
will act as it it were set to `False`.

Setting the value to `True` will start a virtual X framebuffer through the
`Xvfb` command before running any `draw.io` commands, and stop it afterwards.

Setting the value to `False` will run the `draw.io` binary as normal.

### Default Output Format
- *Formal Name*: `drawio_builder_export_format`
- *Default Value*: `{}`

This config option controls the default export file format for each Sphinx
builder. It accepts a dictionary mapping builder names to image formats. The
builder name should match the name of a [Sphinx builder](https://www.sphinx-doc.org/en/master/usage/builders/index.html)
(e.g., `"html"`, `"latex"`). Accepted values for the export format are `"png"`,
`"jpg"`, `"svg"` and `"pdf"`. If no format is set for a given builder, its
preferred image format is used, that is, the first format listed in a builder's
_supported_image_types_ that draw.io is capable of exporting to (eg. SVG for
HTML, PDF for LaTeX). 

### Default Export Scale
- *Formal Name*: `drawio_default_export_scale`
- *Default Value*: `100`
- *Possible Values*: any positive integer

This config option sets the default export scale for all diagrams. This scales
the size of the diagram. So if you take a diagram that by default would output 
a image with a resolution of 50x50 pixels and a scale of 200, you will obtain an
image with a resolution that is approximately 100x100 pixels. By default draw.io
*usually* outputs relatively low resolution images, so this setting can be used
to remedy that. 

This setting will get automatically overridden if the `scale` is set for a
individual diagram in the directive. If either `export-width` or `export-height`
are set for an image, this option will have no effect on the generated image.

### Default Transparency
- *Formal Name*: `drawio_default_transparency`
- *Default Value*:  `False`
- *Possible Values*: `True` or `False`

This changes the background transparency for diagrams exported in *png* format. 
This will be overridden if the transparency is set for a individual diagram in
the directive. If the output format isn't *png*, it will not affect the image
exported.

### Disable Verbose Electron
- *Formal Name*: `drawio_disable_verbose_electron`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

Electron's verbose logging is turned on by default to help troubleshoot certain
errors produced by the drawio app, but can be disabled if it causes a logging
conflict. This option only affects the output when the drawio app errors. See the
[Electron docs](https://www.electronjs.org/docs/latest/api/command-line-switches#--enable-loggingfile)
for more info.

### No Sandbox
- *Formal Name*: `drawio_no_sandbox`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

This option may be needed to work in a docker container. You should probably
only enable it if you are experiencing issues. See https://github.com/jgraph/drawio-desktop/issues/144 
for more info. 

## Usage
The extension can be used through the `drawio-image` directive. For example:
```
.. drawio-image:: example.drawio
   :export-scale: 150
```

There's also a `drawio-figure` directive that mimics the `figure` directive:
```
.. drawio-figure:: example.drawio
   :format: png

   An example diagram
```

The directives can be configured with options to control the export of the
draw.io diagram to a bitmap or vector image. These options are documented below.

Additionally, `drawio-image` accepts all of the options supported by the
[image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
These options apply to the image as exported by draw.io. Similarly,
`drawio-figure` accepts all options supported by the [figure directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure).

### Format
- *Formal Name*: `:format:`
- *Default Value*: `"png"`
- *Possible Values*: `"png"`, `"jpg"`, `"svg"` or `"pdf"`

This option controls the output file format of *this specific* directive.

### Page Index
- *Formal Name*: `:page-index:`
- *Default Value*: `0`
- *Possible Values*: any integer

This option allows you to select a particular page from a draw.io file to
export. Note that an invalid page-index will revert to one of the other valid
pages (draw.io binary functionality).

### Export Scale
- *Formal Name*: `:export-scale:`
- *Default Value*: `drawio_default_export_scale` set in conf.py
- *Possible Values*: any positive integer

This scales the size of the output image. So if you take a diagram that by
default would output a image with a resolution of 50x50 pixels and a scale of
200, you will obtain an image with a resolution that is approximately 100x100 
pixels. By default draw.io *usually* outputs relatively low-resolution images,
so this setting can be used to remedy that. This overrides the
`drawio_default_export_scale` set in conf.py for this specific diagram. If
either `export-width` or `export-height` are set for a given image,
`export-scale` will have no effect on the generated image.

### Export Width
- *Formal Name*: `:export-width:`
- *Possible Values*: any positive integer

This fits the generated image into the specified width, preserving aspect ratio.
When exporting to a bitmap image, this specifies the width in pixels. For PDF,
a value of 100 corresponds to 1.00 inches.

### Export Height
- *Formal Name*: `:export-height:`
- *Possible Values*: any positive integer

This fits the generated image into the specified height, preserving aspect
ratio. When exporting to a bitmap image, this specifies the height in pixels.
For PDF, a value of 100 corresponds to 1.00 inches.

### Transparency
- *Formal Name*: `:transparency:`
- *Default Value*: `drawio_default_transparency` set in conf.py
- *Possible Values*: `"true"` or `"false"`

This changes the background transparency for diagrams exported to `png` files.
Will override `drawio_default_transparency` which was set in conf.py for this
specific diagram. If this setting is specified while the output format is not
`png` it will have no effect on the generated image




%package help
Summary:	Development documents and examples for sphinxcontrib-drawio
Provides:	python3-sphinxcontrib-drawio-doc
%description help
# sphinxcontrib-drawio

Sphinx Extension adding the `drawio-image` and `drawio-figure` directives.
These are equivalent to the standard `image` and `figure` directives, but
accept the path to a `.drawio` file and additional options to control
exporting of the diagram to a suitable image format. 

These directives replace the `drawio` directive which is now deprecated, and
for which support will be dropped in version 1.0. Deprecation warnings are 
output when a `drawio` directive is encountered. Please replace these with
`drawio-image` orand `drawio-figure`, taking into account these differences:

- the *drawio_output_format* conf.py option has been removed; the draw.io
  diagram is exported to the Sphinx builder's preferred image format (eg. SVG
  for HTML, PDF for LaTeX). The *drawio_builder_export_format* configuration
  variable allows setting another default export format for each builder. Note
  that this can still be overridden for individual `drawio-image` and
  `drawio-figure` directives. See below for details.
- the *scale*, *width* and *height* options have been renamed, respectively, to
  *export-scale*, *export-width* and *export-height* so as not to conflict with
  the options inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *export-scale* option now takes an integer percentage; i.e. a value of 100
  means no scaling. This was changed to allow non-integer scaling and offer
  consistency with the `scale` option inherited from the [image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
- the *drawio_default_scale* conf.py option has been replaced by the
  *drawio_default_export_scale* option, also accepting a integer percentage
  value.

**Important:** This extension does not work on readthedocs as RTD does not allow
packages (e.g. drawio) to be installed. If you only require diagrams in a single
format, you can consider using editable SVGs or PNGs, accessible through
draw.io's File > Export menu.

The drawio-desktop package does not run without an x-server (e.g. when in a CI
environment), see [this issue](https://github.com/jgraph/drawio-desktop/issues/146).
The workaround is to install `xvfb` and set the `drawio_headless` configuration
option to `auto`.

If any other of the `draw.io` CLI tool's options are wanted, please file an
issue.

## Installation

1. `python3 -m pip install sphinxcontrib-drawio`
2. In your sphinx config, add:

    ```python
    extensions = [
        "sphinxcontrib.drawio"
    ]
    ```

3. Add the draw.io binary to `$PATH`. See [Options: Binary Path](#binary-path)
   for more details and alternative solutions.

4. If running headless, install Xvfb, e.g. via `$ sudo apt install xvfb`.

## Options
These values are placed in the `conf.py` of your sphinx project.

### Binary Path
- *Formal Name*: `drawio_binary_path`
- *Default Value*: `None`

This allows for a specific override for the binary location. By default, this
chooses the `drawio` (or `draw.io.exe`) binary accessible in `$PATH`. However,
if this file does not exist, it picks the platform-appropriate path:

- Windows: `C:\Program Files\draw.io\draw.io.exe`
- Linux: `/opt/drawio/drawio` or `/opt/draw.io/drawio` (older versions)
- MacOS: `/Applications/draw.io.app/Contents/MacOS/draw.io`.

### Headless Mode
- *Formal Name*: `drawio_headless`
- *Default Value*: `"auto"`
- *Possible Values*: `True`, `False`, or `"auto"`

This config option controls the behaviour of running the Xvfb server. It is
necessary because `draw.io` will not work without an X-server, see
[this issue](https://github.com/jgraph/drawio-desktop/issues/146).

The `auto` mode will detect whether the program is running in a headless
environment through the `$DISPLAY` environment variable, and act as if it were
set to `True`. If not running on Linux, or the `$DISPLAY` environment variable
contains some value (i.e. running in an X-server on a developer's machine), it
will act as it it were set to `False`.

Setting the value to `True` will start a virtual X framebuffer through the
`Xvfb` command before running any `draw.io` commands, and stop it afterwards.

Setting the value to `False` will run the `draw.io` binary as normal.

### Default Output Format
- *Formal Name*: `drawio_builder_export_format`
- *Default Value*: `{}`

This config option controls the default export file format for each Sphinx
builder. It accepts a dictionary mapping builder names to image formats. The
builder name should match the name of a [Sphinx builder](https://www.sphinx-doc.org/en/master/usage/builders/index.html)
(e.g., `"html"`, `"latex"`). Accepted values for the export format are `"png"`,
`"jpg"`, `"svg"` and `"pdf"`. If no format is set for a given builder, its
preferred image format is used, that is, the first format listed in a builder's
_supported_image_types_ that draw.io is capable of exporting to (eg. SVG for
HTML, PDF for LaTeX). 

### Default Export Scale
- *Formal Name*: `drawio_default_export_scale`
- *Default Value*: `100`
- *Possible Values*: any positive integer

This config option sets the default export scale for all diagrams. This scales
the size of the diagram. So if you take a diagram that by default would output 
a image with a resolution of 50x50 pixels and a scale of 200, you will obtain an
image with a resolution that is approximately 100x100 pixels. By default draw.io
*usually* outputs relatively low resolution images, so this setting can be used
to remedy that. 

This setting will get automatically overridden if the `scale` is set for a
individual diagram in the directive. If either `export-width` or `export-height`
are set for an image, this option will have no effect on the generated image.

### Default Transparency
- *Formal Name*: `drawio_default_transparency`
- *Default Value*:  `False`
- *Possible Values*: `True` or `False`

This changes the background transparency for diagrams exported in *png* format. 
This will be overridden if the transparency is set for a individual diagram in
the directive. If the output format isn't *png*, it will not affect the image
exported.

### Disable Verbose Electron
- *Formal Name*: `drawio_disable_verbose_electron`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

Electron's verbose logging is turned on by default to help troubleshoot certain
errors produced by the drawio app, but can be disabled if it causes a logging
conflict. This option only affects the output when the drawio app errors. See the
[Electron docs](https://www.electronjs.org/docs/latest/api/command-line-switches#--enable-loggingfile)
for more info.

### No Sandbox
- *Formal Name*: `drawio_no_sandbox`
- *Default Value*: `False`
- *Possible Values*: `True` or `False`

This option may be needed to work in a docker container. You should probably
only enable it if you are experiencing issues. See https://github.com/jgraph/drawio-desktop/issues/144 
for more info. 

## Usage
The extension can be used through the `drawio-image` directive. For example:
```
.. drawio-image:: example.drawio
   :export-scale: 150
```

There's also a `drawio-figure` directive that mimics the `figure` directive:
```
.. drawio-figure:: example.drawio
   :format: png

   An example diagram
```

The directives can be configured with options to control the export of the
draw.io diagram to a bitmap or vector image. These options are documented below.

Additionally, `drawio-image` accepts all of the options supported by the
[image directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#image).
These options apply to the image as exported by draw.io. Similarly,
`drawio-figure` accepts all options supported by the [figure directive](https://docutils.sourceforge.io/docs/ref/rst/directives.html#figure).

### Format
- *Formal Name*: `:format:`
- *Default Value*: `"png"`
- *Possible Values*: `"png"`, `"jpg"`, `"svg"` or `"pdf"`

This option controls the output file format of *this specific* directive.

### Page Index
- *Formal Name*: `:page-index:`
- *Default Value*: `0`
- *Possible Values*: any integer

This option allows you to select a particular page from a draw.io file to
export. Note that an invalid page-index will revert to one of the other valid
pages (draw.io binary functionality).

### Export Scale
- *Formal Name*: `:export-scale:`
- *Default Value*: `drawio_default_export_scale` set in conf.py
- *Possible Values*: any positive integer

This scales the size of the output image. So if you take a diagram that by
default would output a image with a resolution of 50x50 pixels and a scale of
200, you will obtain an image with a resolution that is approximately 100x100 
pixels. By default draw.io *usually* outputs relatively low-resolution images,
so this setting can be used to remedy that. This overrides the
`drawio_default_export_scale` set in conf.py for this specific diagram. If
either `export-width` or `export-height` are set for a given image,
`export-scale` will have no effect on the generated image.

### Export Width
- *Formal Name*: `:export-width:`
- *Possible Values*: any positive integer

This fits the generated image into the specified width, preserving aspect ratio.
When exporting to a bitmap image, this specifies the width in pixels. For PDF,
a value of 100 corresponds to 1.00 inches.

### Export Height
- *Formal Name*: `:export-height:`
- *Possible Values*: any positive integer

This fits the generated image into the specified height, preserving aspect
ratio. When exporting to a bitmap image, this specifies the height in pixels.
For PDF, a value of 100 corresponds to 1.00 inches.

### Transparency
- *Formal Name*: `:transparency:`
- *Default Value*: `drawio_default_transparency` set in conf.py
- *Possible Values*: `"true"` or `"false"`

This changes the background transparency for diagrams exported to `png` files.
Will override `drawio_default_transparency` which was set in conf.py for this
specific diagram. If this setting is specified while the output format is not
`png` it will have no effect on the generated image




%prep
%autosetup -n sphinxcontrib-drawio-0.0.16

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-sphinxcontrib-drawio -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.16-1
- Package Spec generated