Joplin works well for me, I started using it as an Evernote replacement half a year ago. It's open source, has markdown, syntax highlighting for many languages, comes with a mobile and desktop app and syncs via various services, e.g. Dropbox.
Mind you that the notebooks seem to be actually "categories".
One notebook can be dragged into another to create trees.