Skip to content

Commit

Permalink
add unescape
Browse files Browse the repository at this point in the history
  • Loading branch information
umemak committed May 30, 2022
1 parent e64ddbf commit 7227e55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
withHeadings: true,
content: [
["name", "1", "2", "3", "4", "5"],
["A", "@11l8o4v120gf", "e4g>c<b4g>d", "c4e4r4c<b", "a4>fdc4<b4>", "c2r2"],
["B", "@11l8o3v100r4", "rgggrggg", ">rcccrccc", "rdddrerf", "rggfe4r4"],
["C", "@11l8o3v100r4", "reeerfff", "rgggrggg", "raaa>rcrd", "reedc4r4"],
["D", "@11l2o3v100r4", "cd", "ee", "fg4g4", ">c4r4r2"]
["A", "@11l8o4v120gf", "e4g&gt;c&lt;b4g&gt;d", "c4e4r4c&lt;b", "a4>fdc4&lt;b4&gt;", "c2r2"],
["B", "@11l8o3v100r4", "rgggrggg", "&gt;rcccrccc", "rdddrerf", "rggfe4r4"],
["C", "@11l8o3v100r4", "reeerfff", "rgggrggg", "raaa&gt;rcrd", "reedc4r4"],
["D", "@11l2o3v100r4", "cd", "ee", "fg4g4", "&gt;c4r4r2"]
]
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/json2md.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function JSONtoMD(json: string): string {
let res = ""
const js = JSON.parse(json).blocks
const js = JSON.parse(unescapeHtm(json)).blocks
for (let i = 0; i < js.length; i++) {
const e = js[i]
if (e.type == "table") {
Expand All @@ -21,3 +21,22 @@ export function JSONtoMD(json: string): string {
}
return res
}

function unescapeHtm(src: string): string {
const patterns = new Map<string, string>([
['&lt;', '<'],
['&gt;', '>'],
['&amp;', '&'],
['&quot;', '"'],
['&#x27;', '\''],
['&#x60;', '`'],
])

return src.replace(/&(lt|gt|amp|quot|#x27|#x60);/g, function (match: string): string {
const ret = patterns.get(match)
if (ret == undefined) {
return ""
}
return ret
})
}

0 comments on commit 7227e55

Please sign in to comment.