factor out html preprocessing stuff