mam_mol icon indicating copy to clipboard operation
mam_mol copied to clipboard

Unexpected behavior of $mol_tree2_to_json

Open blokhin opened this issue 2 years ago • 4 comments

I observe strange behavior of $mol_tree2_to_json using node v18.14.0. The tree ref implementation was installed with npm i mol_tree2.

This produces an empty string (expected JSON):

console.log(
	Tree.$mol_tree2_to_json(
		Tree.$mol_tree2_from_string(`
	foo
		bar
		lol
	hello \world
`)
	)
);

This yields an error Error: Unknown json type (article) (expected JSON):

console.log(
	Tree.$mol_tree2_to_json(
		Tree.$mol_tree2_from_string(`
article
	title \Hello world
	description
		\This is demo of tree-format
		\Cool! Is not it? :-)
`)
	)
);

However in both these cases $mol_tree2_from_string produces valid $mol_tree2 object.

What am I doing wrong here?

blokhin avatar Oct 29 '23 16:10 blokhin

Try this:

console.log(
	Tree.$mol_tree2_to_json(
		Tree.$mol_tree2_from_string(`
			* article *
				title \\Hello world
				description \\
					\\This is demo of tree-format
					\\Cool! Is not it? :-)
		`)
	)
);

I also updated the documentation, I think it's clearer now

nin-jin avatar Nov 02 '23 16:11 nin-jin

@nin-jin OK, thanks, that was quite an unexpected change, I should admit. My second example was copied from https://github.com/nin-jin/tree.d (it's still there!). Should I always escape \ with \\ ?

blokhin avatar Nov 06 '23 14:11 blokhin

BTW please let me recommend raising an error for my first example (there's still an empty output in [email protected]). It's taken from https://github.com/hyoo-ru/mam_mol/tree/master/tree2

blokhin avatar Nov 06 '23 14:11 blokhin

@nin-jin OK, thanks, that was quite an unexpected change, I should admit. My second example was copied from https://github.com/nin-jin/tree.d (it's still there!). Should I always escape \ with \\ ?

Always in js string literals of course.

nin-jin avatar Nov 06 '23 21:11 nin-jin