Mercurial > libervia-backend
annotate libervia/frontends/tools/composition.py @ 4136:72b95cdc3432
plugin XEP-0363: fix headers setting
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Nov 2023 13:55:34 +0100 |
parents | 26b7ed2817da |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 """ |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
1766 | 6 Copyright (C) 2013-2016 Adrien Cossa <souliane@mailoo.org> |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 """ |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 # Map the messages recipient types to their properties. |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 RECIPIENT_TYPES = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
24 "To": {"desc": "Direct recipients", "optional": False}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
25 "Cc": {"desc": "Carbon copies", "optional": True}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
26 "Bcc": {"desc": "Blind carbon copies", "optional": True}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
27 } |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 # Rich text buttons icons and descriptions |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 RICH_BUTTONS = { |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 "bold": {"tip": "Bold", "icon": "media/icons/dokuwiki/toolbar/16/bold.png"}, |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 "italic": {"tip": "Italic", "icon": "media/icons/dokuwiki/toolbar/16/italic.png"}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
33 "underline": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 "tip": "Underline", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 "icon": "media/icons/dokuwiki/toolbar/16/underline.png", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 }, |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 "code": {"tip": "Code", "icon": "media/icons/dokuwiki/toolbar/16/mono.png"}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
38 "strikethrough": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 "tip": "Strikethrough", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 "icon": "media/icons/dokuwiki/toolbar/16/strike.png", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 }, |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 "heading": {"tip": "Heading", "icon": "media/icons/dokuwiki/toolbar/16/hequal.png"}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 "numberedlist": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 "tip": "Numbered List", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 "icon": "media/icons/dokuwiki/toolbar/16/ol.png", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 }, |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 "list": {"tip": "List", "icon": "media/icons/dokuwiki/toolbar/16/ul.png"}, |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 "link": {"tip": "Link", "icon": "media/icons/dokuwiki/toolbar/16/linkextern.png"}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 "horizontalrule": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 "tip": "Horizontal rule", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 "icon": "media/icons/dokuwiki/toolbar/16/hr.png", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 "image": {"tip": "Image", "icon": "media/icons/dokuwiki/toolbar/16/image.png"}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 } |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 |
835
c00d90bce252
tools: composition RICH_FORMATS constant has been renamed to RICH_SYNTAXES
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
56 # Define here your rich text syntaxes, the key must match the ones used in button. |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 # Tupples values must have 3 elements : prefix to the selection or cursor |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 # position, sample text to write if the marker is not applied on a selection, |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 # suffix to the selection or cursor position. |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 # FIXME: must not be hard-coded like this |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 RICH_SYNTAXES = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 "markdown": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 "bold": ("**", "bold", "**"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 "italic": ("*", "italic", "*"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 "code": ("`", "code", "`"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "heading": ("\n# ", "Heading 1", "\n## Heading 2\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "link": ("[desc](", "link", ")"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 "list": ("\n* ", "item", "\n + subitem\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 "horizontalrule": ("\n***\n", "", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 "image": ("![desc](", "path", ")"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 "bbcode": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 "bold": ("[b]", "bold", "[/b]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 "italic": ("[i]", "italic", "[/i]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 "underline": ("[u]", "underline", "[/u]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 "code": ("[code]", "code", "[/code]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 "strikethrough": ("[s]", "strikethrough", "[/s]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 "link": ("[url=", "link", "]desc[/url]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 "list": ("\n[list] [*]", "item 1", " [*]item 2 [/list]\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 "image": ('[img alt="desc\]', "path", "[/img]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 "dokuwiki": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 "bold": ("**", "bold", "**"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 "italic": ("//", "italic", "//"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 "underline": ("__", "underline", "__"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 "code": ("<code>", "code", "</code>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 "strikethrough": ("<del>", "strikethrough", "</del>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 "heading": ("\n==== ", "Heading 1", " ====\n=== Heading 2 ===\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 "link": ("[[", "link", "|desc]]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 "list": ("\n * ", "item\n", "\n * subitem\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 "horizontalrule": ("\n----\n", "", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 "image": ("{{", "path", " |desc}}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 "XHTML": { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 "bold": ("<b>", "bold", "</b>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 "italic": ("<i>", "italic", "</i>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 "underline": ("<u>", "underline", "</u>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 "code": ("<pre>", "code", "</pre>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 "strikethrough": ("<s>", "strikethrough", "</s>"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 "heading": ("\n<h3>", "Heading 1", "</h3>\n<h4>Heading 2</h4>\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 "link": ('<a href="', "link", '">desc</a>'), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 "list": ("\n<ul><li>", "item 1", "</li><li>item 2</li></ul>\n"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 "horizontalrule": ("\n<hr/>\n", "", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 "image": ('<img src="', "path", '" alt="desc"/>'), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 } |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
840
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
108 # Define here the commands that are supported by the WYSIWYG edition. |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
109 # Keys must be the same than the ones used in RICH_SYNTAXES["XHTML"]. |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
110 # Values will be used to call execCommand(cmd, False, arg), they can be: |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
111 # - a string used for cmd and arg is assumed empty |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
112 # - a tuple (cmd, prompt, arg) with cmd the name of the command, |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
113 # prompt the text to display for asking a user input and arg is the |
58b4568ed4f2
frontends: add COMMANDS constant for Wysiwyg edition + add "image" button info for the syntaxes
souliane <souliane@mailoo.org>
parents:
835
diff
changeset
|
114 # value to use directly without asking the user if prompt is empty. |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 COMMANDS = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 "bold": "bold", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 "italic": "italic", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 "underline": "underline", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 "code": ("formatBlock", "", "pre"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 "strikethrough": "strikeThrough", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 "heading": ("heading", "Please specify the heading level (h1, h2, h3...)", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 "link": ("createLink", "Please specify an URL", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 "list": "insertUnorderedList", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 "horizontalrule": "insertHorizontalRule", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 "image": ("insertImage", "Please specify an image path", ""), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 } |
691
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 # These values should be equal to the ones in plugin_misc_text_syntaxes |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 # FIXME: should the plugin import them from here to avoid duplicity? Importing |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 # the plugin's values from here is not possible because Libervia would fail. |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 PARAM_KEY_COMPOSITION = "Composition" |
481e0f8ae47c
tools frontend: moved here from Libervia some definitions for message composition
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 PARAM_NAME_SYNTAX = "Syntax" |