@item Extended Preserve Space
This data category extends the standard @samp{Preserve Space} data
-category with the additional value @samp{trim}. The value means to
-remove the leading and trailing whitespaces of the content, but not to
-normalize whitespaces in the middle. In the global rule, the
-@code{preserveSpaceRule} element contains the following:
+category with the additional values @samp{trim} and @samp{paragraph}.
+@samp{trim} means to remove the leading and trailing whitespaces of the
+content, but not to normalize whitespaces in the middle.
+@samp{paragraph} means to normalize the content but keep the paragraph
+boundaries. In the global
+rule, the @code{preserveSpaceRule} element contains the following:
@itemize
@item
@item
A required @code{space} attribute with the value @code{default},
-@code{preserve}, or @code{trim}.
+@code{preserve}, @code{trim}, or @code{paragraph}.
@end itemize
@end table
case ITS_WHITESPACE_TRIM:
return trim (text);
+ case ITS_WHITESPACE_NORMALIZE_PARAGRAPH:
+ /* Normalize whitespaces within the text, keeping paragraph
+ boundaries. */
+ {
+ char *result, *p, *out;
+
+ result = trim (text);
+ for (p = out = result; *p != '\0';)
+ {
+ char *pp, *pend = NULL, *next = NULL;
+ bool last_ws = false;
+
+ /* Find a paragraph boundary. */
+ for (pp = p; *pp != '\0';)
+ {
+ char *nl = strchrnul (pp, '\n');
+ if (*nl == '\0')
+ {
+ pend = nl;
+ next = pend;
+ break;
+ }
+ pp = nl + 1;
+ pp += strspn (pp, " \t\n");
+ if (*pp == '\n')
+ {
+ pend = nl;
+ next = pp + 1;
+ break;
+ }
+ }
+
+ /* Normalize whitespaces in the paragraph. */
+ assert (pend != NULL);
+ for (pp = p; pp < pend; pp++)
+ if (!(*pp == ' ' || *pp == '\t' || *pp == '\n'))
+ break;
+ for (; pp < pend; pp++)
+ {
+ if (*pp == ' ' || *pp == '\t' || *pp == '\n')
+ {
+ if (!last_ws)
+ {
+ *out++ = ' ';
+ last_ws = true;
+ }
+ }
+ else
+ {
+ *out++ = *pp;
+ last_ws = false;
+ }
+ }
+ if (*pend != '\0')
+ {
+ memcpy (out, "\n\n", 2);
+ out += 2;
+ }
+ p = next;
+ }
+ *out = '\0';
+ return result;
+ }
default:
/* Normalize whitespaces within the text, but not at the beginning
nor the end of the text. */
|| strcmp (prop, "default") == 0
/* gettext extension: remove leading/trailing whitespaces only. */
|| (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
- && strcmp (prop, "trim") == 0)))
+ && strcmp (prop, "trim") == 0)
+ /* gettext extension: same as default except keeping
+ paragraph boundaries. */
+ || (node->ns && xmlStrEqual (node->ns->href, BAD_CAST GT_NS)
+ && strcmp (prop, "paragraph") == 0)))
{
error (0, 0, _("invalid attribute value \"%s\" for \"%s\""),
prop, "space");
whitespace = ITS_WHITESPACE_PRESERVE;
else if (value && strcmp (value, "trim") == 0)
whitespace = ITS_WHITESPACE_TRIM;
+ else if (value && strcmp (value, "paragraph") == 0)
+ whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
else
whitespace = ITS_WHITESPACE_NORMALIZE;
whitespace = ITS_WHITESPACE_PRESERVE;
else if (value && strcmp (value, "trim") == 0)
whitespace = ITS_WHITESPACE_TRIM;
+ else if (value && strcmp (value, "paragraph") == 0)
+ whitespace = ITS_WHITESPACE_NORMALIZE_PARAGRAPH;
else
whitespace = ITS_WHITESPACE_NORMALIZE;
<message unescaped="This is an unescaped attribute <>&"">
<p></p>
</message>
+ <message>
+ <p xml:space="paragraph">
+ This is the first paragraph with
+a newline.
+
+ This is the second paragprah with spaces.
+
+
+ This is the last paragraph.</p>
+ </message>
+ <message>
+ <p xml:space="paragraph">This is the only one paragraph</p>
+ </message>
+ <message>
+ <p xml:space="paragraph">This is the only one paragraph with a boundary
+
+</p>
+ </message>
+ <message>
+ <p xml:space="paragraph"></p>
+ </message>
+ <message>
+ <p xml:space="paragraph"> </p>
+ </message>
</messages>
EOF
#: messages.xml:61
msgid "This is an unescaped attribute <>&\""
msgstr ""
+
+#. (itstool) path: message/p
+#: messages.xml:65
+msgid ""
+"This is the first paragraph with a newline.\n"
+"\n"
+"This is the second paragprah with spaces.\n"
+"\n"
+"This is the last paragraph."
+msgstr ""
+
+#. (itstool) path: message/p
+#: messages.xml:75
+msgid "This is the only one paragraph"
+msgstr ""
+
+#. (itstool) path: message/p
+#: messages.xml:78
+msgid "This is the only one paragraph with a boundary"
+msgstr ""
EOF
: ${DIFF=diff}