Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior of $mol_tree2_to_json #649

Open
blokhin opened this issue Oct 29, 2023 · 4 comments
Open

Unexpected behavior of $mol_tree2_to_json #649

blokhin opened this issue Oct 29, 2023 · 4 comments

Comments

@blokhin
Copy link

blokhin commented Oct 29, 2023

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?

@nin-jin
Copy link
Member

nin-jin commented Nov 2, 2023

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

@blokhin
Copy link
Author

blokhin commented Nov 6, 2023

@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
Copy link
Author

blokhin commented Nov 6, 2023

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

@nin-jin
Copy link
Member

nin-jin commented Nov 6, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants