proton
proton copied to clipboard
Convert table to HTML
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
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.
是否可以给我一点思路,我想实现表格的自定义,以及html转表格
I want to know why there is no "TableView" in the version I downloaded, but there is in the demo
Table related code is here: https://github.com/rajdeep/proton/tree/main/Proton/Sources/Swift/Table.
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 , 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.
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
@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.