diff --git a/ios/MarkdownCommitHook.mm b/ios/MarkdownCommitHook.mm index 6524cac9..f1923a3d 100644 --- a/ios/MarkdownCommitHook.mm +++ b/ios/MarkdownCommitHook.mm @@ -169,6 +169,53 @@ } } + // apply markdown + auto newString = [utils parseMarkdown:nsAttributedString + withAttributes:defaultNSTextAttributes]; + + // create a clone of the old TextInputState and update the + // attributed string box to point to the string with markdown + // applied + auto newStateData = std::make_shared(stateData); + newStateData->attributedStringBox = + RCTAttributedStringBoxFromNSAttributedString(newString); + + // clone the text input with the new state + return node.clone({ + .state = std::make_shared>( + newStateData, textInputState), + }); + }); + } else if (stateData.attributedStringBox.getMode() == + AttributedStringBox::Mode::OpaquePointer) { + rootNode = rootNode->cloneTree( + nodes.textInput->getFamily(), + [&nodes, &textInputState, &stateData, + fontSizeMultiplier](const ShadowNode &node) { + const auto &markdownProps = *std::static_pointer_cast< + MarkdownTextInputDecoratorViewProps const>( + nodes.decorator->getProps()); + const auto &textInputProps = + *std::static_pointer_cast( + nodes.textInput->getProps()); + + const auto defaultTextAttributes = + textInputProps.getEffectiveTextAttributes(fontSizeMultiplier); + const auto defaultNSTextAttributes = + RCTNSTextAttributesFromTextAttributes(defaultTextAttributes); + + // this can possibly be optimized + RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc] + initWithStruct:markdownProps.markdownStyle]; + RCTMarkdownUtils *utils = [[RCTMarkdownUtils alloc] init]; + [utils setMarkdownStyle:markdownStyle]; + + // convert the attibuted string stored in state to + // NSAttributedString + auto nsAttributedString = + RCTNSAttributedStringFromAttributedStringBox( + stateData.attributedStringBox); + // apply markdown auto newString = [utils parseMarkdown:nsAttributedString withAttributes:defaultNSTextAttributes];