proton icon indicating copy to clipboard operation
proton copied to clipboard

Convert table to HTML

Open zhuxiaod opened this issue 8 months ago • 8 comments

Hello, I plan to use your framework, but before that, I would like to know something because my final rich text data needs to run across endpoints, so I need to convert rich text into HTML. And most importantly, I need to support tables. I would like to know if I can convert tables and rich text into HTML for my colleagues to use

zhuxiaod avatar Mar 01 '25 09:03 zhuxiaod

iOS provides an option to convert attributedText to HTML. However, to convert the tables in Proton to HTML, you will need custom code. It is possible but Proton does not provide any API to do that.

rajdeep avatar Mar 01 '25 10:03 rajdeep

是否可以给我一点思路,我想实现表格的自定义,以及html转表格

zhuxiaod avatar Mar 03 '25 03:03 zhuxiaod

I want to know why there is no "TableView" in the version I downloaded, but there is in the demo

zhuxiaod avatar Mar 12 '25 06:03 zhuxiaod

Table related code is here: https://github.com/rajdeep/proton/tree/main/Proton/Sources/Swift/Table.

rajdeep avatar Mar 12 '25 07:03 rajdeep

public struct AttachmentContentIdentifier {

public let openingID: NSAttributedString
public let closingID: NSAttributedString

/// Constructs separators for using in `getFullAttributedText(:)`
/// - Parameters:
///   - openingID: Used to identify start of attachment content
///   - closingID: Used to identify end of attachment content
init(openingID: NSAttributedString, closingID: NSAttributedString) {
    self.openingID = openingID
    self.closingID = closingID
}

}

Init is not an external method and cannot be called

zhuxiaod avatar Mar 14 '25 08:03 zhuxiaod

@zhuxiaod , thanks for highlighting. I have made it public in #361.

I am not sure how you intend to use AttachmentContentIdentifier for tables as it may be tricky to get info around table rows/cells. However, there is another concept in Proton that you can use to generate HTML from the Editor and Attachments.

Please have a look at EditorContentDecoding. There is a sample implementation using this concept and converting the content from Editor and Attachments to JSON. You can see that in JSONDecoder. You can build similar logic but instead of converting to JSON, convert the output to HTML format. That would be probably the easiest solution that I can think of.

rajdeep avatar Mar 16 '25 02:03 rajdeep

Thank you for your reply. I have encountered another issue, which is that my front-end colleague received an HTML message from the server with the following data:< p>Some text here

, I want to load the image onto EditorView, but if I use HTML decoding, when I want to export it again, the image will become a space. So I need to find a way to load it onto EditorView using NSTextAttachment. I may need to manage asynchrony, replace images, etc. This operation increases my workload. Is there a simpler method. Question: How to load HTML images onto editorView

zhuxiaod avatar Mar 17 '25 08:03 zhuxiaod

@zhuxiaod You can create an attachment and either set its image to the image that you have or create an image view and pass that to attachment. If your image is from a url, you'll need to get the data and create an image out of it.

Also note, while you can get data from url, and pass that directly to create an image, it may not be optimum for performance reasons.

rajdeep avatar Mar 23 '25 07:03 rajdeep