Add a GMarkupParseFlags flag for treating CDATA as text.
authorMatthias Clasen <mclasen@redhat.com>
Mon, 29 May 2006 00:08:30 +0000 (00:08 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 29 May 2006 00:08:30 +0000 (00:08 +0000)
2006-05-28  Matthias Clasen  <mclasen@redhat.com>

* glib/gmarkup.h: Add a GMarkupParseFlags flag for
treating CDATA as text.

* glib/gmarkup.c (g_markup_parse_context_parse):
Implement it here.

ChangeLog
ChangeLog.pre-2-12
docs/reference/ChangeLog
docs/reference/glib/tmpl/markup.sgml
glib/gmarkup.c
glib/gmarkup.h

index fb1f1cc..acd1574 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2006-05-28  Matthias Clasen  <mclasen@redhat.com>
 
+       * glib/gmarkup.h: Add a GMarkupParseFlags flag for
+       treating CDATA as text. 
+
+       * glib/gmarkup.c (g_markup_parse_context_parse): 
+       Implement it here.
+
+2006-05-28  Matthias Clasen  <mclasen@redhat.com>
+
        * tests/markups/expected-*: Output that test-markup
        is expected to produce when run on the valid gmarkup 
        examples.
index fb1f1cc..acd1574 100644 (file)
@@ -1,5 +1,13 @@
 2006-05-28  Matthias Clasen  <mclasen@redhat.com>
 
+       * glib/gmarkup.h: Add a GMarkupParseFlags flag for
+       treating CDATA as text. 
+
+       * glib/gmarkup.c (g_markup_parse_context_parse): 
+       Implement it here.
+
+2006-05-28  Matthias Clasen  <mclasen@redhat.com>
+
        * tests/markups/expected-*: Output that test-markup
        is expected to produce when run on the valid gmarkup 
        examples.
index b8b1f6f..3f3870a 100644 (file)
@@ -1,3 +1,7 @@
+2006-05-28  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/tmpl/markup.sgml: Document G_MARKUP_TREAT_CDATA_AS_TEXT.
+
 2006-05-16  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib-sections.txt: Add g_ascii_strtoll
index c14026f..29e8efe 100644 (file)
@@ -115,11 +115,16 @@ error domains.
 
 <!-- ##### ENUM GMarkupParseFlags ##### -->
 <para>
-There are no flags right now. Pass "0" for the flags argument to all 
-functions.
+Flags that affect the behaviour of the parser. 
 </para>
 
 @G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use.
+@G_MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked
+  sections are not passed literally to the @passthrough function of
+  the parser. Instead, the content of the section (without the 
+  <literal>&lt;![CDATA[</literal> and <literal>]]&gt;</literal>) is
+  passed to the @text function. This flag was added in GLib 2.12. 
+
 
 <!-- ##### STRUCT GMarkupParseContext ##### -->
 <para>
@@ -141,14 +146,22 @@ g_markup_parse_context_parse() will report that error back to its caller.
 </para>
 
 @start_element: Callback to invoke when the opening tag of an element
-is seen.
-@end_element: Callback to invoke when the closing tag of an element is seen
+    is seen.
+@end_element: Callback to invoke when the closing tag of an element is seen.
+    Note that this is also called for empty tags like 
+    <literal>&lt;empty/&gt;</literal>.
 @text: Callback to invoke when some text is seen (text is always
-inside an element)
-@passthrough: Callback to invoke for comments, processing
-instructions and doctype declarations; if you're re-writing the parsed document, write the
-passthrough text back out in the same position
-@error: Callback to invoke when an error occurs
+    inside an element). Note that the text of an element may be spread
+    over multiple calls of this function. If the %G_MARKUP_TREAT_CDATA_AS_TEXT
+    flag is set, this function is also called for the content of CDATA marked 
+    sections.
+@passthrough: Callback to invoke for comments, processing instructions 
+    and doctype declarations; if you're re-writing the parsed document, 
+    write the passthrough text back out in the same position. If the
+    %G_MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also 
+    called for CDATA marked sections.
+@error: Callback to invoke when an error occurs.
+
 
 <!-- ##### FUNCTION g_markup_escape_text ##### -->
 <para>
index fad05d2..484d448 100644 (file)
@@ -1646,7 +1646,7 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
               /* The passthrough hasn't necessarily ended. Merge with
                * partial chunk, leave state unchanged.
                */
-              add_to_partial (context, context->start, context->iter);
+               add_to_partial (context, context->start, context->iter);
             }
           else
             {
@@ -1660,7 +1660,18 @@ g_markup_parse_context_parse (GMarkupParseContext *context,
               advance_char (context); /* advance past close angle */
               add_to_partial (context, context->start, context->iter);
 
-              if (context->parser->passthrough)
+             if (context->flags & G_MARKUP_TREAT_CDATA_AS_TEXT &&
+                 g_str_has_prefix (context->partial_chunk->str, "<![CDATA[") &&
+                 g_str_has_suffix (context->partial_chunk->str, "]]>"))
+               {
+                 if (context->parser->text)
+                   (*context->parser->text) (context,
+                                             context->partial_chunk->str + strlen ("<![CDATA["),
+                                             context->partial_chunk->len - strlen ("<![CDATA[" "]]>"),
+                                             context->user_data,
+                                             &tmp_error);
+               }
+             else if (context->parser->passthrough)
                 (*context->parser->passthrough) (context,
                                                  context->partial_chunk->str,
                                                  context->partial_chunk->len,
index 47e3e87..b272d5c 100644 (file)
@@ -46,9 +46,8 @@ GQuark g_markup_error_quark (void);
 
 typedef enum
 {
-  /* Hmm, can't think of any at the moment */
-  G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0
-  
+  G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
+  G_MARKUP_TREAT_CDATA_AS_TEXT              = 1 << 1  
 } GMarkupParseFlags;
 
 typedef struct _GMarkupParseContext GMarkupParseContext;