Skip to content

Commit

Permalink
Allow inline elements configuration (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-glutting committed Jun 3, 2019
1 parent fd9582c commit 24c622b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/draft-js-import-element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ stateFromElement(element, {
});
```

- `inlineElements`: Array of (lowercase) tag names which should be handled as inline tags. Example:
```js
stateFromElement(element, {
inlineElements: ['my-first-custom-tag', 'my-second-custom-tag']
});
```

## License

This software is [BSD Licensed](/LICENSE).
5 changes: 4 additions & 1 deletion packages/draft-js-import-element/src/stateFromElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Options = {
blockTypes?: {[key: string]: string};
customBlockFn?: CustomBlockFn;
customInlineFn?: CustomInlineFn;
inlineElements?: string[];
};
type DataMap<T> = {[key: string]: T};

Expand Down Expand Up @@ -403,10 +404,12 @@ class ContentGenerator {

processNode(node: DOMNode) {
if (node.nodeType === NODE_TYPE_ELEMENT) {
let {inlineElements} = this.options;
// $FlowIssue
let element: DOMElement = node;
let tagName = element.nodeName.toLowerCase();
if (INLINE_ELEMENTS.hasOwnProperty(tagName)) {
if (INLINE_ELEMENTS.hasOwnProperty(tagName)
|| (inlineElements && inlineElements.find((el) => el === tagName))) {
this.processInlineElement(element);
} else {
this.processBlockElement(element);
Expand Down
1 change: 1 addition & 0 deletions packages/draft-js-import-html/src/stateFromHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Options = {
blockTypes?: {[key: string]: string};
customBlockFn?: CustomBlockFn;
customInlineFn?: CustomInlineFn;
inlineElements: string[];
};

const defaultOptions: Options = {};
Expand Down
1 change: 1 addition & 0 deletions packages/draft-js-import-html/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare module 'draft-js-import-html' {
elementStyles?: { [styleName: string]: string };
customBlockFn?: CustomBlockFn;
customInlineFn?: CustomInlineFn;
inlineElements?: string []
}

export function stateFromHTML(html: string, options?: Options): draftjs.ContentState;
Expand Down

0 comments on commit 24c622b

Please sign in to comment.