Skip to content

Commit 42d81a2

Browse files
committed
Merge branch 'dev' into RT-496
2 parents ae88512 + 6037a82 commit 42d81a2

File tree

9 files changed

+138
-13
lines changed

9 files changed

+138
-13
lines changed

.github/workflows/secrets-scan.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Secrets Scan
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened]
5+
jobs:
6+
security-secrets:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
with:
11+
fetch-depth: '2'
12+
ref: '${{ github.event.pull_request.head.ref }}'
13+
- run: |
14+
git reset --soft HEAD~1
15+
- name: Install Talisman
16+
run: |
17+
# Download Talisman
18+
wget https://github.com/thoughtworks/talisman/releases/download/v1.37.0/talisman_linux_amd64 -O talisman
19+
20+
# Checksum verification
21+
checksum=$(sha256sum ./talisman | awk '{print $1}')
22+
if [ "$checksum" != "8e0ae8bb7b160bf10c4fa1448beb04a32a35e63505b3dddff74a092bccaaa7e4" ]; then exit 1; fi
23+
24+
# Make it executable
25+
chmod +x talisman
26+
- name: Run talisman
27+
run: |
28+
# Run Talisman with the pre-commit hook
29+
./talisman --githook pre-commit

.talismanrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
fileignoreconfig:
2+
- filename: .github/workflows/secrets-scan.yml
3+
ignore_detectors:
4+
- filecontent
25
- filename: README.md
36
checksum: 4bffa07e1e88d50a311464c9f90ff92bcba7fe434be4d9374bcd49bf76b1e6a8
47
- filename: coverage/lcov-report/base.css

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/json-rte-serializer",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "This Package converts Html Document to Json and vice-versa.",
55
"main": "lib/index.js",
66
"module": "lib/index.mjs",

src/fromRedactor.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ export const ELEMENT_TAGS: IHtmlToJsonElementTags = {
2020
const attrs: Record<string, string> = {}
2121
const target = el.getAttribute('target');
2222
const href = el.getAttribute('href');
23+
const title = el.getAttribute('title');
2324

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

2627
if(target && target !== '') {
2728
attrs.target = target;
2829
}
30+
if(title && title !== '') {
31+
attrs.title = title;
32+
}
2933

3034
return {
3135
type: "a",

src/jsonToMarkdown.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ const ELEMENT_TYPES: IJsonToMarkdownElementTags = {
1414
'h1': (attrs: any, child: string) => {
1515
return `
1616
17-
#${child}#`
17+
# ${child} #`
1818
},
1919
'h2': (attrs: any, child: any) => {
2020
return `
2121
22-
##${child}##`
22+
## ${child} ##`
2323
},
2424
'h3': (attrs: any, child: any) => {
2525
return `
2626
27-
###${child}###`
27+
### ${child} ###`
2828
},
2929
'h4': (attrs: any, child: any) => {
3030
return `
3131
32-
####${child}####`
32+
#### ${child} ####`
3333
},
3434
'h5': (attrs: any, child: any) => {
3535
return `
3636
37-
#####${child}#####`
37+
##### ${child} #####`
3838
},
3939
'h6': (attrs: any, child: any) => {
4040
return `
4141
42-
######${child}######`
42+
###### ${child} ######`
4343
},
4444
img: (attrsJson: any, child: any) => {
4545
if(attrsJson) {

test/expectedJson.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,77 @@ export default {
24162416
"_version": 2
24172417
}
24182418
]
2419+
},
2420+
"RT-501":{
2421+
"html" : [
2422+
`<p><a href="google.in" target="_blank" title="google">ABC</a></p>`
2423+
],
2424+
"json" : [
2425+
{
2426+
"type": "doc",
2427+
"attrs": {},
2428+
"uid": "bd63f151aa8d402cae046c8dae440134",
2429+
"children": [
2430+
{
2431+
"type": "p",
2432+
"uid": "d2949ce0e0974ce783543edd37410c71",
2433+
"attrs": {},
2434+
"children": [
2435+
{
2436+
"uid": "7a2fd904668447ca8720428cbd2b0acc",
2437+
"type": "a",
2438+
"attrs": {
2439+
"url": "google.in",
2440+
"target": "_blank",
2441+
"title": "google"
2442+
},
2443+
"children": [
2444+
{
2445+
"text": "ABC"
2446+
}
2447+
]
2448+
}
2449+
]
2450+
}
2451+
],
2452+
}
2453+
],
2454+
"jsonWithRedactorAttributes": [
2455+
{
2456+
"type": "doc",
2457+
"attrs": {},
2458+
"uid": "bd63f151aa8d402cae046c8dae440134",
2459+
"children": [
2460+
{
2461+
"type": "p",
2462+
"uid": "d2949ce0e0974ce783543edd37410c71",
2463+
"attrs": {},
2464+
"children": [
2465+
{
2466+
"uid": "7a2fd904668447ca8720428cbd2b0acc",
2467+
"type": "a",
2468+
"attrs": {
2469+
"url": "google.in",
2470+
"target": "_blank",
2471+
"title": "google",
2472+
"style": {},
2473+
"redactor-attributes": {
2474+
"href": "google.in",
2475+
"target": "_blank",
2476+
"title": "google"
2477+
}
2478+
},
2479+
"children": [
2480+
{
2481+
"text": "ABC"
2482+
}
2483+
]
2484+
}
2485+
]
2486+
}
2487+
]
2488+
}
2489+
]
24192490
}
24202491

24212492
}

test/expectedMarkdown.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,17 @@ This is a paragraph with \`inline code\`.`
163163
}],
164164
"markdown": `
165165
166-
#Heading 1#
166+
# Heading 1 #
167167
168-
##Heading 2##
168+
## Heading 2 ##
169169
170-
###Heading 3###
170+
### Heading 3 ###
171171
172-
####Heading 4####
172+
#### Heading 4 ####
173173
174-
#####Heading 5#####
174+
##### Heading 5 #####
175175
176-
######Heading 6######`
176+
###### Heading 6 ######`
177177
},
178178
{
179179
"title": "Block Quote Conversion",

test/fromRedactor.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ describe("Testing html to json conversion", () => {
328328
expect(json).toStrictEqual({"type":"doc","uid":"uid","attrs":{},"children":[{"type":"p","attrs":{},"uid":"uid","children":[{"text":"Hello","attrs":{"style":{}},"bold":true},{"text":" Hii"}]}]})
329329

330330
})
331+
test("should add title attr to anchor tag", () => {
332+
const html = expectedValue["RT-501"].html[0];
333+
const json =expectedValue["RT-501"].jsonWithRedactorAttributes[0];
334+
335+
let jsonValue = htmlToJson(html)
336+
expect(omitdeep(jsonValue, "uid")).toStrictEqual(omitdeep(json, "uid"))
337+
})
331338
})
332339

333340

test/toRedactor.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ describe("Testing json to html conversion", () => {
329329
})
330330
})
331331

332+
describe("RT-501",()=>{
333+
it("should add title attr to anchor tag",()=>{
334+
const html = expectedValue["RT-501"].html[0];
335+
const json =expectedValue["RT-501"].json[0];
336+
337+
let htmlValue = toRedactor(json)
338+
expect(htmlValue).toBe(html);
339+
})
340+
341+
})
342+
332343
})
333344

334345
test("should add nbsp for empty blocks", () => {

0 commit comments

Comments
 (0)