Skip to content

Commit d951770

Browse files
committed
Allow inline elements configuration (#141)
1 parent fd9582c commit d951770

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

packages/draft-js-import-element/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ stateFromElement(element, {
6565
});
6666
```
6767

68+
- `inlineElements`: Array of (lowercase) tag names which should be handled as inline tags. Example:
69+
```js
70+
stateFromElement(element, {
71+
inlineElements: ['my-first-custom-tag', 'my-second-custom-tag']
72+
});
73+
```
74+
6875
## License
6976

7077
This software is [BSD Licensed](/LICENSE).

packages/draft-js-import-element/src/stateFromElement.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type Options = {
8383
blockTypes?: {[key: string]: string};
8484
customBlockFn?: CustomBlockFn;
8585
customInlineFn?: CustomInlineFn;
86+
inlineElements?: string[];
8687
};
8788
type DataMap<T> = {[key: string]: T};
8889

@@ -403,10 +404,12 @@ class ContentGenerator {
403404

404405
processNode(node: DOMNode) {
405406
if (node.nodeType === NODE_TYPE_ELEMENT) {
407+
let {inlineElements} = this.options;
406408
// $FlowIssue
407409
let element: DOMElement = node;
408410
let tagName = element.nodeName.toLowerCase();
409-
if (INLINE_ELEMENTS.hasOwnProperty(tagName)) {
411+
if (INLINE_ELEMENTS.hasOwnProperty(tagName)
412+
|| (inlineElements && inlineElements.find((el) => el === tagName))) {
410413
this.processInlineElement(element);
411414
} else {
412415
this.processBlockElement(element);

packages/draft-js-import-html/src/stateFromHTML.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Options = {
1212
blockTypes?: {[key: string]: string};
1313
customBlockFn?: CustomBlockFn;
1414
customInlineFn?: CustomInlineFn;
15+
inlineElements?: string[];
1516
};
1617

1718
const defaultOptions: Options = {};

packages/draft-js-import-html/typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ declare module 'draft-js-import-html' {
2626
elementStyles?: { [styleName: string]: string };
2727
customBlockFn?: CustomBlockFn;
2828
customInlineFn?: CustomInlineFn;
29+
inlineElements?: string []
2930
}
3031

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

0 commit comments

Comments
 (0)