Skip to content

Commit

Permalink
[DEV-1374] Correct br parsing (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommaso1 authored Feb 28, 2024
1 parent fe20b97 commit b2dedb0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/spicy-coins-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gitbook-docs": patch
"nextjs-website": patch
---

Fix br parsing
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const components: RenderingComponents<ReactNode> = {
Card: Card,
CardItem: CardItem,
PageLink: PageLink,
Br: () => <br />,
};

const GitBookContent = ({ content, config }: GitBookContentProps) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ export const TableD = (props: TableCellProps) => {
>
{Array.isArray(props.children)
? props.children.map((children, index) => (
<Fragment key={index}>
{children}
<br />
</Fragment>
<Fragment key={index}>{children}</Fragment>
))
: props.children}
</MUITableCell>
Expand Down
10 changes: 10 additions & 0 deletions packages/gitbook-docs/src/__tests__/parseContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ describe('parseContent', () => {
]);
});

it('should parse br correctly', () => {
expect(parseContent('Hello<br>there', config)).toStrictEqual([
new Markdoc.Tag('Paragraph', {}, [
'Hello',
new Markdoc.Tag('Br', {}),
'there',
]),
]);
});

it('should convert href as expected given a link with an anchor', () => {
expect(
parseContent(
Expand Down
5 changes: 5 additions & 0 deletions packages/gitbook-docs/src/markdoc/schema/br.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Schema } from '@markdoc/markdoc';

export const br: Schema = {
render: 'Br',
};
2 changes: 2 additions & 0 deletions packages/gitbook-docs/src/parseContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { blockquote } from './markdoc/schema/blockquote';
import { tabs } from './markdoc/schema/tabs';
import { details } from './markdoc/schema/details';
import { embed } from './markdoc/schema/embed';
import { br } from './markdoc/schema/br';
import { table } from './markdoc/schema/table';
import { pageLink } from './markdoc/schema/pageLink';
import { processHtmlTokens } from './markdoc/tokenProcessor';
Expand Down Expand Up @@ -70,6 +71,7 @@ const schema: ConfigType = {
htmlli: item,
htmltable: table,
htmla: link,
htmlbr: br,
htmlstrong: styled.strong,
},
nodes: {
Expand Down
1 change: 1 addition & 0 deletions packages/gitbook-docs/src/renderContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export type RenderingComponents<A> = {
readonly ExpandableDetails: (props: ExpandableDetailsProps<A>) => A;
readonly Swagger: (props: SwaggerProps) => A;
readonly PageLink: (props: PageLinkProps<A>) => A;
readonly Br: () => A;
};

export const renderContent = (
Expand Down

0 comments on commit b2dedb0

Please sign in to comment.