Skip to content

Commit 554378b

Browse files
authored
feat: edit an HTML email as a plain text (#61)
It does minimal processing like `\n` → `<br>`, `<` → `&lt;`, `>` → `&gt;` and so on. Closes #6 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allows editing HTML emails as plain text. HTML emails are now converted to plain text before being sent to the editor, and changes are converted back to HTML on write. A new "Edit HTML as-is" option (default off) keeps the previous behavior. Closes #6. **Migration** - Minimum supported Thunderbird version is now 140 (was 128) since the conversion relies on `messengerUtilities.convertToPlainText`; older versions must upgrade. **Bug Fixes** - The compose body is now read with `innerText` instead of `textContent`, so `<br>` tags become actual newlines in the editor. <sup>Written for commit bb432ca. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/exteditor/ghostbird/pull/61?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
2 parents 155dc03 + bb432ca commit 554378b

18 files changed

Lines changed: 272 additions & 32 deletions

File tree

‎.web-ext-config.example.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See: https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/#use-a-custom-profile
44
export default {
55
run: {
6-
// You can use flatpak by specifying "flatpak:org.mozilla.Thunderbird"
6+
// You can use flatpak by specifying "flatpak:org.mozilla.thunderbird_esr"
77
firefox: "/usr/bin/thunderbird",
88
firefoxProfile: import.meta.dirname + "/.cache/thunderbird-testing-profile/",
99
profileCreateIfMissing: true,

‎ext/options.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ label {
5959
&[for="ignoreEmptyBodyUpdates"]::before {
6060
content: "__MSG_options_ignore_empty_body_updates__";
6161
}
62+
&[for="editHtmlAsIs"]::before {
63+
content: "__MSG_options_edit_html_as_is__";
64+
}
6265
}
6366
.progress {
6467
&.saved::before {

‎ext/options.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
type="checkbox"
3838
>
3939
</label>
40+
<label for="editHtmlAsIs"></label>
41+
<label>
42+
<input id="editHtmlAsIs" name="editHtmlAsIs" type="checkbox">
43+
</label>
4044
<span></span>
4145
<span
4246
><input type="reset"></span

‎locales.toml‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,37 @@ vi = "Bỏ qua cập nhật nội dung trống (cách khắc phục tạm thời
283283
zh = "忽略空正文更新(临时解决方法)"
284284
zh-tw = "忽略空白內文更新(臨時解決方法)"
285285

286+
[options_edit_html_as_is]
287+
# Description of the option item for editing HTML emails as-is.
288+
ar = "تعديل HTML كما هو"
289+
be = "Рэдагаваць HTML як ёсць"
290+
ca = "Edita l'HTML tal qual"
291+
cs = "Upravit HTML tak, jak je"
292+
de = "HTML unverändert bearbeiten"
293+
el = "Επεξεργασία HTML ως έχει"
294+
en = "Edit HTML as-is"
295+
es = "Editar HTML tal cual"
296+
fi = "Muokkaa HTML:ää sellaisenaan"
297+
fr = "Éditer l'HTML tel quel"
298+
hu = "HTML szerkesztése eredeti formájában"
299+
id = "Edit HTML apa adanya"
300+
it = "Modifica HTML così com'è"
301+
ja = "HTMLをそのまま編集する"
302+
ko = "HTML 있는 그대로 편집"
303+
nl = "HTML bewerken zoals het is"
304+
pl = "Edytuj HTML tak, jak jest"
305+
pt = "Editar HTML tal como está"
306+
pt-br = "Editar HTML como está"
307+
ro = "Editați HTML-ul așa cum este"
308+
ru = "Редактировать HTML как есть"
309+
sk = "Upraviť HTML tak, ako je"
310+
th = "แก้ไข HTML ตามที่เป็นอยู่"
311+
tr = "HTML'yi olduğu gibi düzenle"
312+
uk = "Редагувати HTML як є"
313+
vi = "Chỉnh sửa HTML như nguyên trạng"
314+
zh = "按原样编辑 HTML"
315+
zh-tw = "按原樣編輯 HTML"
316+
286317
[options_saved]
287318
# Message shown when the options has been saved successfully.
288319
ar = "تم الحفظ"

‎manifest_template.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"browser_specific_settings": {
1212
"gecko": {
1313
"id": "@ghostbird.exteditor.addons.thunderbird.net",
14-
"strict_min_version": "128.0",
14+
"strict_min_version": "140.0",
1515
"data_collection_permissions": {
1616
"required": [
1717
"none"

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "module",
1111
"packageManager": "[email protected]",
1212
"engines": {
13-
"thunderbird": ">= 128"
13+
"thunderbird": ">= 140"
1414
},
1515
"homepage": "https://exteditor.github.io/ghostbird/",
1616
"bugs": "https://github.com/exteditor/ghostbird/issues/",
@@ -80,6 +80,7 @@
8080
"barrelsby": "^2.8.1",
8181
"git-describe": "^4.1.1",
8282
"glob": "^10",
83+
"html-entities": "^2.6.0",
8384
"jsdom": "^27.0.1",
8485
"rolldown": "^1.2.14",
8586
"toposort-class": "^1.0.1",

‎src/app-compose/body_editor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class BodyEditor {
77
) {}
88

99
getBody(isPlainText: boolean): string {
10-
return (isPlainText ? this.body.textContent : this.body.innerHTML) ?? ""
10+
return (isPlainText ? this.body.innerText : this.body.innerHTML) ?? ""
1111
}
1212

1313
applyEdit(body: string, isPlainText: boolean): void {

‎src/ghosttext-adaptor/api.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export type StoredOptions = {
8585
enableNotifications: boolean
8686
/** Ignore all empty body updates sent by the server if true */
8787
ignoreEmptyBodyUpdates: boolean
88+
/** Edit HTML emails as-is */
89+
editHtmlAsIs: boolean
8890
}
8991

9092
/** Manages access to options */
@@ -93,6 +95,14 @@ export interface IStoredOptionsLoader {
9395
load(): Promise<StoredOptions>
9496
}
9597

98+
/** Utilities to convert between HTML and plain text */
99+
export interface ITextUtil {
100+
/** Converts an HTML body to plain text */
101+
convertToPlainText(body: string): Promise<string>
102+
/** Encodes text so it is safe to embed in HTML */
103+
encode(text: string): string
104+
}
105+
96106
/** Message sent from the background script to the compose window */
97107
export type BackgroundMessage = { body: string } | { isPlainText: boolean }
98108

‎src/ghosttext-adaptor/client_options_loader.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const DEFAULT_STORED_OPTIONS: StoredOptions = {
55
serverPort: 4001,
66
enableNotifications: true,
77
ignoreEmptyBodyUpdates: false,
8+
editHtmlAsIs: false,
89
} as const
910

1011
export class ClientOptionsLoader implements IClientOptionsLoader {
@@ -16,7 +17,8 @@ export class ClientOptionsLoader implements IClientOptionsLoader {
1617
) {}
1718

1819
async load(): Promise<ClientOptions> {
19-
let { serverPort, enableNotifications, ignoreEmptyBodyUpdates } = await this.storedOptionsLoader.load()
20+
let { serverPort, enableNotifications, ignoreEmptyBodyUpdates, editHtmlAsIs } =
21+
await this.storedOptionsLoader.load()
2022
const extensionId = this.manifestInfo.getId()
2123
let serverUrl = new URL(`http://localhost:${serverPort}/`)
2224
let { host } = new URL(`extension://${extensionId}.localhost`)
@@ -26,6 +28,7 @@ export class ClientOptionsLoader implements IClientOptionsLoader {
2628
clientHostName: host,
2729
enableNotifications,
2830
ignoreEmptyBodyUpdates,
31+
editHtmlAsIs,
2932
}
3033
}
3134
}
@@ -41,6 +44,7 @@ if (import.meta.vitest) {
4144
serverPort: 1234,
4245
enableNotifications: true,
4346
ignoreEmptyBodyUpdates: true,
47+
editHtmlAsIs: true,
4448
}),
4549
} satisfies IStoredOptionsLoader
4650
const manifestInfo = {
@@ -53,6 +57,7 @@ if (import.meta.vitest) {
5357
clientHostName: "test.extension.localhost",
5458
enableNotifications: true,
5559
ignoreEmptyBodyUpdates: true,
60+
editHtmlAsIs: true,
5661
})
5762
})
5863
})

0 commit comments

Comments
 (0)