Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
JinHao-L authored Mar 2, 2024
2 parents f009b36 + 4703988 commit 25261dd
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 221 deletions.
14 changes: 14 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: backstage.io/v1alpha1
kind: System
metadata:
name: rich-text
description: |
Monorepo with Typescript libraries for handling and rendering Contentful Rich Text documents.
annotations:
circleci.com/project-slug: github/contentful/rich-text
github.com/project-slug: contentful/rich-text
backstage.io/source-location: url:https://github.com/contentful/rich-text/
spec:
type: library
lifecycle: production
owner: group:team-tolkien
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"trailingComma": "all"
},
"devDependencies": {
"@commitlint/cli": "17.4.2",
"@commitlint/cli": "19.0.3",
"@commitlint/config-conventional": "17.4.2",
"@types/benchmark": "^2.1.4",
"@types/faker": "^4.1.12",
Expand Down
6 changes: 6 additions & 0 deletions packages/rich-text-from-markdown/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [15.16.14](https://github.com/contentful/rich-text/compare/@contentful/[email protected]...@contentful/[email protected]) (2024-03-01)

### Bug Fixes

- support <br/> from markdown ([#536](https://github.com/contentful/rich-text/issues/536)) ([30a3668](https://github.com/contentful/rich-text/commit/30a36685f42c70c98ae4bfb514ba710812ec0824))

## [15.16.13](https://github.com/contentful/rich-text/compare/@contentful/[email protected]...@contentful/[email protected]) (2024-01-30)

**Note:** Version bump only for package @contentful/rich-text-from-markdown
Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text-from-markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentful/rich-text-from-markdown",
"version": "15.16.13",
"version": "15.16.14",
"description": "convert markdown to rich text",
"keywords": [
"rich-text",
Expand Down
6 changes: 3 additions & 3 deletions packages/rich-text-from-markdown/src/__test__/real-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Unordered
* Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
- Very easy!
- Here is a list item<br/>with a line break

Ordered

Expand Down Expand Up @@ -88,7 +89,7 @@ Inline `code`
| Test 1 | Germany |
| Test 2 | USA |
| > Test 3 | USA |
| * Test 4 | Germany |
| \* Test 4 | Germany |
| # Test 5 | Germany |
| <p>Test 6<br/>Test 7</p> | USA |
| <ul><li>Test 8</li></ul> | USA |
Expand All @@ -109,12 +110,11 @@ Inline `code`
| abc | def |
| --- | --- |


## Table with empty cells

| | |
| ------ | ------ |
| Cell 1 | |
| | Cell 2 |

<!-- prettier-ignore-end -->
<!-- prettier-ignore-end -->
15 changes: 13 additions & 2 deletions packages/rich-text-from-markdown/src/__test__/real-world.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ with a new line.`),
),
block(BLOCKS.PARAGRAPH, {}, text('This is a new paragraph.')),
// TODO: <br /> test should be ideally the same as the new line one.
block(BLOCKS.PARAGRAPH, {}, text('This is a paragraph'), text('using br.')),
block(BLOCKS.PARAGRAPH, {}, text('This is a paragraph'), text('\n'), text('using br.')),

block(BLOCKS.HEADING_2, {}, text('Horizontal Rules')),
block(BLOCKS.HR),
Expand Down Expand Up @@ -106,6 +106,17 @@ with a new line.`),
),
),
block(BLOCKS.LIST_ITEM, {}, block(BLOCKS.PARAGRAPH, {}, text('Very easy!'))),
block(
BLOCKS.LIST_ITEM,
{},
block(
BLOCKS.PARAGRAPH,
{},
text('Here is a list item'),
text('\n'),
text('with a line break'),
),
),
),
block(BLOCKS.PARAGRAPH, {}, text('Ordered')),
block(
Expand Down Expand Up @@ -217,7 +228,7 @@ with a new line.`),
block(
BLOCKS.TABLE_CELL,
{},
block(BLOCKS.PARAGRAPH, {}, text('Test 6'), text('Test 7')),
block(BLOCKS.PARAGRAPH, {}, text('Test 6'), text('\n'), text('Test 7')),
),
block(BLOCKS.TABLE_CELL, {}, block(BLOCKS.PARAGRAPH, {}, text('USA'))),
),
Expand Down
7 changes: 7 additions & 0 deletions packages/rich-text-from-markdown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ async function mdToRichTextNode(
fallback: FallbackResolver,
appliedMarksTypes: string[] = [],
): Promise<Node[]> {
// By default <br/> is parsed as html node, causing it to be stripped out.
// We need to convert it manually in order to support it
if (node.type === 'html' && /<br\s?\/?>/gi.test(node.value)) {
node.value = '\n';
node.type = 'text';
}

const nodeType = nodeTypeFor(node);

if (isLink(node)) {
Expand Down
Loading

0 comments on commit 25261dd

Please sign in to comment.