ZhgChgLi / ZMarkupParser

ZMarkupParser is a pure-Swift library that helps you convert HTML strings into NSAttributedString with customized styles and tags.
https://link.zhgchg.li/
MIT License
311 stars 24 forks source link

Add better table rendering support #38

Closed charrondev closed 7 months ago

charrondev commented 11 months ago

I've noticed that table rendering is relatively lackluster.

I'm willing to take a crack at it in the next few months but wanted to open this issue to start getting some ideas down.

Current Limitations

Currently the table implementation creates tries to even things out by making use of whitespace characters to even the columns. This has numerous shortcomings, most notably that

Implementation Ideas

My goal would be something like the following:

To actually accomplish this it will certainly need to be some type of NSTextAttachment, and ZNSTextAttachment seems like a good enough inspiration of something with dynamic, initially unknown height to calculate and render.

zhgchgli0718 commented 10 months ago

The issue of handling tables is indeed quite complex because NSAttributedString only provides basic typesetting functionality.

Achieving a complete table implementation, including scaling, can be very challenging.

Currently, the project only has a simple implementation for tables.

One possible approach could be obtaining the screen size and converting the table content into an image to be inserted into NSAttributedString.

zhgchgli0718 commented 9 months ago

ref: may use ascii-table instead: https://ozh.github.io/ascii-tables/

charrondev commented 7 months ago

I've abandonded my use of Swift altogether for the area that I need to view HTML content and am instead just using a webview.

In addition to having much greater support for all manor of HTML, I'm also finding it's rendering on large amounts of text far faster than the equivalent NSAttributedStrings. I wasn't expecting that at all.