Nanoribbon edges of transition-metal dichalcogenides: Stability and electronic properties