Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/hjson
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if (args["-help"] || args["?"] || args.h) {
console.error(" -sl output the opening brace on the same line");
console.error(" -quote quote all strings");
console.error(" -quote=all quote keys as well");
console.error(" -ml use multiline format for multiline strings");
console.error(" -js output in JavaScript/JSON compatible format");
console.error(" can be used with -rt and // comments");
console.error(" -rt round trip comments");
Expand Down Expand Up @@ -88,6 +89,7 @@ function convert(text) {
quotes: args.quote,
separator: args.js,
keepWsc: args.rt,
multiline: args.ml ? "force" : "std",
colors: !args.nocol && process.stdout.isTTY,
dsf: dsf,
});
Expand Down
2 changes: 1 addition & 1 deletion lib/hjson-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function(data, opt) {
bracesSameLine = opt.bracesSameLine;
quoteKeys = opt.quotes === 'all' || opt.quotes === 'keys';
quoteStrings = opt.quotes === 'all' || opt.quotes === 'strings' || opt.separator === true;
if (quoteStrings || opt.multiline == 'off') multiline = 0;
if ((quoteStrings && opt.multiline !== 'force') || opt.multiline == 'off') multiline = 0;
else multiline = opt.multiline == 'no-tabs' ? 2 : 1;
separator = opt.separator === true ? token.com[0] : '';
dsfDef = opt.dsf;
Expand Down
9 changes: 9 additions & 0 deletions test/assets/extra/force_ml_string_result.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
unquoted_string: "an unquoted normal string"
ml_string:
'''
this is
a multiline
string
'''
}
4 changes: 4 additions & 0 deletions test/assets/extra/force_ml_string_result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"unquoted_string": "an unquoted normal string",
"ml_string": "this is\na multiline\nstring"
}
9 changes: 9 additions & 0 deletions test/assets/extra/force_ml_string_test.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
unquoted_string: an unquoted normal string
ml_string:
'''
this is
a multiline
string
'''
}
6 changes: 6 additions & 0 deletions test/assets/extra/force_ml_string_testmeta.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
options: {
multiline: force
quotes: strings
}
}
1 change: 1 addition & 0 deletions test/assets/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ stringify/quotes_always_test.hjson
stringify/quotes_keys_test.hjson
stringify/quotes_strings_ml_test.json
stringify/quotes_strings_test.hjson
extra/force_ml_string_test.hjson
extra/notabs_test.json
extra/root_test.hjson
extra/separator_test.json