I would do this by modifying the list to include the parent on every line, sorting and then removing the parent eg
Code:
animals
- cat
- dog
- monkey
plants
- grass
- tree
- shrubbery
becomes
Code:
animals
animals - cat
animals - dog
animals - monkey
plants
plants - grass
plants - tree
plants - shrubbery
This is easy to sort as one big group and then you can remove the parents where necessary