-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
@prismicio/client/richtext
entry (#318)
* feat: add `@prismicio/client/richtext` entry * refactor: remove dependency on `@prismicio/richtext` * chore(deps): maintain dependencies * chore(deps): pin TypeScript version because ignore comments behavior changed --------- Co-authored-by: lihbr <lihbr@users.noreply.github.com>
- Loading branch information
1 parent
b43557d
commit fb555fd
Showing
38 changed files
with
6,388 additions
and
594 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,27 @@ | ||
import { RTTextNode, RichTextField } from "../types/value/richText"; | ||
|
||
/** | ||
* Serializes a rich text or title field to a plain text string | ||
* | ||
* @param richTextField - A rich text or title field from Prismic | ||
* @param separator - Separator used to join each element, defaults to a space | ||
* | ||
* @returns Plain text equivalent of the provided rich text or title field | ||
* | ||
* @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript} | ||
*/ | ||
export const asText = ( | ||
richTextField: RichTextField, | ||
separator = " ", | ||
): string => { | ||
let result = ""; | ||
|
||
for (let i = 0; i < richTextField.length; i++) { | ||
if ("text" in richTextField[i]) { | ||
result += | ||
(result ? separator : "") + (richTextField[i] as RTTextNode).text; | ||
} | ||
} | ||
|
||
return result; | ||
}; |
Oops, something went wrong.