tpnote-lib 0.45.11

Minimalistic note-taking: save and edit your clipboard content as a note file
Documentation
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
### The fallback scheme for the `sync_filename` template choice, in case the
### `scheme` header variable is empty or is not defined.
### Not to be confused with `app_arg.scheme`!
scheme_sync_default = "default"


### This is the base scheme all schemes inherit from.
[base_scheme]

### The name of the base scheme. Its data is in `base_scheme.filename` and
### `base_scheme.tmpl`.
name = "base_scheme"

### Filename related settings for the base scheme.
[base_scheme.filename]

### List of characters that can be part of a _sort tag_.
### Besides the characters listed here, the digits `0..9` and
### the lowercase letters `a..z` are always valid sort-tag characters.
sort_tag.extra_chars = ".-_="

### If empty, the first character which is not in `filename.sort_tag.extra_chars`
### marks the end of a sort tag.
### If not empty, a _sort_tag_ is only valid, when is its followed by
### `filename.sort_tag.separator`. A _sort_tag_ itself may contain separators,
### but must not end with one.
sort_tag.separator = "-"

### In case the file stem starts with a character in `sort_tag.extra_chars` a
### `sort_tag.extra_separator` character may be inserted in order to tell
### the sort tag apart reliably.
sort_tag.extra_separator = "'"

### A sort-tag can have several counters. A counter is a set of digits or
### a set of lower case letters. A valid sort-tag (sequential or chronological)
### can have at most this number of letters in succession.
sort_tag.letters_in_succession_max = 2

### The criterion to tell if a sort tag is sequential or not:
### a sequential sort-tag must have at most `digits_in_succession_max ` number
### of digits in succession. By default, this is set to `3` assuming, that a
### chronological sort-tag usually contains some year information, e.g.
### `20231028` or `2023-10-28` with at least 4 digits. On the other hand,
### we require sequential sort-tags to have shorter numbers to satisfy this
### criterion, e.g. `3.1.123` or `3a123`.
sort_tag.sequential.digits_in_succession_max = 3

### If the stem of a filename ends with a pattern, that is similar to a copy
### counter, add this extra separator. It must be one of `TRIM_LINE_CHARS` (see
### definition in crate: `sanitize_filename_reader_friendly`) because they are
### known not to appear at the end of `sanitze()`'d strings. This is why they
### are suitable here.
copy_counter.extra_separator = "-"

### Tp-Note may add a counter at the end of the filename when it cannot save a
### file because the name is taken already. This is the opening bracket search
### pattern. Some examples: `"-"`, "'_'"", `"_-"`,`"-_"`, `"("` Can be empty.
copy_counter.opening_brackets = "("

### Tp-Note may add a counter at the end of the filename when it cannot save a
### file because the name is taken already. This is the closing bracket search
### pattern. Some examples: `"-"`, "'_'"", `"_-"`,`"-_"`, `"("` Can be empty.
copy_counter.closing_brackets = ")"

### File extension for new Tp-Note files.
### NB: Do not forget to adapt the templates `tmpl.*` in case you set
### this to another markup language.
extension_default = "md"

### The variable `filename.extensions` lists all file extensions that Tp-Note
### considers as its own note files. The list entry is a tuple defined as
### follows:
###     Vec[(extension,
###          html_to_markup(extension),
###          markup_to_html(extension)
###     )]
###
### The templates `from_clipboard` and `from_clipboard_yaml` contain some
### `html_to_markup(extension)` filters which convert HTML clipboard content
### into markup formatted content. The second tuple value of the vector
### parameterizes the `html_to_markup` filter. It determines which converter is
### used. Currently, the following converters are implemented:
### * `Disabled`,
### * `ToMarkdown` and
### * `PassThrough`.
###
### When Tp-Note's viewer displays a note file, the HTML output is generated
### with `tmpl_html` templates. The templates contain some
### `markup_to_html(extension)` filters which are parametrized by the third
### value of the tuple. It determines which renderer is used.
### Currently, the following renderers are implemented:
### * `Markdown`,
### * `ReStructuredText`,
### * `PassThrough`,
### * `PlainText` and
### * `RendererDisabled`.
###
### Normally, the rendered HTML is displayed to the user via his web browser.
### Only when the selected renderer for a certain file extension is
### `RendererDisabled`, then no viewer is started.
###
### NB: The list is ordered to look for the most common extensions first.
extensions = [
  ["txt", "ToMarkdown", "Markdown"],
  ["md", "ToMarkdown", "Markdown"],
  ["rst", "Disabled", "ReStructuredText"],
  ["htmlnote", "PassThrough", "Html"],
  ["txtnote", "Disabled", "PlainText"],
  ["adoc", "Disabled", "PlainText"],
  ["text", "ToMarkdown", "Markdown"],
  ["markdn", "ToMarkdown", "Markdown"],
  ["markdown", "ToMarkdown", "Markdown"],
  ["mdown", "ToMarkdown", "Markdown"],
  ["mdtext", "ToMarkdown", "Markdown"],
  ["mdtxt", "ToMarkdown", "Markdown"],
  ["mdwn", "ToMarkdown", "Markdown"],
  ["mkd", "ToMarkdown", "Markdown"],
  ["rest", "Disabled", "ReStructuredText"],
  ["asciidoc", "Disabled", "PlainText"],
  ["mediawiki", "Disabled", "RendererDisabled"],
  ["mw", "Disabled", "RendererDisabled"],
  ["t2t", "Disabled", "RendererDisabled"],
]

### Template related settings for the base scheme.
[base_scheme.tmpl]

### After generating a new note with a content template, Tp-Note parses the
### resulting front matter variables, which may be localized. The variables, are
### then converted into front matter variables starting with `fm.fm_`.
###
### The first item per line is the checked `fm.fm_`-variable as it appears
### in the templates.
### The second item per line is the translated variable name as it appears in the
### note file. For example, the expression `fm.fm_lang` resolves to `lang`.
### This allows to translate the templates into other human languages than English
### without actually touching the templates itself.
### For variables not listed below, only the prefix `fm.fm_` is stripped and
### no translation occurs, e.g. `fm.fm_unknown` becomes `unknown`.
fm_var.localization = [
    ["fm_title", "title"],
    ["fm_subtitle", "subtitle"],
    ["fm_author", "author"],
    ["fm_date", "date"],
    ["fm_lang", "lang"],
    ["fm_languages", "languages"],
    ["fm_sort_tag", "sort_tag"],
    ["fm_file_ext", "file_ext"],
    ["fm_no_filename_sync", "no_filename_sync"],
    ["fm_filename_sync", "filename_sync"],
    ["fm_scheme", "scheme"],
]

### Before the front matter `fm.fm_` variables are applied to a filename template,
### their validity is checked. The following table lists test, every value has to
### pass. If one test fails the user is informed.
###
### * `IsDefined`: Assert that the variable is defined in the template.
### * `IsString`: Assert, that if the variable is defined, its type -or all
###    subtypes- are `Value::String`.
### * `IsNotEmptyString`: In addition to `IsString`, the condition asserts, that
###    the string -or all substrings-) are not empty.
### * `IsNumber`: Assert, that if the variable is defined, its type -or all
###    subtypes- are `Value::Number`.
### * `IsBool`: Assert, that if the variable is defined, its type -or all
###    subtypes- are `Value::Bool`.
### * `IsNotCompound`: Assert, that if the variable is defined, its type is not
###   `Value::Array` or `Value::Object`.
### * `IsValidSortTag`: Assert, that if the variable is defined, the value's
###    string representation contains solely characters of the
###    `filename.sort_tag.extra_chars` set, digits or lowercase letters.
###    The number of lowercase letters in a row is limited by
###    `scheme.filename.sort_tag.letters_in_succession_max`.
### *  `IsConfguredScheme`: Assert, that -if the variable is defined- the
###    string equals to one of the `scheme.name` in the configuration file.
### * `IsTpnoteExtension`: Assert, that if the variable is defined, the values
###    string representation is registered in one of the `filename.extension_*`
###    configuration file variables.
### * `NoOperation` (default): A test that is always satisfied. For internal use
###    only.
###
fm_var.assertions = [
    ["fm_title", ["IsDefined", "IsString", "IsNotEmptyString", "IsNotCompound"]],
    ["fm_subtitle", ["IsString", "IsNotCompound"]],
    ["fm_author",  ["IsString"]],
    ["fm_lang", ["IsString", "IsNotCompound"]],
    ["fm_languages", ["IsString"]],
    ["fm_sort_tag", ["IsNotCompound", "IsValidSortTag"]],
    ["fm_file_ext", ["IsString", "IsNotCompound", "IsTpnoteExtension"]],
    ["fm_no_filename_sync", ["IsBool", "IsNotCompound"]],
    ["fm_filename_sync", ["IsBool", "IsNotCompound"]],
    ["fm_scheme", ["IsString", "IsConfiguredScheme"]],
]

### The operation mode of the `get_lang` filter.
###
### * Disabled:
###    The `get_lang` filter is disabled. No language guessing occurs.
### * Monolingual:
###   The algorithm of the `get_lang` filter assumes, that the input is
###   monolingual. Only one language is searched and reported.
### * Multilingual:
###   The algorithm of the `get_lang` filter assumes, that the input is
###   monolingual. If present in the input, more than one language can be
###   reported.
filter.get_lang.mode = "Multilingual"

### A list of language tags, defining languages the `get_lang` filter tries
### to identify in its input. The user's default language subtag, as reported
### from the operating system, is automatically added to the present list.
### The language recognition feature is disabled, when the user's default
### language, as reported from the operating system, is not supported by the
### external language guessing library Lingua. In this case the filter returns
### always the empty array.
### If the list `language_candiates` is empty, the algorithm searches for all
### available languages (currently 75). The environment variable
### `TPNOTE_LANG_DETECTION, if set, overwrites this setting.
### Example: filter.get_lang.language_candidates = [ "en", "fr", "de" ]
filter.get_lang.language_candidates = []

### Sets the desired value for the minimum relative distance measure.
### This is one of the parameters with which false positives can be reduced
### when determining natural language with the `get_lang` filter.
### By default, the Lingua library returns the most likely language for a given
### input text. However, there are certain words that are spelled the same in
### more than one language. The word prologue, for instance, is both a valid
### English and French word. Lingua would output either English or French which
### might be wrong in the given context. For cases like that, it is possible
### to specify a minimum relative distance that the logarithmized and summed up
### probabilities for each possible language have to satisfy. Be aware that the
### distance between the language probabilities is dependent on the length of
### the input text. The longer the input text, the larger the distance between
### the languages. So if you want to classify very short text phrases, do not
### set the minimum relative distance too high. Otherwise, `get_lang` will
### return most results as empty array, which is the return value for cases
### where language detection is not reliably possible. Valid values are between
### `0.0` and `0.99`. A low value finds more languages, but can lead to more
### false positives.
### NB: Languages not listed in `language_candidates` are never searched for,
### independent of the `relative_distance_min` value set here.
filter.get_lang.relative_distance_min = 0.3

### Sets the minimum amount of consecutive words in one language to be
### considered when detecting languages in the input text. This is one of
### the parameters with which false positives can be reduced when determining
### natural language with the `get_lang` filter.
filter.get_lang.consecutive_words_min  = 7

### Set the minimum word count ratio in percent a language must appear in
### the input text to be reported. This is one of the parameters with which
### false positives can be reduced when determining natural language with the
### `get_lang` filter.
filter.get_lang.words_total_percentage_min = 10

### Default values for the `map_lang` hash map filter, that are used to post
### process the language recognition subtag as defined in `filter.get_lang`.
### The key is a language subtag as ISO 639 code, the corresponding value is
### an IETF language tag obtained by adding some region information. The region
### information is useful because some editor plugins like the _LanguageTool_
### grammar checker can read it.
### In case a language subtag has no key in the present hash map, the filter
### forwards the input unchanged, e.g. the filter input `fr` results in `fr`.
### One entry, derived from the user's default language - as reported from the
### operating system - is automatically added to the present list. This
### happens only when this language is not listed yet. For example,
### consider the list `tmpl.filter.map_lang = &[&["en", "en-US"]]`: In this
### case, the user's default language `fr_CA.UTF-8` is added as
### `&["fr", "fr-CA"]`. But, if the user's default language were
### `en_GB.UTF-8`, then it is _not_ added because an entry `&["en", "en-US"]`
### exists already.
### Note, that the empty input string results in the user's default language
### tag - here `fr-CA` - as well.
filter.map_lang = [
    [ "de", "de-DE", ],
    [ "et", "et-ET", ],
]

### Default value used by `to_yaml_filter`.
### The parameter `tmpl.filter.to_yaml_tab = n` indents the YAML values
### `n` characters to the right of the first character of the key by inserting
### additional spaces between the key and the value. `n==0` disables the
### extra indentation.
filter.to_yaml_tab = 14

### Default content template used when the command line argument `<sanit>`
### is a directory. Can be changed through editing the configuration
### file. The following variables are defined:
### Clipboard data may be available.
### This template needs `Context<ReadyForContentTemplate`.
from_dir_content = """
{%- set stdin = stdin.body |default(value = '') -%}
{%- set html_clipboard = html_clipboard.body |default(value = '') -%}
{%- set txt_clipboard = txt_clipboard.body |default(value = '') -%}

{%- set title_text = fm.fm_title | default(value = '')
     | replace_empty(with = stdin | html_heading )
     | replace_empty(with = stdin | link_text_picky )
     | replace_empty(with = stdin | link_text )
     | replace_empty(with = stdin | heading )
     | replace_empty(with = html_clipboard | html_heading )
     | replace_empty(with = html_clipboard | link_text_picky )
     | replace_empty(with = txt_clipboard | link_text_picky )
     | replace_empty(with = html_clipboard | link_text )
     | replace_empty(with = txt_clipboard | link_text )
     | replace_empty(with = txt_clipboard | heading )
     | replace_empty(with = path | trim_file_sort_tag )
     | trim  -%}

{%- set stdin = stdin
     | html_to_markup(extension=extension_default, default=stdin)
     | append(newline=true) -%}
{%- set clipboard = html_clipboard
     | html_to_markup(extension=extension_default, default=txt_clipboard) -%}
{%- set input = stdin ~ clipboard | trim -%}

{%- set languages = fm.fm_languages
     | default(value = [force_lang])
     | replace_empty(with = input | replace_empty(with = path | trim_file_sort_tag )
                             | get_lang | map_lang(default=lang) ) -%}
{%- set lang = fm.fm_lang | default(value = languages | first ) -%}

---
{{ title_text | trunc | to_yaml(key='fm_title') }}
{{ fm.fm_subtitle | default(value = 'Note') | trunc | to_yaml(key='fm_subtitle') }}
{{ fm.fm_author | default(value=username | capitalize) | to_yaml(key='fm_author') }}
{{ fm.fm_date | default(value = now()|date(format='%Y-%m-%d')) | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
  {{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
{#- We deliberately ignore `fm.fm_scheme` from clipboards -#}
{% if scheme_sync_default != current_scheme -%}
  {{ current_scheme | to_yaml(key='fm_scheme') | append(newline=true) }}
{%- endif -%}
{% if fm.fm_sort_tag -%}
  {{ fm.fm_sort_tag | to_yaml(key='fm_sort_tag') | append(newline=true) }}
{%- endif -%}
{%- if fm -%}
  {{- fm
    | remove(key='fm_title')
    | remove(key='fm_subtitle')
    | remove(key='fm_author')
    | remove(key='fm_date')
    | remove(key='fm_lang')
    | remove(key='fm_languages')
    | remove(key='fm_scheme')
    | remove(key='fm_sort_tag')
    | to_yaml
    | prepend(newline=true)
    | append(newline=true) -}}
{%- endif -%}
---

{{ input | append(newline=true) }}
"""

### Default filename template for a new note file on disk. It implements the
### sync criteria for note metadata in front matter and filename.
### This template needs `Context<ReadyForFilenameTemplate>`.
from_dir_filename = """
{%- if fm.fm_sort_tag -%}
  {%- set tag = fm.fm_sort_tag | as_str -%}
{%- else -%}
  {%- set tag = dir_path | find_last_created_file
        | incr_sort_tag(default=now() | date(format='%Y%m%d')) -%}
{%- endif -%}
{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ fm.fm_subtitle | sanit | prepend(with='--') }}\
{{ fm.fm_file_ext | default(value = extension_default ) | prepend(with='.') }}"""

### Default template used, when the opened text file (with a known file
### extension) is missing a YAML front matter section. This template prepends
### such a header. The template inserts information extracted from the input
### filename and its creation date. `{{ path }}` points to the text file,
### `{{ dir_path }}` to the directory where it is located.
from_text_file_content = """
{%- set languages = [force_lang]
   | replace_empty(with = doc.body | get_lang | map_lang(default=lang)) -%}
{%- set lang = languages | first -%}
---
{{ path | file_stem | split(pat='--') | first | trunc | to_yaml(key='fm_title') }}
{{ path | file_stem | split(pat='--') | nth(n=1) | trunc
     | to_yaml(key='fm_subtitle') }}
{{ username | capitalize | to_yaml(key='fm_author') }}
{{ doc_file_date | default(value=now()) | date(format='%Y-%m-%d') | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
{{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
# {{ path | file_name | to_yaml(key='fm_orig_name', tab=12) }}
{% if scheme_sync_default != current_scheme -%}
{{ current_scheme | to_yaml(key='fm_scheme') | append(newline=true) }}
{%- endif -%}
---

{{ doc.body }}
"""

### Default filename template used when the input file (with a known
### file extension) is missing a YAML front matter section.
### The text file's sort-tag and file extension are preserved.
from_text_file_filename = """
{%- if path | file_sort_tag != '' -%}
  {%- set tag = path | file_sort_tag -%}
{%- else -%}
  {%- set tag = doc_file_date | default(value=now()) | date(format='%Y%m%d') -%}
{%- endif -%}
{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ fm.fm_subtitle | default(value='') | sanit | prepend(with='--') }}\
{{ path | file_ext | prepend(with='.') }}"""

### Default template used when the command line `<path>` parameter points to an
### existing - to be annotated - non-`.md`-file. `{{ path}}` points to that
### file, `{{ dir_path }}` to the directory where it is located.
annotate_file_content = """
{%- set stdin = stdin.body |default(value = '') -%}
{%- set html_clipboard = html_clipboard.body |default(value = '') -%}
{%- set txt_clipboard = txt_clipboard.body |default(value = '') -%}

{%- set stdin = stdin | html_to_markup(extension=extension_default, default=stdin) | append(newline=true) -%}
{%- set clipboard = html_clipboard
      | html_to_markup(extension=extension_default, default=txt_clipboard) -%}
{%- set input = stdin ~ clipboard | trim_end -%}
{%- set languages = [force_lang]
      | replace_empty(with = input | replace_empty(with = path | file_stem) | get_lang | map_lang(default=lang)) -%}
{%- set lang = languages | first -%}

{%- set fname = path | file_name -%}
{%- if extension_default != 'rst' -%}
   {%- set link = '[' ~ fname ~ '](<' ~ fname ~ '>)' -%}
{%- else -%}
   {%- set link = '`<' ~ fname ~ '>`_' -%}
  {%- endif -%}
---
{{ path | trim_file_sort_tag | to_yaml(key='fm_title') }}
{{ 'Note' | to_yaml(key='fm_subtitle') }}
{{ username | capitalize | to_yaml(key='fm_author') }}
{{ now() | date(format='%Y-%m-%d') | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
{{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
{% if scheme_sync_default != current_scheme -%}
{{ current_scheme | to_yaml(key='fm_scheme') | append(newline=true) }}
{%- endif -%}
---

{{ link }}
{{- input | prepend(with='\n____\n\n')}}

"""

### Filename of a new note, that annotates an existing file on disk given in
### `<path>`.
annotate_file_filename = """
{%- set tag = path | file_sort_tag -%}
{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ fm.fm_subtitle | default(value='') | sanit | prepend(with='--') }}\
{{ extension_default | prepend(with='.') }}"""

### Default filename template to test, if the filename of an existing note file
### on disk, corresponds to the note's meta data stored in its front matter. If
### it is not the case, the note's filename will be renamed.
sync_filename = """
{%- set tag = fm.fm_sort_tag | default(value = path | file_sort_tag) | as_str -%}
{{ fm.fm_title | default(value='No title') | sanit | prepend(with_sort_tag=tag) }}\
{{ fm.fm_subtitle | default(value='') | sanit | prepend(with='--') }}\
{{ fm.fm_file_ext | default(value = path | file_ext) | prepend(with='.') }}
"""




### All scheme definitions below inherit from the above `base_scheme`. This
### has the advantage, that we define here only the differences to
### `base_scheme`.


### The `default` scheme taken form `base_scheme` without modification.
[[scheme]]
### The name of this scheme. The data is in `scheme.filename` and
### `scheme.tmpl`.
name = "default"




[[scheme]]
name = "zettel"

[scheme.filename]

sort_tag.separator = "--"

[scheme.tmpl]

from_dir_content = """
{%- set stdin = stdin.body |default(value = '') -%}
{%- set html_clipboard = html_clipboard.body |default(value = '') -%}
{%- set txt_clipboard = txt_clipboard.body |default(value = '') -%}

{%- set title_text = fm.fm_title | default(value = '')
     | replace_empty(with = stdin | html_heading )
     | replace_empty(with = stdin | link_text_picky )
     | replace_empty(with = stdin | link_text )
     | replace_empty(with = stdin | heading )
     | replace_empty(with = html_clipboard | html_heading )
     | replace_empty(with = html_clipboard | link_text_picky )
     | replace_empty(with = txt_clipboard | link_text_picky )
     | replace_empty(with = html_clipboard | link_text )
     | replace_empty(with = txt_clipboard | link_text )
     | replace_empty(with = txt_clipboard | heading )
     | replace_empty(with = path | trim_file_sort_tag )
     | trim  -%}

{%- set stdin = stdin
     | html_to_markup(extension=extension_default, default=stdin)
     | append(newline=true) -%}
{%- set clipboard = html_clipboard
     | html_to_markup(extension=extension_default, default=txt_clipboard) -%}
{%- set input = stdin ~ clipboard | trim -%}

{%- set languages = fm.fm_languages
      | default(value = [force_lang])
      | replace_empty(with = input
          | replace_empty(with = path | trim_file_sort_tag )
          | get_lang
          | map_lang(default=lang) ) -%}
{%- set lang = fm.fm_lang | default(value=languages | first ) -%}

{%- if fm.fm_sort_tag -%}
  {%- set tag = fm.fm_sort_tag -%}
{%- else -%}
  {%- set tag_default = now() | date(format='%Y%m%d') -%}
  {%- set tag = dir_path
        | find_last_created_file
        | incr_sort_tag(default=tag_default) -%}
{%- endif -%}
---
{{ title_text | trunc | to_yaml(key='fm_title') }}
{{ fm.fm_keywords | default(value = ['note']) | to_yaml(key='fm_keywords') }}
{{ fm.fm_author | default(value=username | capitalize) | to_yaml(key='fm_author') }}
{{ fm.fm_date | default(value = now()|date(format='%Y-%m-%d')) | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
  {{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
{#- We deliberately ignore `fm.fm_scheme` from clipboards -#}
{{ 'zettel' | to_yaml(key='fm_scheme') }}
{{ tag | to_yaml(key='fm_sort_tag') }}
{% if fm -%}
  {{- fm
    | remove(key='fm_title')
    | remove(key='fm_keywords')
    | remove(key='fm_author')
    | remove(key='fm_date')
    | remove(key='fm_lang')
    | remove(key='fm_languages')
    | remove(key='fm_scheme')
    | remove(key='fm_sort_tag')
    | to_yaml
    | prepend(newline=true)
    | append(newline=true) -}}
{%- endif -%}
---

{{ input | append(newline=true) }}
"""

from_dir_filename = """
{%- set keywords = '' -%}
{%- for sub in fm.fm_keywords | default(value=[]) -%}
{%- set_global keywords = keywords~sub~'_' -%}
{%- endfor -%}

{%- if fm.fm_sort_tag -%}
  {%- set tag = fm.fm_sort_tag | as_str -%}
{%- else -%}
  {%- set tag_default = now() | date(format='%Y%m%d') -%}
  {%- set tag = dir_path
        | find_last_created_file
        | incr_sort_tag(default=tag_default) -%}
{%- endif -%}

{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ keywords | default(value='') | sanit | prepend(with='__') }}\
{{ fm.fm_file_ext | default(value = extension_default ) | prepend(with='.') }}"""

from_text_file_content = """
{%- set file = path | file_name -%}
{%- if file is containing('==')-%}
  {%- set file = file | split(pat='==') | nth(n=1) -%}
{%- endif -%}

{%- if path | file_sort_tag != '' -%}
  {%- set tag = path | file_sort_tag -%}
{%- else -%}
  {%- set tag = doc_file_date | default(value=now()) | date(format='%Y%m%d') -%}
{%- endif -%}

{%- set file = file | file_stem -%}
{%- set title = file | split(pat='__') | first -%}
{%- set keywords = file | split(pat='__') | nth(n=1) -%}
{%- set languages = [force_lang]
   | replace_empty(with = doc.body | get_lang | map_lang(default=lang)) -%}
{%- set lang = languages | first -%}
---
{{ title | trunc | to_yaml(key='fm_title') }}
{{ keywords | split(pat='_') | to_yaml(key='fm_keywords') }}
{{ username | capitalize | to_yaml(key='fm_author') }}
{{ doc_file_date | default(value=now()) | date(format='%Y-%m-%d') | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
{{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
{{ 'zettel' | to_yaml(key='fm_scheme') }}
{{ tag | to_yaml(key='fm_sort_tag') }}
# {{ path | file_name | to_yaml(key='fm_orig_name', tab=12) }}
---

{{ doc.body }}
"""

from_text_file_filename = """
{%- if fm.fm_sort_tag -%}
  {%- set tag = fm.fm_sort_tag -%}
{%- else -%}
  {%- if path | file_sort_tag != '' -%}
    {%- set tag = path | file_sort_tag -%}
  {%- else -%}
    {%- set tag = doc_file_date | default(value=now()) | date(format='%Y%m%d') -%}
  {%- endif -%}
{%- endif -%}

{%- set keywords = '' -%}
{%- if fm.fm_keywords | as_str == fm.fm_keywords -%}
  {%- set keywords = fm.fm_keywords -%}
{%- else -%}
  {%- for sub in fm.fm_keywords | default(value=[]) -%}
    {%- set_global keywords = keywords~sub~'_' -%}
  {%- endfor -%}
{%- endif -%}

{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ keywords | sanit | prepend(with='__') }}\
{{ path | file_ext | prepend(with='.') }}"""

annotate_file_content = """
{%- set stdin = stdin.body |default(value = '') -%}
{%- set html_clipboard = html_clipboard.body |default(value = '') -%}
{%- set txt_clipboard = txt_clipboard.body |default(value = '') -%}

{%- set stdin = stdin
      | html_to_markup(extension=extension_default, default=stdin)
      | append(newline=true) -%}
{%- set clipboard = html_clipboard
      | html_to_markup(extension=extension_default, default=txt_clipboard) -%}
{%- set input = stdin ~ clipboard | trim_end -%}
{%- set languages = [force_lang]
      | replace_empty(with = input | replace_empty(with = path | file_stem) | get_lang | map_lang(default=lang)) -%}
{%- set lang = languages | first -%}

{%- set fname = path | file_name -%}
{%- if extension_default != 'rst' -%}
   {%- set link = '[' ~ fname ~ '](<' ~ fname ~ '>)' -%}
{%- else -%}
   {%- set link = '`<' ~ fname ~ '>`_' -%}
  {%- endif -%}
---
{{ path | trim_file_sort_tag | to_yaml(key='fm_title') }}
{{ ['note'] | to_yaml(key='fm_keywords') }}
{{ username | capitalize | to_yaml(key='fm_author') }}
{{ now() | date(format='%Y-%m-%d') | to_yaml(key='fm_date') }}
{{ lang | to_yaml(key='fm_lang') }}
{% if languages | length > 1 -%}
{{ languages | to_yaml(key='fm_languages') | append(newline=true) }}
{%- endif -%}
{{ 'zettel' | to_yaml(key='fm_scheme') }}
{{ path | file_sort_tag | to_yaml(key='fm_sort_tag') }}
---

{{ link }}
{{- input | prepend(with='\n____\n\n')}}

"""

annotate_file_filename = """
{%- set keywords = '' -%}
{%- for sub in fm.fm_keywords | default(value=[]) -%}
{%- set_global keywords = keywords~sub~'_' -%}
{%- endfor -%}

{%- if fm.fm_sort_tag -%}
  {%- set tag = fm.fm_sort_tag -%}
{%- else -%}
  {%- set tag = path | file_sort_tag -%}
{%- endif -%}

{{ fm.fm_title | sanit | prepend(with_sort_tag=tag) }}\
{{ keywords | default(value='') | sanit | prepend(with='__') }}\
{{ extension_default | prepend(with='.') }}"""

sync_filename = """
{%- set keywords = '' -%}
{%- set fm_keywords = fm.fm_keywords | default(value='') -%}
{%- if fm_keywords | as_str == fm_keywords -%}
  {%- set_global keywords = fm_keywords -%}
{%- else -%}
  {%- for sub in fm.fm_keywords -%}
    {%- set_global keywords = keywords~sub~'_' -%}
  {%- endfor -%}
{%- endif -%}

{%- set tag = fm.fm_sort_tag | default(value = path | file_sort_tag) | as_str -%}

{{ fm.fm_title | default(value='No title') | sanit | prepend(with_sort_tag=tag) }}\
{{ keywords | sanit | prepend(with='__') }}\
{{ fm.fm_file_ext | default(value = path | file_ext) | prepend(with='.') }}"""

### This is the end of scheme "zettel"




### This part is common for all schemes.
[tmpl_html]

### HTML template to render regular viewer pages. Note: HTML templates escape HTML
### critical symbols by default. To disable this feature for a specific variable,
### add a `safe` filter in last position.
viewer = '''
{%- set ext = fm.fm_file_ext | default(value=path|file_ext) -%}
<!DOCTYPE html>
<html lang="{{ fm.fm_lang | default(value='en') }}">
<head>
<meta charset="UTF-8">
<title>{{ fm.fm_title }}</title>
<link rel="stylesheet" href="{{ viewer_doc_css_path | safe}}">
<link rel="stylesheet" href="{{ viewer_highlighting_css_path |safe }}">
<style type="text/css">
/* Customize the viewer CSS here */
</style>
</head>
<body>
  <table class="fm">
    <tr>
    <th class="fmkey">{{'fm_title' | name}}:</th>
    <th class="fmval"><b>{{ fm.fm_title | default(value='') | to_html | safe }}</b></th>
  </tr>
  {% if fm.fm_subtitle %}
    <tr>
    <th class="fmkey">{{'fm_subtitle' | name}}:</th>
    <th class="fmval">{{ fm.fm_subtitle | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_keywords %}
    <tr>
    <th class="fmkeygrey">{{'fm_keywords' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_keywords | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
    <tr>
    <th class="fmkeygrey">{{'fm_author' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_author | default(value='') | to_html | safe }}</th>
  </tr>
    <tr>
    <th class="fmkeygrey">{{'fm_date' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_date | default(value='') | to_html | safe }}</th>
  </tr>
    <tr>
    <th class="fmkeygrey">{{'fm_lang' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_lang | default(value='') |to_html | safe }}</th>
  </tr>
  {% if fm.fm_languages %}
    <tr>
    <th class="fmkeygrey">{{'fm_languages' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_languages | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_scheme %}
    <tr>
    <th class="fmkeygrey">{{'fm_scheme' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_scheme | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_sort_tag %}
    <tr>
    <th class="fmkeygrey">{{'fm_sort_tag' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_sort_tag | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% set extra_fm = fm
     | remove(key='fm_title')
     | remove(key='fm_subtitle')
     | remove(key='fm_keywords')
     | remove(key='fm_author')
     | remove(key='fm_date')
     | remove(key='fm_lang')
     | remove(key='fm_languages')
     | remove(key='fm_scheme')
     | remove(key='fm_sort_tag')
   %}
  {% if extra_fm | length > 0 %}
    <tr><th colspan=2;\"/>&nbsp<th/</tr>
  {% endif %}
  {% for k, v in extra_fm %}
    <tr>
    <th class="fmkeygrey">{{ k | name }}:</th>
    <th class="fmvalgrey">{{ v | to_html | safe }}</th>
  </tr>
  {% endfor %}
  </table>
  <div class="doc-body">{{ doc.body | markup_to_html(extension=ext) | safe }}
  </div>
  <script>{{ viewer_doc_js | safe }}</script>
</body>
</html>
'''

### HTML template to render the viewer-error page.
viewer_error = """
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<title>Syntax error</title>
<style type="text/css">
@media (prefers-color-scheme: dark) {
  .note-error { color: #e5948d; }
  h1, h2, h3, h4, h5, h6 { color: #8db2e5; }
  a { color: #8de594; }
  body {
    background: #292929;
    color: #eeeeee;
  }
}
@media (prefers-color-scheme: light) {
  .note-error { color: #523626; }
  h1, h2, h3, h4, h5, h6 { color: #263292; }
  a { color: #316128; }
  body {
    background: #ffffff;
    color: #000000;
  }
}
pre { white-space: pre-wrap; }
h1, h2, h3, h4, h5, h6 { font-family:sans-serif; }
</style>
</head>
<body>
<h3>Syntax error</h3>
<p> in note file: <pre>{{ path }}</pre><p>
<div class=\"note-error\">
<hr>
<pre>{{ doc_error }}</pre>
<hr>
</div>
{{ doc_text | markup_to_html | safe }}
<script>{{ viewer_doc_js | safe }}</script>
</body>
</html>
"""

### A constant holding common CSS code, published by Tp-Note's viewer under the
### `/viewer_doc.css` path.
viewer_doc_css = """
/* Tp-Note's viewer document CSS */
@media (prefers-color-scheme: dark) {
  h1, h2, h3 { font-weight: normal; color: #fad566; }
  h4, h5, h6 { font-weight: bold; color: #fad566; }
  em { color: #cfba8b; }
  a { color: #72a59e; }
  body {
    background: #232323;
    color: #f3f2db;
  }
  table.fm { background-color: #303030; }
  th.fmkey{ color: #cfba8b; }
  th.fmval{ color: #99be70; }
  th.fmkeygrey{ color: #999999; }
  th.fmvalgrey{ color: #999999; }
}
@media (prefers-color-scheme: light) {
  h1, h2, h3, h4, h5, h6 { color: #263292; }
  em { color: #523626; }
  a { color: #316128; }
  body {
    background: #ffffff;
    color: #000000;
  }
  table.fm { background-color: #f3f2e4; }
  th.fmkey{ color: #444444; }
  th.fmval{ color: #316128; }
  th.fmkeygrey{ color: grey; }
  th.fmvalgrey{ color: grey; }
}
table.fm {
  font-weight: normal;
  margin-left: auto;
  margin-right: auto;
  padding: 4px;
  border:1px solid grey;
}
th.fmkey, th.fmkeygrey {
  font-weight: normal;
  padding-left:20px;
  padding-right:10px;
}
th.fmval, th.fmvalgrey {
  font-weight: normal;
  padding-left:10px;
  padding-right:20px;
}
th.fmkey{ text-align:right; vertical-align:top;}
th.fmval{
  text-align:left;
  font-family:sans-serif;
}
th.fmkeygrey{ text-align:right; vertical-align:top;}
th.fmvalgrey{ text-align:left; }
ul.fm {
  padding-left: 15px;
  margin: 0px;
}
li.fm {
  padding-bottom: 0px;
}
blockquote.fm {
  margin: 0px;
  padding-left: 15px
}
pre { white-space: pre-wrap; }
h1 { font-size: 150% }
h2 { font-size: 132% }
h3 { font-size: 115% }
h4, h5, h6 { font-size: 100% }
h1, h2, h3, h4, h5, h6 { font-family:sans-serif; }
"""

### Loads the viewer's code syntax highlighting theme. The theme is converted
### into additional CSS. Currently, available are:
### * `base16-ocean.dark`
### * `base16-eighties.dark`
### * `base16-mocha.dark`
### * `base16-ocean.light`
### * `InspiredGitHub`
### * `Solarized (dark)`
### * `Solarized (light)`
viewer_highlighting_theme = "Solarized (light)"

### When left empty, the CSS is calculated automatically from
### `viewer_highlighting_theme`. This is what you usually want. Anyway, if none
### of the above themes fits, you can provide a custom CSS here.
viewer_highlighting_css = ""

### HTML template used to render a note into HTML when the rendition is saved to
### disk. Similar to `tmpl_html.viewer` but does not inject JavaScript code.
exporter = '''
{%- set ext = fm.fm_file_ext | default(value=path|file_ext) -%}
<!DOCTYPE html>
<html lang="{{ fm.fm_lang | default(value='en') }}">
<head>
<meta charset="utf-8">
<title>{{ fm.fm_title }}</title>
<style type="text/css">
{{ exporter_doc_css | safe }}
{{ exporter_highlighting_css | safe }}
/* Customize the viewer CSS here */
</style>
</head>
<body>
  <table class="fm">
    <tr>
    <th class="fmkey">{{'fm_title' | name}}:</th>
    <th class="fmval"><b>{{ fm.fm_title | default(value='') | to_html | safe }}</b></th>
  </tr>
  {% if fm.fm_subtitle %}
    <tr>
    <th class="fmkey">{{'fm_subtitle' | name}}:</th>
    <th class="fmval">{{ fm.fm_subtitle | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_keywords %}
    <tr>
    <th class="fmkeygrey">{{'fm_keywords' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_keywords | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
    <tr>
    <th class="fmkeygrey">{{'fm_author' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_author | default(value='') | to_html | safe }}</th>
  </tr>
    <tr>
    <th class="fmkeygrey">{{'fm_date' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_date | default(value='') | to_html | safe }}</th>
  </tr>
    <tr>
    <th class="fmkeygrey">{{'fm_lang' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_lang | default(value='') | to_html | safe }}</th>
  </tr>
  {% if fm.fm_languages %}
    <tr>
    <th class="fmkeygrey">{{'fm_languages' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_languages | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_scheme %}
    <tr>
    <th class="fmkeygrey">{{'fm_scheme' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_scheme | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% if fm.fm_sort_tag %}
    <tr>
    <th class="fmkeygrey">{{'fm_sort_tag' | name}}:</th>
    <th class="fmvalgrey">{{ fm.fm_sort_tag | default(value='') | to_html | safe }}</th>
  </tr>
  {% endif %}
  {% set extra_fm = fm
     | remove(key='fm_title')
     | remove(key='fm_subtitle')
     | remove(key='fm_keywords')
     | remove(key='fm_author')
     | remove(key='fm_date')
     | remove(key='fm_lang')
     | remove(key='fm_languages')
     | remove(key='fm_scheme')
     | remove(key='fm_sort_tag')
   %}
  {% if extra_fm | length > 0 %}
    <tr><th colspan=2;\"/>&nbsp<th/</tr>
  {% endif %}
  {% for k, v in extra_fm %}
    <tr>
    <th class="fmkeygrey">{{ k | name }}:</th>
    <th class="fmvalgrey">{{ v | to_html | safe }}</th>
  </tr>
  {% endfor %}
  </table>
  <div class="doc-body">{{ doc.body | markup_to_html(extension=ext) | safe }}
  </div>
</body>
</html>
'''

### Loads the exporter's code syntax highlighting theme. The theme is converted
### into additional CSS. Currently, available are:
### * `base16-ocean.dark`
### * `base16-eighties.dark`
### * `base16-mocha.dark`
### * `base16-ocean.light`
### * `InspiredGitHub`
### * `Solarized (dark)`
### * `Solarized (light)`
exporter_highlighting_theme = "Solarized (light)"

### When left empty, the CSS is calculated automatically from
### `exporter_highlighting_theme`. This is what you usually want. Anyway, if
### none of the above themes fits, you can provide a custom CSS here.
exporter_highlighting_css = ""

### A constant holding common CSS code, inserted into exported HTML documents
### with the template variable `{{ exporter_doc.css }}`.
### [CSS Paged Media Module Level 3](https://www.w3.org/TR/css-page-3/)
exporter_doc_css = """
/* Tp-Note's exporter document CSS */
@page {
  @bottom-center {
    content: counter(page) "/" counter(pages);
  }
  size: A4 portrait;
}

.custom-options input[type=checkbox]{
  margin-left: 5px;
  margin-right: 10px;
  margin-bottom: 5px;
}
input:before{content:attr(value)}
select:before{content:attr(value)}
label {
  display: block;
}
input[type=checkbox] {
  background-clip: content-box;
  background-color: white;
  border: 1px solid;
  border-radius: 2px;
  display: inline-block;
  height: 0.5em;
  margin: 0.5em 0.5em 0 0.5em;
  padding: 2px;
  width: 0.5em;
}
input[type=checkbox][checked] {
  background-color: gray;
}

table.fm {
  font-weight: normal;
  margin-left: auto;
  margin-right: auto;
  padding: 4px;
  background-color: #f3f2e4;
  border:1px solid grey;
}
th.fmkey, th.fmkeygrey {
  font-weight: normal;
  padding-left:20px;
  padding-right:10px;
}
th.fmval, th.fmvalgrey {
  font-weight: normal;
  padding-left:10px;
  padding-right:20px;
}
th.fmkey{ color:#444444; text-align:right; vertical-align:top;}
th.fmval{
  color:#316128;
  text-align:left;
  font-family:sans-serif;
}
th.fmkeygrey{ color:grey; text-align:right; vertical-align:top;}
th.fmvalgrey{ color:grey; text-align:left; }
ul.fm {
  padding-left: 15px;
  margin: 0px;
}
li.fm {
  padding-bottom: 0px;
}
blockquote.fm {
  margin: 0px;
  padding-left: 15px
}
pre { white-space: pre-wrap; }
em { color: #523626; }
a { color: #316128; }
h1 { font-size: 150% }
h2 { font-size: 132% }
h3 { font-size: 115% }
h4, h5, h6 { font-size: 100% }
h1, h2, h3, h4, h5, h6 { color: #263292; font-family:sans-serif; }
"""