elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

Newline stripping breaks markdown lists #59

Closed Gama11 closed 5 years ago

Gama11 commented 5 years ago
import sys.io.File;
import json2object.utils.JsonSchemaWriter;

using StringTools;

class Main {
    static function main() {
        var schema = new JsonSchemaWriter<Config>("\t").schema;
        schema = schema.replace('"description"', '"markdownDescription"');
        File.saveContent("schema.json", schema);
    }
}

typedef Config = {
    /**
        This is a list:
        - a
            - 1
            - 2
        - b
        - c
    **/
    var foo:String;
}

This is valid markdown:

However, all newlines are removed from the generated schema, breaking the list formatting:

"markdownDescription": "This is a list: - a - 1 - 2 - b - c",

json2object 3.6.2

elnabo commented 5 years ago

I think this and #60 will requires the use of some function given to JsonSchemaWriter that allow some kind of customization of the schema object while staying within the spec.

elnabo commented 5 years ago

With the latest commits, we've added the possibility to generate schema that differ a bit from the spec.

We've added json2object.utils.special.VSCodeSchemaWriter.

For your example it generates the following description "markdownDescription": "This is a list:\n- a\n- 1\n- 2\n- b\n- c"

Gama11 commented 5 years ago

This is still not quite correct, the nesting of the list / leading whitespace is removed. Current result is:

"This is a list:\n- a\n- 1\n- 2\n- b\n- c"

But there should be tabs before -1 and -2:

"This is a list:\n- a\n - 1\n   - 2\n- b\n- c"
elnabo commented 5 years ago

Are extra tabulation on all lines but the first one a problem ?

Haxe return this string for your example:

This is a list:\n\t\t- a\n\t\t\t- 1\n\t\t\t- 2\n\t\t- b\n\t\t- c

Would this display correctly or should I remove extra tabulation if all lines but the first have some ?

Gama11 commented 5 years ago

Well, what should be removed is the indentation, which is two tab characters per line in this case. Anything after that belongs to the "content" of the doc comment.

elnabo commented 5 years ago

This should be fixed with 00d1dde2287ca0d00cee8927976d22b8b0b0662f.

Gama11 commented 5 years ago

Great, looks like markdown lists are working now. 👍