src/Pure/PIDE/xml.ML
changeset 74789 a5c23da73fca
parent 74785 4671d29feb00
equal deleted inserted replaced
74788:95e514137861 74789:a5c23da73fca
    32   type attributes = (string * string) list
    32   type attributes = (string * string) list
    33   datatype tree =
    33   datatype tree =
    34       Elem of (string * attributes) * tree list
    34       Elem of (string * attributes) * tree list
    35     | Text of string
    35     | Text of string
    36   type body = tree list
    36   type body = tree list
    37   val string: string -> body
       
    38   val blob: string list -> body
    37   val blob: string list -> body
    39   val is_empty: tree -> bool
    38   val is_empty: tree -> bool
    40   val is_empty_body: body -> bool
    39   val is_empty_body: body -> bool
       
    40   val string: string -> body
       
    41   val enclose: string -> string -> body -> body
    41   val xml_elemN: string
    42   val xml_elemN: string
    42   val xml_nameN: string
    43   val xml_nameN: string
    43   val xml_bodyN: string
    44   val xml_bodyN: string
    44   val wrap_elem: ((string * attributes) * tree list) * tree list -> tree
    45   val wrap_elem: ((string * attributes) * tree list) * tree list -> tree
    45   val unwrap_elem: tree -> (((string * attributes) * tree list) * tree list) option
    46   val unwrap_elem: tree -> (((string * attributes) * tree list) * tree list) option
    76 
    77 
    77 (** XML trees **)
    78 (** XML trees **)
    78 
    79 
    79 open Output_Primitives.XML;
    80 open Output_Primitives.XML;
    80 
    81 
       
    82 val blob = map Text;
       
    83 
       
    84 fun is_empty (Text "") = true
       
    85   | is_empty _ = false;
       
    86 
       
    87 val is_empty_body = forall is_empty;
       
    88 
    81 fun string "" = []
    89 fun string "" = []
    82   | string s = [Text s];
    90   | string s = [Text s];
    83 
    91 
    84 val blob = map Text;
    92 fun enclose bg en body = string bg @ body @ string en;
    85 
       
    86 fun is_empty (Text "") = true
       
    87   | is_empty _ = false;
       
    88 
       
    89 val is_empty_body = forall is_empty;
       
    90 
    93 
    91 
    94 
    92 (* wrapped elements *)
    95 (* wrapped elements *)
    93 
    96 
    94 val xml_elemN = "xml_elem";
    97 val xml_elemN = "xml_elem";
   155 fun elem name atts =
   158 fun elem name atts =
   156   space_implode " " (name :: map (fn (a, x) => a ^ "=\"" ^ text x ^ "\"") atts);
   159   space_implode " " (name :: map (fn (a, x) => a ^ "=\"" ^ text x ^ "\"") atts);
   157 
   160 
   158 fun element name atts body =
   161 fun element name atts body =
   159   let val b = implode body in
   162   let val b = implode body in
   160     if b = "" then enclose "<" "/>" (elem name atts)
   163     if b = "" then Library.enclose "<" "/>" (elem name atts)
   161     else enclose "<" ">" (elem name atts) ^ b ^ enclose "</" ">" name
   164     else Library.enclose "<" ">" (elem name atts) ^ b ^ Library.enclose "</" ">" name
   162   end;
   165   end;
   163 
   166 
   164 fun output_markup (markup as (name, atts)) =
   167 fun output_markup (markup as (name, atts)) =
   165   if Markup.is_empty markup then Markup.no_output
   168   if Markup.is_empty markup then Markup.no_output
   166   else (enclose "<" ">" (elem name atts), enclose "</" ">" name);
   169   else (Library.enclose "<" ">" (elem name atts), Library.enclose "</" ">" name);
   167 
   170 
   168 
   171 
   169 (* output content *)
   172 (* output content *)
   170 
   173 
   171 fun content_depth depth =
   174 fun content_depth depth =