Skip to content

Commit

Permalink
feat: support htmlParserOptions prop
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `decodeEntities` prop has been dropped. Pass this
option to `htmlParserOptions` prop instead.
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 6c9d70f commit 624c57e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/render-html/src/RenderHTML.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const propTypes: RenderHTMLPropTypes = {
ignoredTags: PropTypes.array.isRequired,
ignoredStyles: PropTypes.array.isRequired,
allowedStyles: PropTypes.array,
decodeEntities: PropTypes.bool.isRequired,
htmlParserOptions: PropTypes.object,
debug: PropTypes.bool.isRequired,
listsPrefixesRenderers: PropTypes.object,
alterData: PropTypes.func,
Expand Down Expand Up @@ -70,7 +70,9 @@ const defaultProps: {
[k in keyof RenderHTMLProps]?: RenderHTMLProps[k];
} = {
...defaultSharedPropsContext,
decodeEntities: true,
htmlParserOptions: {
decodeEntities: true
},
emSize: 14,
ptSize: 1.3,
ignoredTags: [],
Expand Down
5 changes: 3 additions & 2 deletions packages/render-html/src/hooks/useTRenderEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function useTRenderEngine(props: RenderHTMLProps) {
const {
allowedStyles,
ignoredStyles,
decodeEntities,
htmlParserOptions,
baseStyle,
classesStyles,
tagsStyles,
Expand Down Expand Up @@ -102,7 +102,8 @@ export default function useTRenderEngine(props: RenderHTMLProps) {
inlinePropertiesWhitelist: allowedStyles
},
htmlParserOptions: {
decodeEntities
decodeEntities: true,
...htmlParserOptions
},
stylesConfig: {
baseStyle,
Expand Down
8 changes: 5 additions & 3 deletions packages/render-html/src/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '@native-html/css-processor';
import type { TStyles } from '@native-html/transient-render-engine';
import { CustomTagRendererRecord } from './render/render-types';
import { ParserOptions as HtmlParserOptions } from 'htmlparser2';

export interface RendererDictionary<P> {}

Expand Down Expand Up @@ -104,10 +105,11 @@ export interface RenderHTMLPassedProps<P = any> {

export interface TransientRenderEngineConfig {
/**
* Decode HTML entities of your content.
* Optional, defaults to true
* ParserOptions for [htmlparser2](https://github.com/fb55/htmlparser2/wiki/Parser-options)
*
* @defaultvalue `{ decodeEntities: true }`
*/
decodeEntities?: boolean;
htmlParserOptions?: HtmlParserOptions;
/**
* Enable or disable fallback styles for each tag. For example, `pre` tags
* will have `whiteSpace` set to 'pre' by default.
Expand Down

0 comments on commit 624c57e

Please sign in to comment.