{"id":13340075,"url":"https://github.com/Infomaniak/swift-rich-html-editor","last_synced_at":"2025-03-11T16:32:05.036Z","repository":{"id":231337970,"uuid":"781523400","full_name":"Infomaniak/swift-rich-html-editor","owner":"Infomaniak","description":"A WYSIWYG text editor written in Swift for iOS/macOS/visionOS. Available for SwiftUI, UIKit and AppKit. Based on HTML contenteditable. Used in the Infomaniak Mail application.","archived":false,"fork":false,"pushed_at":"2025-02-03T08:01:49.000Z","size":1879,"stargazers_count":57,"open_issues_count":2,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-11T05:24:41.286Z","etag":null,"topics":["appkit","editor","ios","macos","rich-text-editor","swiftui","uikit","visionos","wysiwyg"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/Infomaniak/swift-rich-html-editor/documentation/infomaniakrichhtmleditor","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Infomaniak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-03T14:44:20.000Z","updated_at":"2025-02-26T20:34:21.000Z","dependencies_parsed_at":"2024-04-16T09:29:23.161Z","dependency_job_id":"a6e0e7c2-228a-4dae-8009-c907aeed9259","html_url":"https://github.com/Infomaniak/swift-rich-html-editor","commit_stats":null,"previous_names":["infomaniak/ios-rich-html-editor","infomaniak/swift-rich-html-editor"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infomaniak%2Fswift-rich-html-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infomaniak%2Fswift-rich-html-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infomaniak%2Fswift-rich-html-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infomaniak%2Fswift-rich-html-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Infomaniak","download_url":"https://codeload.github.com/Infomaniak/swift-rich-html-editor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243070389,"owners_count":20231444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appkit","editor","ios","macos","rich-text-editor","swiftui","uikit","visionos","wysiwyg"],"created_at":"2024-07-29T19:22:07.458Z","updated_at":"2025-03-11T16:32:00.018Z","avatar_url":"https://github.com/Infomaniak.png","language":"Swift","funding_links":[],"categories":["Swift","ios"],"sub_categories":[],"readme":"# Infomaniak Rich HTML Editor\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FInfomaniak%2Fswift-rich-html-editor%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/Infomaniak/swift-rich-html-editor)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FInfomaniak%2Fswift-rich-html-editor%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/Infomaniak/swift-rich-html-editor)\n\nThe **Infomaniak Rich HTML Editor** is a powerful Swift package designed to provide a seamless WYSIWYG (What You See Is What You Get) text editing experience across iOS, macOS, and visionOS platforms. Leveraging the power of the `contenteditable` HTML attribute, this editor allows you to effortlessly edit HTML content.\n\nBuilt with **UIKit** and **AppKit** thanks to WebKit, it also includes a **SwiftUI** port, making it easy to integrate into modern Swift apps.\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            \u003cimg src=\"Assets/ios.webp\" alt=\"iOS sample app\" style=\"max-height: 250px; width: auto;\"\u003e\n        \u003c/td\u003e\n        \u003ctd\u003e\n            \u003cimg src=\"Assets/macos.webp\" alt=\"iOS sample app\" style=\"max-height: 250px; width: auto;\"\u003e\n        \u003c/td\u003e\n        \u003ctd\u003e\n            \u003cimg src=\"Assets/visionos.webp\" alt=\"iOS sample app\" style=\"max-height: 250px; width: auto;\"\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n## ✍️ About\n\n### Features\n\n- **HTML Content Editing**: Full support for viewing and editing HTML content directly.\n- **Wide range of commands**: Many commands are available to format text, from simple commands like bold to more advanced ones like link creation.\n- **Cross-Platform Support:** Compatible with iOS, macOS, and visionOS.\n- **SwiftUI API**: A dedicated port for SwiftUI, ensuring modern and declarative UI design compatibility.\n\n### Installation\n\nYou can install the package via Swift Package Manager. Add the following line to your Package.swift file:\n```swift\n.package(url: \"https://github.com/Infomaniak/swift-rich-html-editor.git\", from: \"1.0.0\")\n```\n\n### Usage\n\n#### UIKit and AppKit\n\nYou can create the editor view and then add it to the view hierarchy.\n```swift\nimport InfomaniakRichHTMLEditor\nimport UIKit\n\nlet editor = RichHTMLEditorView()\nview.addSubview(editor)\n```\n\nTo respond to editor's events, you can conform to `RichHTMLEditorViewDelegate`.\n\n#### SwiftUI\n\nThe SwiftUI view is called `RichHTMLEditor` and takes two arguments:\n- `html: Binding\u003cString\u003e` the HTML content of the editor\n- `textAttributes: TextAttributes` the objects that contains the current state selected text (or the text at the insertion point) and is responsible to update the style\n\n```swift\nimport InfomaniakRichHTMLEditor\nimport SwiftUI\n\nstruct ContentView: View {\n    @State private var html = \"\"\n    @StateObject private var textAttributes = TextAttributes()\n\n    var body: some View {\n        RichHTMLEditor(html: $html, textAttributes: textAttributes)\n    }\n}\n```\n\nThe object `TextAttributes` contains various attributes about the current style of the selected text. Theses properties are read-only and are automatically updated by the editor.\nTo update the style, you should call the corresponding functions such as `bold()`.\n\nMany modifiers are available to customize the editor and respond to editor's events.\nHere is a non-exhaustive list of modifiers:\n```swift\nRichHTMLEditor(html: $html, textAttributes: textAttributes)\n    .editorScrollable(true)\n    .editorInputAccessoryView(myToolbarView)\n    .editorCSS(\"h1 { foreground-color: red; }\")\n    .onEditorLoaded {\n        // Perform action when editor is loaded\n    }\n    .onCaretPositionChange { newPosition in\n        // Perform action when caret moves\n    }\n    .onJavaScriptFunctionFail { error, function in\n        // Perform action when an editor JavaScript function has failed\n    }\n    .introspectEditor { richEditorView in\n        // Perform action on the editor (UI|NS)View\n    }\n```\n\n### Customize the editor\n\nYou can customize the editor with CSS.\nTo target the editor, you should use the `#swift-rich-html-editor` selector.\n\nFor example:\n```css\n#swift-rich-html-editor {\n    padding: 16px;\n}\n```\n\n## 📖 Documentation\n\nPublic types are documented, and three sample projects are available to help you implement the editor.\n\n## 🔍 Sample Projects\n\nYou can find 3 sample projects in the [Examples](Examples) folder:\n- A [project built with UIKit](Examples/Example%20iOS/) for iOS\n- A [project built with AppKit](Examples/Example%20macOS/) for macOS\n- A [project built with SwiftUI](Examples/Example%20SwiftUI/) for iOS/macOS/visionOS\n\n## 📱 Apps using InfomaniakRichHTMLEditor\n\n\u003ca href=\"https://github.com/Infomaniak/ios-kMail\"\u003e\n    \u003cimg src=\"Assets/infomaniak-mail.webp\" style=\"max-height: 300px; width: auto;\" alt=\"Find App\"\u003e\n\u003c/a\u003e\n\n[Infomaniak Mail](https://github.com/Infomaniak/ios-kMail) allows you to manage your Infomaniak addresses in a completely secure environment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInfomaniak%2Fswift-rich-html-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FInfomaniak%2Fswift-rich-html-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FInfomaniak%2Fswift-rich-html-editor/lists"}