Skip to content

Commit

Permalink
fix(major): lists with start offset
Browse files Browse the repository at this point in the history
  • Loading branch information
gmsgowtham committed Apr 6, 2023
1 parent a6a28de commit e5601b2
Show file tree
Hide file tree
Showing 5 changed files with 374 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/Parser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class Parser {
return this.renderer.hr(this.styles.hr);
}
case "list": {
let startIndex = parseInt(token.start.toString());
if (Number.isNaN(startIndex)) {
startIndex = 1;
}
const li = token.items.map((item) => {
const children = item.tokens.flatMap((cItem) => {
if (cItem.type === "text") {
Expand All @@ -102,6 +106,7 @@ class Parser {
li,
this.styles.list,
this.styles.li,
startIndex,
);
}
case "escape": {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ class Renderer implements RendererInterface {
li: ReactNode[],
listStyle?: ViewStyle,
textStyle?: TextStyle,
startIndex?: number,
): ReactNode {
return (
<MarkedList
counterRenderer={ordered ? Decimal : Disc}
markerTextStyle={textStyle}
markerBoxStyle={listStyle}
key={this.getKey()}
startIndex={startIndex}
>
{li.map((node) => node)}
</MarkedList>
Expand Down
11 changes: 11 additions & 0 deletions src/lib/__tests__/Markdown.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ describe("Lists", () => {
const tree = r.toJSON();
expect(tree).toMatchSnapshot();
});
it("Ordered Lists: With Start Offset", () => {
const r = render(<Markdown value={"57. foo\n1. bar\n2. baz"} />);
expect(screen.queryByText("foo")).toBeTruthy();
expect(screen.queryByText("bar")).toBeTruthy();
expect(screen.queryByText("baz")).toBeTruthy();
expect(screen.queryByText("57.")).toBeTruthy();
expect(screen.queryByText("58.")).toBeTruthy();
expect(screen.queryByText("59.")).toBeTruthy();
const tree = r.toJSON();
expect(tree).toMatchSnapshot();
});
it("Unordered Lists", () => {
const r = render(
<Markdown
Expand Down
Loading

0 comments on commit e5601b2

Please sign in to comment.