This line should be removed, as it is removing the hyphen

wikislug = slug.replace(/\-/g, " "); Should not be there, its removing the hyphen and converting it back to a space, which then gets removed by the line after.