I try to play TidyPas with Tnt Unicode control. I using GUI TidyDemo for testing. I replace Memo1 as TntMemo so that it can display WideString. When I click the 'Diagnose' button, TidyPas return a lot of invalid character code error such as:
1,51: Warnning: replacing invalid character code 150
It seems TidyPas not working well with UTF8 encode input string. Can you give me some suggestion please?
Cheers,
Tao
Here is my modified code:
In unit TidyForm.pas
procedure TForm1.SetOptions;
begin
Tidy1.OutputMode:=TidyOutputMode(ComboBox1.ItemIndex);
Tidy1.AccessibilityCheckLevel:=ComboBox2.ItemIndex;
Tidy1.AllowUnknownTags:=CheckBox1.Checked;
if CheckBox2.Checked then Tidy1.Indent:=2 else Tidy1.Indent:=0;
Tidy1.UppercaseTags:=CheckBox3.Checked;
Tidy1.UppercaseAttrs:=CheckBox4.Checked;
Tidy1.ForceOutput:=CheckBox5.Checked;
Tidy1.OutputBom := TidyAutoState;
Tidy1.CharEncoding := TidyUTF8; // Force UTF8 encoding
Tidy1.InCharEncoding := TidyUTF8;
Tidy1.OutCharEncoding := TidyUTF8;
end;
procedure TForm1.DiagnoseBtnClick(Sender: TObject);
begin
SetOptions;
ListBox1.Clear;
Tidy1.ParseString(System.UTF8Encode(Memo1.Lines.Text)); // Memo1.Lines.Text now is WideString
PageControl1.ActivePage:=TabSheet2;
end;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First thank you for your excellent work.
I try to play TidyPas with Tnt Unicode control. I using GUI TidyDemo for testing. I replace Memo1 as TntMemo so that it can display WideString. When I click the 'Diagnose' button, TidyPas return a lot of invalid character code error such as:
1,51: Warnning: replacing invalid character code 150
It seems TidyPas not working well with UTF8 encode input string. Can you give me some suggestion please?
Cheers,
Tao
Here is my modified code:
In unit TidyForm.pas
procedure TForm1.SetOptions;
begin
Tidy1.OutputMode:=TidyOutputMode(ComboBox1.ItemIndex);
Tidy1.AccessibilityCheckLevel:=ComboBox2.ItemIndex;
Tidy1.AllowUnknownTags:=CheckBox1.Checked;
if CheckBox2.Checked then Tidy1.Indent:=2 else Tidy1.Indent:=0;
Tidy1.UppercaseTags:=CheckBox3.Checked;
Tidy1.UppercaseAttrs:=CheckBox4.Checked;
Tidy1.ForceOutput:=CheckBox5.Checked;
Tidy1.OutputBom := TidyAutoState;
Tidy1.CharEncoding := TidyUTF8; // Force UTF8 encoding
Tidy1.InCharEncoding := TidyUTF8;
Tidy1.OutCharEncoding := TidyUTF8;
end;
procedure TForm1.DiagnoseBtnClick(Sender: TObject);
begin
SetOptions;
ListBox1.Clear;
Tidy1.ParseString(System.UTF8Encode(Memo1.Lines.Text)); // Memo1.Lines.Text now is WideString
PageControl1.ActivePage:=TabSheet2;
end;
Hello, Tao -
Yes, there is a bug when TidyPas tries to set encoding.
You should be able to work around it it by adding these
three lines at the end of the SetOptions procedure:
tidySetCharEncoding(Tidy1.Handle, 'utf8');
tidySetInCharEncoding(Tidy1.Handle,'utf8');
tidySetOutCharEncoding(Tidy1.Handle,'utf8');
Hope this helps,
- Jeff
Thank you very much, Jeff. It works great now!
Tao