space_to_nbsp — replace all spaces (" ") with nonbreakable space (" ") characters


The filter replaces all space (" ") characters with HTML's nonbreakable-space (" ") characters.

This is useful for places where you want strings to appear in a single line, without word-wrapping to the next line.


Example: Filter example

<div style="width: 80px;">
This is a very   small DIV and will   surely word-wrap this text to multiple lines.
With the filter applied, however, it will force the DIV to stretch and            render as single line.

<div style="width: 80px;">
[filter space_to_nbsp]
With the filter        applied, however, it will force the DIV to stretch and render as single line.


Example: Filter example

[filter space_to_nbsp.compress]
Multiple    spaces    in a line   will render   as just   single  space.



In HTML, multiple spaces in a line render as just one space on the screen. When the spaces are converted to "&nbsp;", however, every nonbreakable space will produce one space character on the screen — it's how HTML works. Use the filter's compress when you want to preserve the behavior of only one space being visible on the screen.


space_to_nbsp is available in Interchange versions:

4.6.0-5.9.0 (git-head)


Interchange 5.9.0:

Source: code/Filter/space_to_nbsp.filter
Lines: 24

# Copyright 2002-2007 Interchange Development Group and others
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# $Id: space_to_nbsp.filter,v 1.3 2007-03-30 23:40:45 pajamian Exp $

CodeDef space_to_nbsp Filter
CodeDef space_to_nbsp Description All SPACE to nbsp
CodeDef space_to_nbsp Routine <<EOR
sub {
my ($str, $tag, $opt) = @_;

if ( $opt ) {
  $str =~ s/ +/&nbsp;/g;
} else {
  $str =~ s/ /&nbsp;/g;



Interchange Development Group


lspace_to_nbsp(7ic), space_to_null(7ic)

DocBook! Interchange!