I haven't done any testing on this but since this works:

~~~irb
>> string = "First level              heading"
=> "First level              heading"
>> string.gsub(/ +/, "-")
=> "First-level-heading"
~~~

Maybe we could try:

~~~c
VALUE pattern = rb_str_new2(" +");
pattern = rb_reg_new_str(pattern, 0);
~~~

Not sure that it will work and if it's not too tricky.