mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
* chore(app): vendor react-native-enriched-markdown with the Paseo patch applied Copy react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 (upstream software-mansion/enriched-markdown 766fc0e67) into packages/react-native-enriched-markdown, with patches/react-native-enriched-markdown+1.2.0-nightly-20261014-766fc0e67.patch applied. Nothing else changes in this commit; the package is not a workspace yet. Reproduce: npm pack react-native-enriched-markdown@1.2.0-nightly-20261014-766fc0e67 tar xzf react-native-enriched-markdown-*.tgz mkdir -p t/node_modules && mv package t/node_modules/react-native-enriched-markdown (cd t && git init -q && git apply ../patches/react-native-enriched-markdown+*.patch) diff -r t/node_modules/react-native-enriched-markdown packages/react-native-enriched-markdown The diff is empty. * chore(app): consume react-native-enriched-markdown from its workspace Make packages/react-native-enriched-markdown a private workspace and point the app at it, then remove the patch-package patch it replaces. - package.json: private, version follows the root like every workspace, only the postinstall script that downloads tree-sitter grammars. Upstream's devDependencies would install a second react-native, so they are gone. - The package keeps its name, so autolinking, the Gradle project :react-native-enriched-markdown, the CocoaPods spec and imports are unchanged. - Lockfile: drop the nested registry copy under packages/app/node_modules; npm links node_modules/react-native-enriched-markdown to the workspace. - Formatting, lint and knip skip the vendored code. CI routes changes to it through the app and browser suites. - The codegen test checks the vendored package's generated props. - docs/markdown-renderer.md describes the fork and how to edit it. * fix(app): keep numbered sub-list markers off their text on Android From #9964, moved from the package patch into the vendored package. On Android, a numbered list nested in a bulleted item drew "1." over the first letters of each item. A nested item's text indent summed the root list's narrow bullet column with a fixed marginLeft, while its marker was right-aligned to its own wider "99." column, so the number landed on the text. iOS already indents from the item's own column. Backport the Android hunks of upstream enriched-markdown #1015 (size the number column to the widest marker) and #1023 (nested items start their text from their own marker column). test:android now also runs the backported ListRenderingTest and TaskListInteractionTest suites. docs/markdown-renderer.md lists the fork's backports, this one and #924, which the removed postinstall comment used to track. The vendored tree equals the #9964 patch applied to the pristine package. * fix(app): keep Android assistant replies inside their turns From #10380, moved from the package patch into the vendored package. On Android, an assistant reply with blockquotes nested inside a list could overlap its "Worked for ..." footer and the next user message: the displayed text and the layout measurement applied spans in different orders, and the list-wide line height inflated the blockquote spacers when it ran after them. Use the same span order for Android Markdown measurement and display. Apply list line height before blockquote spacers so nested quotes keep their configured padding and the reply fits above the turn footer. test:android now also runs ListBlockquoteMeasurementTest. Applied on top of #9964; the two changes share only ListRenderer.kt, where #10380's import and line-height call sit beside #9964's marker width code. Every other file equals the #10380 patch applied to the pristine package. * chore(app): match the vendored Markdown web block renderer source to its build The package patch changed lib/module/web/renderers/BlockRenderers.js (the renderers.codeBlock override and the zoom-in cursor on images) but not src/web/renderers/BlockRenderers.tsx. The app runs lib, so behavior does not change. Port both changes into src so src stays the source of lib.
142 lines
6.5 KiB
Objective-C
142 lines
6.5 KiB
Objective-C
#import "ENRMLatexErrorReporting.h"
|
|
#import "ENRMUIKit.h"
|
|
#import <Foundation/Foundation.h>
|
|
|
|
typedef NS_ENUM(NSInteger, BlockType) {
|
|
BlockTypeNone,
|
|
BlockTypeParagraph,
|
|
BlockTypeHeading,
|
|
BlockTypeBlockquote,
|
|
BlockTypeUnorderedList,
|
|
BlockTypeOrderedList,
|
|
BlockTypeCodeBlock
|
|
};
|
|
|
|
/// YES when the enclosing block re-stamps its own line height over paragraph content and applies the
|
|
/// matching baseline offset itself, so a paragraph nested inside it must not apply its own (the outer
|
|
/// block's line height wins, and applyBaselineOffset skips ranges that already carry an offset).
|
|
/// TODO: loose list items have the same shape (ParagraphRenderer runs, then the list re-stamps its
|
|
/// line height); add BlockTypeUnorderedList/BlockTypeOrderedList here once lists own their offset too.
|
|
static inline BOOL ENRMBlockTypeReappliesBaselineOffset(BlockType type)
|
|
{
|
|
return type == BlockTypeBlockquote;
|
|
}
|
|
|
|
typedef NS_ENUM(NSInteger, ListType) { ListTypeUnordered, ListTypeOrdered };
|
|
|
|
@interface BlockStyle : NSObject
|
|
@property (nonatomic, assign) CGFloat fontSize;
|
|
@property (nonatomic, strong) NSString *fontFamily;
|
|
@property (nonatomic, strong) NSString *fontWeight;
|
|
@property (nonatomic, strong) RCTUIColor *color;
|
|
@property (nonatomic, strong) UIFont *cachedFont;
|
|
@property (nonatomic, strong) NSDictionary *cachedTextAttributes;
|
|
@end
|
|
|
|
@interface RenderContext : NSObject
|
|
@property (nonatomic, strong) NSMutableArray<NSValue *> *linkRanges;
|
|
@property (nonatomic, strong) NSMutableArray<NSString *> *linkURLs;
|
|
@property (nonatomic, strong) NSMutableArray<NSValue *> *headingRanges;
|
|
@property (nonatomic, strong) NSMutableArray<NSNumber *> *headingLevels;
|
|
@property (nonatomic, strong) NSMutableArray<NSValue *> *imageRanges;
|
|
@property (nonatomic, strong) NSMutableArray<NSString *> *imageAltTexts;
|
|
@property (nonatomic, strong) NSMutableArray<NSString *> *imageURLs;
|
|
@property (nonatomic, strong) NSMutableArray<NSValue *> *listItemRanges;
|
|
@property (nonatomic, strong) NSMutableArray<NSNumber *> *listItemPositions; // Position in parent list (1, 2, 3...)
|
|
@property (nonatomic, strong) NSMutableArray<NSNumber *> *listItemDepths; // Nesting depth (1 = top level, 2+ = nested)
|
|
@property (nonatomic, strong) NSMutableArray<NSNumber *> *listItemOrdered; // YES = ordered, NO = unordered (bullet)
|
|
@property (nonatomic, assign) BlockType currentBlockType;
|
|
@property (nonatomic, strong) BlockStyle *currentBlockStyle;
|
|
@property (nonatomic, assign) NSInteger currentHeadingLevel;
|
|
@property (nonatomic, assign) NSInteger blockquoteDepth;
|
|
@property (nonatomic, assign) NSInteger listDepth;
|
|
@property (nonatomic, assign) ListType listType;
|
|
@property (nonatomic, assign) NSInteger listItemNumber;
|
|
@property (nonatomic, assign) CGFloat accumulatedIndent;
|
|
@property (nonatomic, assign) BOOL allowFontScaling;
|
|
@property (nonatomic, assign) CGFloat maxFontSizeMultiplier;
|
|
@property (nonatomic, assign) NSInteger taskItemCount;
|
|
@property (nonatomic, strong) NSMutableArray<id<ENRMLatexErrorReporting>> *mathReporters;
|
|
|
|
- (instancetype)init;
|
|
- (void)reset;
|
|
|
|
- (UIFont *)cachedFontForSize:(CGFloat)fontSize family:(NSString *)fontFamily weight:(NSString *)fontWeight;
|
|
- (NSMutableParagraphStyle *)spacerStyleWithHeight:(CGFloat)height spacing:(CGFloat)spacing;
|
|
- (NSMutableParagraphStyle *)blockSpacerStyleWithMargin:(CGFloat)margin;
|
|
- (void)registerLinkRange:(NSRange)range url:(NSString *)url;
|
|
|
|
- (void)applyLinkAttributesToString:(NSMutableAttributedString *)attributedString;
|
|
- (void)applyImageAttributesToString:(NSMutableAttributedString *)attributedString;
|
|
- (void)registerHeadingRange:(NSRange)range level:(NSInteger)level text:(NSString *)text;
|
|
- (void)registerImageRange:(NSRange)range altText:(NSString *)altText url:(NSString *)url;
|
|
- (void)registerListItemRange:(NSRange)range
|
|
position:(NSInteger)position
|
|
depth:(NSInteger)depth
|
|
isOrdered:(BOOL)isOrdered;
|
|
- (void)setBlockStyle:(BlockType)type
|
|
fontSize:(CGFloat)fontSize
|
|
fontFamily:(NSString *)fontFamily
|
|
fontWeight:(NSString *)fontWeight
|
|
color:(RCTUIColor *)color;
|
|
- (void)setBlockStyle:(BlockType)type
|
|
fontSize:(CGFloat)fontSize
|
|
fontFamily:(NSString *)fontFamily
|
|
fontWeight:(NSString *)fontWeight
|
|
color:(RCTUIColor *)color
|
|
headingLevel:(NSInteger)headingLevel;
|
|
- (void)setBlockStyle:(BlockType)type
|
|
font:(UIFont *)font
|
|
color:(RCTUIColor *)color
|
|
headingLevel:(NSInteger)headingLevel;
|
|
- (BlockStyle *)getBlockStyle;
|
|
- (NSDictionary *)getTextAttributes;
|
|
- (void)clearBlockStyle;
|
|
|
|
/**
|
|
* Captures/restores the scoped context state: block style, block type, heading level,
|
|
* blockquote/list depths, list type, list item counter and accumulated indent.
|
|
* Accumulators (range registries, taskItemCount) are excluded on purpose — they
|
|
* must survive restores.
|
|
*/
|
|
- (id)snapshotScope;
|
|
- (void)restoreScope:(id)snapshot;
|
|
|
|
/**
|
|
* Checks if colors should be preserved based on existing attributes.
|
|
* Returns YES if the text is inside a link or inline code, which means
|
|
* we should preserve their colors instead of applying new colors.
|
|
*/
|
|
+ (BOOL)shouldPreserveColors:(NSDictionary *)existingAttributes;
|
|
|
|
/**
|
|
* Calculates the color that strong would use based on the configured strong color and block style.
|
|
* Uses strongColor if explicitly set (different from block color), otherwise uses block color.
|
|
*/
|
|
+ (RCTUIColor *)calculateStrongColor:(RCTUIColor *)configStrongColor blockColor:(RCTUIColor *)blockColor;
|
|
|
|
/**
|
|
* Resolves highlight foreground color: uses block color when config matches paragraph default.
|
|
*/
|
|
+ (RCTUIColor *)calculateHighlightColor:(RCTUIColor *)configHighlightColor
|
|
paragraphColor:(RCTUIColor *)paragraphColor
|
|
blockColor:(RCTUIColor *)blockColor;
|
|
|
|
/**
|
|
* Calculates the range for content rendered between start and current output length.
|
|
* Returns a range with length 0 if no content was rendered.
|
|
*/
|
|
+ (NSRange)rangeForRenderedContent:(NSMutableAttributedString *)output start:(NSUInteger)start;
|
|
|
|
/**
|
|
* Applies font and color attributes conditionally, only updating if they've changed.
|
|
* Returns YES if any attributes were updated, NO otherwise.
|
|
*/
|
|
+ (BOOL)applyFontAndColorAttributes:(NSMutableAttributedString *)output
|
|
range:(NSRange)range
|
|
font:(UIFont *)font
|
|
color:(RCTUIColor *)color
|
|
existingAttributes:(NSDictionary *)existingAttributes
|
|
shouldPreserveColors:(BOOL)shouldPreserveColors;
|
|
@end
|