comparison libervia/frontends/tools/composition.py @ 4074:26b7ed2817da

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