Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
typescript
json2html
Commits
03501972
Commit
03501972
authored
Oct 19, 2020
by
Zéfling
🎨
Browse files
Add optionalEndTags
parent
04e60efb
Changes
1
Hide whitespace changes
Inline
Side-by-side
projects/json2html/src/lib/json2html.ts
View file @
03501972
...
...
@@ -49,6 +49,10 @@ export interface Json2htmlOptions {
indent
?:
boolean
;
/** list of HTML tags without content */
noContentTags
?:
string
[];
/** remove optional end tags */
removeOptionalEndTags
?:
boolean
;
/** list of HTML tags with options end tag */
optionalEndTags
?:
string
[];
}
export
class
Json2html
{
...
...
@@ -80,6 +84,26 @@ export class Json2html {
'
source
'
,
'
track
'
,
'
wbr
'
],
removeOptionalEndTags
:
false
,
optionalEndTags
:
[
'
colgroup
'
,
'
dd
'
,
'
dt
'
,
'
li
'
,
'
optgroup
'
,
'
option
'
,
'
p
'
,
'
rb
'
,
'
rt
'
,
'
rtc
'
,
'
rp
'
,
'
td
'
,
'
th
'
,
'
thead
'
,
'
tbody
'
,
'
tfoot
'
,
'
tr
'
]
};
...
...
@@ -124,7 +148,14 @@ export class Json2html {
if
(
tagcontent
&&
this
.
_hasMultiline
())
{
tagcontent
=
`
${
tagcontent
}
\n
${
this
.
_getSpacing
(
lvl
)}
`
;
}
string
+=
`
${
tagcontent
}
</
${
json
.
tag
}
>`
;
string
+=
tagcontent
;
if
(
!
this
.
options
.
removeOptionalEndTags
||
this
.
options
.
type
===
'
xml
'
||
this
.
options
.
removeOptionalEndTags
&&
!
this
.
options
.
optionalEndTags
.
includes
(
json
.
tag
.
toLowerCase
())
)
{
string
+=
`</
${
json
.
tag
}
>`
;
}
}
return
string
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment