Browse Source

*HTML writer: change charset in 'meta' tag (if any) to utf-8, because it is the encoding we actually write.

git-svn-id: trunk@13354 -
sergei 16 years ago
parent
commit
ccb730c051
1 changed files with 17 additions and 1 deletions
  1. 17 1
      packages/fcl-xml/src/htmwrite.pp

+ 17 - 1
packages/fcl-xml/src/htmwrite.pp

@@ -336,21 +336,37 @@ var
   s: string;
   ElFlags: THTMLElementFlags;
   j: THTMLElementTag;
+  meta: Boolean;
 begin
   if not FInsideTextNode then
     wrtIndent;
-    
+
+  meta := False;
   s := LowerCase(node.NodeName);
   ElFlags := [efSubelementContent, efPCDATAContent];    // default flags
   for j := Low(THTMLElementTag) to High(THTMLElementTag) do
     if HTMLElementProps[J].Name = s then
     begin
       ElFlags := HTMLElementProps[j].Flags;
+      if j = etMeta then
+        meta := True;
       break;
     end;
 
   wrtChr('<');
   wrtStr(TDOMElement(node).TagName);
+
+  { Force charset label to utf-8, because it is the encoding we actually write }
+  if meta then
+  begin
+    s := TDOMElement(node).GetAttribute('http-equiv');
+    if SameText(s, 'content-type') then
+    begin
+      wrtStr(' content="text/html; charset=utf-8" http-equiv="Content-Type">');
+      Exit;
+    end;
+  end;
+
   if node.HasAttributes then
     for i := 0 to node.Attributes.Length - 1 do
     begin