-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): heading with links not rendered (#41)
- Loading branch information
1 parent
4d51023
commit c7ea848
Showing
11 changed files
with
160 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphcms/rich-text-react-renderer': patch | ||
--- | ||
|
||
Fix heading with links not being rendered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { | ||
ElementNode, | ||
isElement, | ||
isText, | ||
Text, | ||
} from '@graphcms/rich-text-types'; | ||
|
||
export function elementIsEmpty({ | ||
children, | ||
}: { | ||
children: (ElementNode | Text)[]; | ||
}): boolean { | ||
// Checks if the children array has more than one element. | ||
// It may have a link inside, that's why we need to check this condition. | ||
if (children.length > 1) { | ||
const hasText = children.filter(function f(child): boolean | number { | ||
if (isText(child) && child.text !== '') { | ||
return true; | ||
} | ||
|
||
if (isElement(child)) { | ||
return (child.children = child.children.filter(f)).length; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
return hasText.length > 0 ? false : true; | ||
} else if (children[0].text === '') return true; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.