-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add OL renderer #90482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OL renderer #90482
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {TNode} from 'react-native-render-html'; | ||
| import {TNodeChildrenRenderer} from 'react-native-render-html'; | ||
| import Text from '@components/Text'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| type NumberedItemRendererProps = {tnode: TNode; index: number}; | ||
|
|
||
| function NumberedItemRenderer({tnode, index}: NumberedItemRendererProps) { | ||
| const styles = useThemeStyles(); | ||
|
|
||
| return ( | ||
| <View style={[styles.flexRow, styles.w100]}> | ||
| <Text style={styles.numberedListItemMarker}>{`${index}.`}</Text> | ||
| <View style={styles.flex1}> | ||
| <TNodeChildrenRenderer tnode={tnode} /> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default NumberedItemRenderer; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {CustomRendererProps, TBlock} from 'react-native-render-html'; | ||
| import {TNodeRenderer} from 'react-native-render-html'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import NumberedItemRenderer from './NumberedItemRenderer'; | ||
|
|
||
| function buildLiIndices(children: CustomRendererProps<TBlock>['tnode']['children']): Map<number, number> { | ||
| const map = new Map<number, number>(); | ||
| let counter = 0; | ||
| for (const [i, child] of children.entries()) { | ||
| if (child.tagName === 'li') { | ||
| counter += 1; | ||
| map.set(i, counter); | ||
|
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The custom Useful? React with 👍 / 👎.
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an ordered list uses standard numbering controls such as Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
| return map; | ||
| } | ||
|
|
||
| function OLRenderer({tnode, style}: CustomRendererProps<TBlock>) { | ||
| const styles = useThemeStyles(); | ||
| const liIndices = buildLiIndices(tnode.children); | ||
|
|
||
| return ( | ||
| <View style={[style, styles.gap2]}> | ||
| {tnode.children.map((child, index) => { | ||
| const key = `${child.tagName ?? 'node'}-${index}`; | ||
| const liIndex = liIndices.get(index); | ||
| if (liIndex !== undefined) { | ||
| return ( | ||
| <NumberedItemRenderer | ||
| key={key} | ||
| tnode={child} | ||
| index={liIndex} | ||
| /> | ||
| ); | ||
| } | ||
| return ( | ||
| <TNodeRenderer | ||
| key={key} | ||
| tnode={child} | ||
| renderIndex={index} | ||
| renderLength={tnode.children.length} | ||
| /> | ||
| ); | ||
| })} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default OLRenderer; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numbering attributes when rendering markers
The new ordered-list renderer always starts numbering from
1and increments per<li>(counter = 0thencounter += 1), so it ignores standard list attributes like<ol start>,<ol reversed>,<ol type>, and per-itemvalue. In any HTML payload that uses those attributes (for example, continuation lists starting at 3), the rendered numbering becomes incorrect (1., 2., ...), which changes the meaning of ordered instructions.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question weather we need it? Do we expect concierge to use those ?