Skip to content

Optimize latex rendering logic.#10

Merged
GIKICoder merged 9 commits intomainfrom
dev_richtext
Jul 2, 2025
Merged

Optimize latex rendering logic.#10
GIKICoder merged 9 commits intomainfrom
dev_richtext

Conversation

@GIKICoder
Copy link
Copy Markdown
Owner

No description provided.

@GIKICoder GIKICoder requested a review from Copilot July 2, 2025 17:56
@GIKICoder GIKICoder merged commit f88968b into main Jul 2, 2025
@GIKICoder GIKICoder deleted the dev_richtext branch July 2, 2025 17:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR centralizes LaTeX rendering by introducing a smart renderer, removes legacy Macaw-based SVG code and dependencies, and renames the table renderer for clarity.

  • Swap direct MathImage usage for GMarkLaTexRender.renderLatexSmart, with fallback on failure.
  • Eliminate Macaw imports and deprecate SVG POC classes; update package dependencies.
  • Rename GMarkTableRender to GMarkTableLayout and update all references.

Reviewed Changes

Copilot reviewed 20 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Sources/Visitor/GMarkupVisitor.swift Use renderLatexSmart with fallback instead of MathImage
Sources/Render/RenderCells/GMarkLatexCellPOC.swift Comment out Macaw-based SVG POC code
Sources/Render/RenderCells/GMarkLatexCell.swift Remove Macaw import and SVG view handling
Sources/Render/GMarkdownMultiViewPOC.swift Change preload to include all chunks
Sources/Render/GMarkdownMultiView.swift Only check latexImage when choosing LaTeX cell
Sources/Generator/Table/GMarkTableLayout.swift Rename class from GMarkTableRender to GMarkTableLayout
Sources/Generator/MarkupHandler/TableMarkupHandler.swift Use GMarkTableLayout in handler
Sources/Generator/MarkupHandler/LaTexMarkupHandler.swift Refactor LaTeX handling to use smart renderer
Sources/Generator/LaTex/GMarkSVGRender.swift Add new low-level SVG rendering implementation
Sources/Generator/LaTex/GMarkLaTexToSVGConverter.swift Rename SVG converter class and adjust options
Sources/Generator/LaTex/GMarkLaTexRender.swift Add GMarkLaTexRender smart LaTeX renderer
Sources/Generator/GMarkChunkGenerator.swift Remove Macaw import
Sources/Generator/GMarkChunk.swift Remove latexNode and Macaw references
Package.swift Drop Macaw package dependency
Examples/GMarkdownExample/.../md/markdownLatex Add LaTeX reference example file
Examples/GMarkdownExample/GMarkdownExample/RealTimeRenderController.swift Include markdownLatex and adjust maxContainerWidth
Examples/GMarkdownExample/GMarkdownExample/MarkdownRenderController.swift Include markdownLatex and adjust maxContainerWidth
Examples/GMarkdownExample/GMarkdownExample/Assets.xcassets/AppIcon.appiconset/Contents.json Overhaul app icon JSON
Examples/GMarkdownExample/GMarkdownExample.xcodeproj/Package.resolved Remove Macaw and SWXMLHash from resolved packages
Examples/GMarkdownExample/GMarkdownExample.xcodeproj/project.pbxproj Register markdownLatex resource in project file


return result
} else {
print("LaTeX 渲染失败: \(result.error?.localizedDescription ?? "未知错误")")
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider replacing this print statement with a structured logging framework or a debug-only log to avoid polluting console output in production.

Suggested change
print("LaTeX 渲染失败: \(result.error?.localizedDescription ?? "未知错误")")
os_log("LaTeX 渲染失败: %{public}@", log: .default, type: .error, result.error?.localizedDescription ?? "未知错误")

Copilot uses AI. Check for mistakes.
import MPITextKit
import Macaw

/*
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Rather than commenting out large blocks of code, consider removing this POC file or moving it behind a feature flag to reduce code clutter.

Suggested change
/*
#if ENABLE_GMARK_LATEX_CELL_POC

Copilot uses AI. Check for mistakes.

for i in start...end {
if let chunk = chunks[safe: i], chunk.latexNode != nil {
if let chunk = chunks[safe: i] {
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The preload logic now collects all chunks instead of only LaTeX ones, which may lead to unnecessary work; consider filtering by chunk.latexImage != nil again.

Suggested change
if let chunk = chunks[safe: i] {
if let chunk = chunks[safe: i], chunk.latexImage != nil {

Copilot uses AI. Check for mistakes.
DispatchQueue.global(qos: .userInitiated).async {
let style = MarkdownStyle.defaultStyle()
var style = MarkdownStyle.defaultStyle()
style.maxContainerWidth = UIScreen.main.bounds.size.width - 32
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This calculation is duplicated in multiple controllers; consider extracting common style configuration into a helper.

Copilot uses AI. Check for mistakes.
DispatchQueue.global(qos: .userInitiated).async {
let style = MarkdownStyle.defaultStyle()
var style = MarkdownStyle.defaultStyle()
style.maxContainerWidth = UIScreen.main.bounds.size.width - 32
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Duplicate width adjustment seen here and in RealTimeRenderController; factor into shared utility to avoid drift.

Suggested change
style.maxContainerWidth = UIScreen.main.bounds.size.width - 32
style.maxContainerWidth = calculateMaxContainerWidth(padding: 32)

Copilot uses AI. Check for mistakes.
"version" : 1
}
}
{"images":[{"size":"20x20","idiom":"iphone","filename":"iPhoneNotification_20pt@2x.png","scale":"2x"},{"size":"20x20","idiom":"iphone","filename":"iPhoneNotification_20pt@3x.png","scale":"3x"},{"size":"29x29","idiom":"iphone","filename":"iPhoneSpootlight5_29pt@2x.png","scale":"2x"},{"size":"29x29","idiom":"iphone","filename":"iPhoneSpootlight5_29pt@3x.png","scale":"3x"},{"size":"40x40","idiom":"iphone","filename":"iPhoneSpootlight7_40pt@2x.png","scale":"2x"},{"size":"40x40","idiom":"iphone","filename":"iPhoneSpootlight7_40pt@3x.png","scale":"3x"},{"size":"60x60","idiom":"iphone","filename":"iPhoneApp_60pt@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"iPhoneApp_60pt@3x.png","scale":"3x"},{"size":"1024x1024","idiom":"ios-marketing","filename":"store_1024pt.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"iPadNotification_20pt.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"iPadNotification_20pt@2x.png","scale":"2x"},{"size":"29x29","idiom":"ipad","filename":"iPadSpootlight5_29pt.png","scale":"1x"},{"size":"29x29","idiom":"ipad","filename":"iPadSpootlight5_29pt@2x.png","scale":"2x"},{"size":"40x40","idiom":"ipad","filename":"iPadSpootlight7_40pt.png","scale":"1x"},{"size":"40x40","idiom":"ipad","filename":"iPadSpootlight7_40pt@2x.png","scale":"2x"},{"size":"76x76","idiom":"ipad","filename":"iPadApp_76pt.png","scale":"1x"},{"size":"76x76","idiom":"ipad","filename":"iPadApp_76pt@2x.png","scale":"2x"},{"size":"83.5x83.5","idiom":"ipad","filename":"iPadProApp_83.5pt@2x.png","scale":"2x"}],"info":{"version":1,"author":"xcode"}} No newline at end of file
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asset name "iPhoneSpootlight5" appears to have a typo; you may want to correct it to "iPhoneSpotlight5".

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants