1 | /* |
2 | SPDX-FileCopyrightText: 2002 Dave Corrie <kde@davecorrie.com> |
3 | SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef KCOREADDONS_KTEXTTOHTML_H |
9 | #define KCOREADDONS_KTEXTTOHTML_H |
10 | |
11 | #include <kcoreaddons_export.h> |
12 | |
13 | #include <QString> |
14 | |
15 | /** |
16 | * @author Dave Corrie \<kde@davecorrie.com\> |
17 | */ |
18 | namespace KTextToHTML |
19 | { |
20 | /** |
21 | * @see Options |
22 | * @since 5.5.0 |
23 | */ |
24 | enum Option { |
25 | /** |
26 | * Preserve white-space formatting of the text |
27 | */ |
28 | PreserveSpaces = 1 << 1, |
29 | |
30 | /** |
31 | * Replace text emoticons smileys by emoticons images. |
32 | * |
33 | * @note |
34 | * This option works only when KEmoticons framework is available at runtime, |
35 | * and requires QGuiApplication, otherwise the flag is simply ignored. |
36 | */ |
37 | ReplaceSmileys = 1 << 2, |
38 | |
39 | /** |
40 | * Don't parse and replace any URLs. |
41 | */ |
42 | IgnoreUrls = 1 << 3, |
43 | |
44 | /** |
45 | * Interpret text highlighting markup, like *bold*, _underline_ and /italic/, |
46 | * and wrap them in corresponding HTML entities. |
47 | */ |
48 | HighlightText = 1 << 4, |
49 | |
50 | /** |
51 | * Replace phone numbers with tel: links. |
52 | * @since 5.56.0 |
53 | */ |
54 | ConvertPhoneNumbers = 1 << 5, |
55 | }; |
56 | /** |
57 | * Stores a combination of #Option values. |
58 | */ |
59 | Q_DECLARE_FLAGS(Options, Option) |
60 | Q_DECLARE_OPERATORS_FOR_FLAGS(Options) |
61 | |
62 | /** |
63 | * Converts plaintext into html. The following characters are converted |
64 | * to HTML entities: & " < >. Newlines are also preserved. |
65 | * |
66 | * @param plainText The text to be converted into HTML. |
67 | * @param options The options to use when processing @p plainText. |
68 | * @param maxUrlLen The maximum length of permitted URLs. The reason for |
69 | * this limit is that there may be possible security |
70 | * implications in handling URLs of unlimited length. |
71 | * @param maxAddressLen The maximum length of permitted email addresses. |
72 | * The reason for this limit is that there may be possible |
73 | * security implications in handling addresses of unlimited |
74 | * length. |
75 | * |
76 | * @return An HTML version of the text supplied in the 'plainText' |
77 | * parameter, suitable for inclusion in the BODY of an HTML document. |
78 | * |
79 | * @since 5.5.0 |
80 | */ |
81 | KCOREADDONS_EXPORT QString convertToHtml(const QString &plainText, const KTextToHTML::Options &options, int maxUrlLen = 4096, int maxAddressLen = 255); |
82 | |
83 | } |
84 | |
85 | #endif |
86 | |