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 root = true
[*] [*]
charset = utf-8 charset = utf-8
indent_style = space indent_style = space
indent_size = 2 indent_size = 4
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.md] [*.md]
max_line_length = off max_line_length = off
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.json]
indent_size = 2
# Changelog of json2html-lib # Changelog of json2html-lib
## V0.0.2 (2020-10-14)
- Fix attributs render
## V0.0.1 (2020-10-14) ## V0.0.1 (2020-10-14)
- initial release - initial release
{ {
"name": "json2html-lib", "name": "json2html-lib",
"version": "0.0.1", "version": "0.0.2",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",
......
...@@ -79,30 +79,32 @@ export class Json2html { ...@@ -79,30 +79,32 @@ export class Json2html {
private _generateAttrs(lvl: number, json: Json2htmlRef) { private _generateAttrs(lvl: number, json: Json2htmlRef) {
let string = ''; let string = '';
const attrs = json.attrs; const attrs = json.attrs;
if (json.attrs && Object.keys(json.attrs).length) { if (attrs && Object.keys(attrs).length) {
for (const id in json.attrs) { for (const id in attrs) {
if (json.attrs[id] !== undefined) { if (attrs[id] !== undefined) {
let attr = '';
switch (this.options.attrPosition) { switch (this.options.attrPosition) {
case 'inline': case 'inline':
string += ' '; attr += ' ';
break; break;
case 'space': case 'space':
string += string && this.options.indent && this._hasMultiline() attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl + 1)}` ? `\n${this._getSpacing(lvl + 1)}`
: string += ' '; : string += ' ';
break; break;
case 'alignTag': case 'alignTag':
string += string += string && this.options.indent && this._hasMultiline() attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl, 1)}` ? `\n${this._getSpacing(lvl, 1)}`
: ' '; : ' ';
break; break;
case 'alignFirstAttr': case 'alignFirstAttr':
string += string += string && this.options.indent && this._hasMultiline() attr += string && this.options.indent && this._hasMultiline()
? `\n${this._getSpacing(lvl, this.json.tag.length + 2)}` ? `\n${this._getSpacing(lvl, json.tag.length + 2)}`
: ' '; : ' ';
break; break;
} }
string += `${id}${json.attrs[id] !== null || json.attrs[id] ? `="${json.attrs[id]}"` : ''}`; attr += `${id}${attrs[id] !== null || attrs[id] ? `="${attrs[id]}"` : ''}`;
string += attr;
} }
} }
} }
......
Supports Markdown
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