Skip to content

Commit

Permalink
Merge pull request #34 from contentstack/EB-689-issue-using-jsonrte-s…
Browse files Browse the repository at this point in the history
…erializer

Eb 689 issue using jsonrte serializer
  • Loading branch information
sairajchouhan authored Jan 4, 2024
2 parents ec4585d + c0fd0bd commit cf6bd1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/fromRedactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ const isVoid = ['img', 'embed']


const ELEMENT_TAGS: IHtmlToJsonElementTags = {
A: (el: HTMLElement) => ({
type: 'a',
attrs: {
url:
el.getAttribute('href') ? el.getAttribute('href') : '#'
A: (el: HTMLElement) => {
const attrs: Record<string, string> = {}
const target = el.getAttribute('target');
const href = el.getAttribute('href');

attrs.url = href ? href : '#';

if(target && target !== '') {
attrs.target = target;
}
}),

return {
type: "a",
attrs: attrs,
};
},
BLOCKQUOTE: () => ({ type: 'blockquote', attrs: {} }),
H1: () => ({ type: 'h1', attrs: {} }),
H2: () => ({ type: 'h2', attrs: {} }),
Expand Down
2 changes: 2 additions & 0 deletions test/expectedJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ export default {
"type": "a",
"attrs": {
"url": "link.com",
"target": "_self",
"style": {},
"redactor-attributes": {
"href": "link.com",
Expand Down Expand Up @@ -870,6 +871,7 @@ export default {
"type": "a",
"attrs": {
"url": "#",
"target": "_blank",
"style": {},
"redactor-attributes": {
"target": "_blank"
Expand Down

0 comments on commit cf6bd1c

Please sign in to comment.