Commit ee4c20fa authored by Zéfling's avatar Zéfling 🎨
Browse files

fix attributes render

parent ca9ac460
# Editor configuration, see http://editorconfig.org
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
[*.json]
indent_size = 2
# Changelog of json2html-lib
## V0.0.2 (2020-10-14)
- Fix attributs render
## V0.0.1 (2020-10-14)
- initial release
{
"name": "json2html-lib",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",
"repository": {
"type": "git",
......
......@@ -79,30 +79,32 @@ export class Json2html {
private _generateAttrs(lvl: number, json: Json2htmlRef) {
let string = '';
const attrs = json.attrs;
if (json.attrs && Object.keys(json.attrs).length) {
for (const id in json.attrs) {
if (json.attrs[id] !== undefined) {
if (attrs && Object.keys(attrs).length) {
for (const id in attrs) {
if (attrs[id] !== undefined) {
let attr = '';
switch (this.options.attrPosition) {
case 'inline':
string += ' ';
attr += ' ';
break;
case 'space':
string += string && this.options.indent && this._hasMultiline()
attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl + 1)}`
: string += ' ';
break;
case 'alignTag':
string += string += string && this.options.indent && this._hasMultiline()
attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl, 1)}`
: ' ';
break;
case 'alignFirstAttr':
string += string += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl, this.json.tag.length + 2)}`
attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl, json.tag.length + 2)}`
: ' ';
break;
}
string += `${id}${json.attrs[id] !== null || json.attrs[id] ? `="${json.attrs[id]}"` : ''}`;
attr += `${id}${attrs[id] !== null || attrs[id] ? `="${attrs[id]}"` : ''}`;
string += attr;
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment