1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
|
{-------------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: SynExportHTML.pas, released 2000-04-16.
The Original Code is partly based on the mwHTMLExport.pas file from the
mwEdit component suite by Martin Waldenburg and other developers, the Initial
Author of this file is Michael Hieke.
Portions created by Michael Hieke are Copyright 2000 Michael Hieke.
Portions created by James D. Jacobson are Copyright 1999 Martin Waldenburg.
All Rights Reserved.
Contributors to the SynEdit project are listed in the Contributors.txt file.
Alternatively, the contents of this file may be used under the terms of the
GNU General Public License Version 2 or later (the "GPL"), in which case
the provisions of the GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms
of the GPL and not to allow others to use your version of this file
under the MPL, indicate your decision by deleting the provisions above and
replace them with the notice and other provisions required by the GPL.
If you do not delete the provisions above, a recipient may use your version
of this file under either the MPL or the GPL.
$Id: synexporthtml.pas 53363 2016-11-12 16:33:33Z bart $
You may retrieve the latest version of this file at the SynEdit home page,
located at http://SynEdit.SourceForge.net
Known Issues:
-------------------------------------------------------------------------------}
unit SynExportHTML;
{$I synedit.inc}
{.$define debug_synexporthtml}
interface
uses
Classes,
LCLIntf, LCLType, Graphics, ClipBrd,
SynEditHighlighter, SynEditExport, LCLProc, LazUtf8;
type
THTMLFontSize = (fs01, fs02, fs03, fs04, fs05, fs06, fs07, fsDefault); //eb 2000-10-12
TExportHtmlOption = (
heoFragmentOnly, //no surrounding <html><body>...</body><html> Note: will exclude heoDoctype, heoCharset
heoDoctype, //add doctype declaration
heoCharset, //add charset (UTF-8) information
heoWinClipHeader //add Clipboard header (affects Windows only) Note: cannot be set if ExportAsText = True!
);
TExportHtmlOptions = set of TExportHtmlOption;
{ TSynExporterHTML }
TSynExporterHTML = class(TSynCustomExporter)
private
fOptions: TExportHtmlOptions;
fFontSize: THTMLFontSize;
procedure SetExportHtmlOptions(Value: TExportHtmlOptions);
function GetCreateHTMLFragment: Boolean;
procedure SetCreateHTMLFragment(Value: Boolean);
function MakeFontSpan(FG, BG: TColor): String;
function StyleToHtml(AStyle: TFontStyles; IsSpace, DoSet: Boolean): String;
protected
procedure FormatAfterLastAttribute; override;
procedure FormatAttributeDone(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles); override;
procedure FormatAttributeInit(BackgroundChanged, ForegroundChanged: boolean;
FontStylesChanged: TFontStyles); override;
{begin} //mh 2000-10-10
procedure FormatBeforeFirstAttribute(BackgroundChanged,
ForegroundChanged: boolean; FontStylesChanged: TFontStyles); override;
{end} //mh 2000-10-10
procedure FormatBeforeFirstAttributeImmediate(BG, FG: TColor); override;
procedure FormatAfterLastAttributeImmediate; override;
procedure FormatAttributeInitImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); override;
procedure FormatAttributeDoneImmediate(Attri: TSynHighlighterAttributes; IsSpace: Boolean); override;
procedure FormatNewLine; override;
function GetFooter: string; override;
function GetFormatName: string; override;
function GetHeader: string; override;
procedure SetExportAsText(Value: boolean); override;
public
constructor Create(AOwner: TComponent); override;
published
property Color;
property CreateHTMLFragment: boolean read GetCreateHTMLFragment
write SetCreateHTMLFragment default FALSE; deprecated 'Use Options instead';
property DefaultFilter;
property Options: TExportHtmlOptions read fOptions write SetExportHtmlOptions default [heoDoctype, heoCharset];
property Font;
property Highlighter;
property HTMLFontSize: THTMLFontSize read fFontSize write fFontSize; //eb 2000-10-12
property Title;
property UseBackground;
end;
function ColorToHTML(AColor: TColor): string;
implementation
uses
SysUtils,
SynEditStrConst;
const
DocType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"' + LineEnding +
'"http://www.w3.org/TR/html4/loose.dtd">'; //cannot use strict, because we use <font> tag
Generator = '<meta name="generator" content="Lazarus SynEdit Html Exporter">';
CharSet = '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
DocumentStart = '<html>'+LineEnding+
'<head>'+LineEnding+
'%s'+LineEnding+
'</head>'+LineEnding+
'<body text="%s" bgcolor="%s">';
DocumentEnd = '</body>'+LineEnding+'</html>';
CodeStart = '<pre><code>';
CodeEnd = '</code></pre>';
FontStart = '<font %s face="%s">';
FontEnd = '</font>';
WinClipHeaderFmt = 'Version:0.9' + LineEnding +
'StartHTML:%.8d' + LineEnding +
'EndHTML:%.8d' + LineEnding +
'StartFragment:%.8d' + LineEnding +
'EndFragment:%.8d' + LineEnding;
StartFragmentComment = '<!--StartFragment-->';
EndFragmentComment = '<!--EndFragment-->';
function ColorToHTML(AColor: TColor): string;
var
RGBColor: TColorRef;
RGBValue: byte;
const
Digits: array[0..15] of char = '0123456789ABCDEF';
begin
Result := '';
case AColor of
clRed: Result := 'red';
clGreen: Result := 'green';
clBlue: Result := 'blue';
clPurple: Result := 'purple';
clYellow: Result := 'yellow';
clBlack: Result := 'black';
clWhite: Result := 'white';
clGray: Result := 'gray';
clMaroon: Result := 'maroon';
clFuchsia: Result := 'fuchsia';
clLime: Result := 'lime';
clNavy: Result := 'navy';
clAqua: Result := 'aqua';
clTeal: Result := 'teal';
clSilver: Result := 'silver';
end;
if (Result <> '') then
Exit;
RGBColor := ColorToRGB(AColor);
Result := '#000000';
{****************}
RGBValue := GetRValue(RGBColor);
if RGBValue > 0 then begin
Result[2] := Digits[RGBValue shr 4];
Result[3] := Digits[RGBValue and 15];
end;
{****************}
RGBValue := GetGValue(RGBColor);
if RGBValue > 0 then begin
Result[4] := Digits[RGBValue shr 4];
Result[5] := Digits[RGBValue and 15];
end;
{****************}
RGBValue := GetBValue(RGBColor);
if RGBValue > 0 then begin
Result[6] := Digits[RGBValue shr 4];
Result[7] := Digits[RGBValue and 15];
end;
end;
{ TSynExporterHTML }
constructor TSynExporterHTML.Create(AOwner: TComponent);
const
HTML_Format = {$ifdef windows}'HTML Format'{$else}'text/html'{$endif};
begin
inherited Create(AOwner);
{**************}
fClipboardFormat := RegisterClipboardFormat(HTML_Format);
fFontSize := fs03;
fOptions := [heoDocType, heoCharset];
fDefaultFilter := SYNS_FilterHTML;
// setup array of chars to be replaced
fReplaceReserved['&'] := '&';
fReplaceReserved['<'] := '<';
fReplaceReserved['>'] := '>';
//fReplaceReserved['"'] := '"'; //no need to replace this
//fReplaceReserved[''''] := '''; //no need to replace this
{ The following characters are multi-byte in UTF-8:
fReplaceReserved['™'] := '™';
fReplaceReserved['©'] := '©';
fReplaceReserved['®'] := '®';
fReplaceReserved['À'] := 'À';
fReplaceReserved['Á'] := 'Á';
fReplaceReserved['Â'] := 'Â';
fReplaceReserved['Ã'] := 'Ã';
fReplaceReserved['Ä'] := 'Ä';
fReplaceReserved['Å'] := 'Å';
fReplaceReserved['Æ'] := 'Æ';
fReplaceReserved['Ç'] := 'Ç';
fReplaceReserved['È'] := 'È';
fReplaceReserved['É'] := 'É';
fReplaceReserved['Ê'] := 'Ê';
fReplaceReserved['Ë'] := 'Ë';
fReplaceReserved['Ì'] := 'Ì';
fReplaceReserved['Í'] := 'Í';
fReplaceReserved['Î'] := 'Î';
fReplaceReserved['Ï'] := 'Ï';
fReplaceReserved['Ð'] := 'Ð';
fReplaceReserved['Ñ'] := 'Ñ';
fReplaceReserved['Ò'] := 'Ò';
fReplaceReserved['Ó'] := 'Ó';
fReplaceReserved['Ô'] := 'Ô';
fReplaceReserved['Õ'] := 'Õ';
fReplaceReserved['Ö'] := 'Ö';
fReplaceReserved['Ø'] := 'Ø';
fReplaceReserved['Ù'] := 'Ù';
fReplaceReserved['Ú'] := 'Ú';
fReplaceReserved['Û'] := 'Û';
fReplaceReserved['Ü'] := 'Ü';
fReplaceReserved['Ý'] := 'Ý';
fReplaceReserved['Þ'] := 'Þ';
fReplaceReserved['ß'] := 'ß';
fReplaceReserved['à'] := 'à';
fReplaceReserved['á'] := 'á';
fReplaceReserved['â'] := 'â';
fReplaceReserved['ã'] := 'ã';
fReplaceReserved['ä'] := 'ä';
fReplaceReserved['å'] := 'å';
fReplaceReserved['æ'] := 'æ';
fReplaceReserved['ç'] := 'ç';
fReplaceReserved['è'] := 'è';
fReplaceReserved['é'] := 'é';
fReplaceReserved['ê'] := 'ê';
fReplaceReserved['ë'] := 'ë';
fReplaceReserved['ì'] := 'ì';
fReplaceReserved['í'] := 'í';
fReplaceReserved['î'] := 'î';
fReplaceReserved['ï'] := 'ï';
fReplaceReserved['ð'] := 'ð';
fReplaceReserved['ñ'] := 'ñ';
fReplaceReserved['ò'] := 'ò';
fReplaceReserved['ó'] := 'ó';
fReplaceReserved['ô'] := 'ô';
fReplaceReserved['õ'] := 'õ';
fReplaceReserved['ö'] := 'ö';
fReplaceReserved['ø'] := 'ø';
fReplaceReserved['ù'] := 'ù';
fReplaceReserved['ú'] := 'ú';
fReplaceReserved['û'] := 'û';
fReplaceReserved['ü'] := 'ü';
fReplaceReserved['ý'] := 'ý';
fReplaceReserved['þ'] := 'þ';
fReplaceReserved['ÿ'] := 'ÿ';
fReplaceReserved['¡'] := '¡';
fReplaceReserved['¢'] := '¢';
fReplaceReserved['£'] := '£';
fReplaceReserved['¤'] := '¤';
fReplaceReserved['¥'] := '¥';
fReplaceReserved['¦'] := '¦';
fReplaceReserved['§'] := '§';
fReplaceReserved['¨'] := '¨';
fReplaceReserved['ª'] := 'ª';
fReplaceReserved['«'] := '«';
fReplaceReserved['¬'] := '­';
fReplaceReserved['¯'] := '¯';
fReplaceReserved['°'] := '°';
fReplaceReserved['±'] := '±';
fReplaceReserved['²'] := '²';
fReplaceReserved['³'] := '³';
fReplaceReserved['´'] := '´';
fReplaceReserved['µ'] := 'µ';
fReplaceReserved['·'] := '·';
fReplaceReserved['¸'] := '¸';
fReplaceReserved['¹'] := '¹';
fReplaceReserved['º'] := 'º';
fReplaceReserved['»'] := '»';
fReplaceReserved['¼'] := '¼';
fReplaceReserved['½'] := '½';
fReplaceReserved['¾'] := '¾';
fReplaceReserved['¿'] := '¿';
fReplaceReserved['×'] := '×';
fReplaceReserved['÷'] := '÷';
fReplaceReserved['€'] := '€';}
end;
procedure TSynExporterHTML.FormatAfterLastAttribute;
begin
if fsStrikeout in fLastStyle then
AddData('</strike>');
if fsUnderline in fLastStyle then
AddData('</u>');
if fsItalic in fLastStyle then
AddData('</i>');
if fsBold in fLastStyle then
AddData('</b>');
if fLastFG <> fFont.Color then
AddData('</font>');
if UseBackground and (fLastBG <> fBackgroundColor) then
AddData('</span>');
end;
procedure TSynExporterHTML.FormatAttributeDone(BackgroundChanged,
ForegroundChanged: boolean; FontStylesChanged: TFontStyles);
begin
if BackgroundChanged or ForegroundChanged or (FontStylesChanged <> []) then
begin
if fsStrikeout in fLastStyle then
AddData('</strike>');
if fsUnderline in fLastStyle then
AddData('</u>');
if fsItalic in fLastStyle then
AddData('</i>');
if fsBold in fLastStyle then
AddData('</b>');
end;
if (BackgroundChanged or ForegroundChanged) and (fLastFG <> fFont.Color) then //mh 2000-10-10
AddData('</font>');
if BackgroundChanged then
AddData('</span>');
end;
procedure TSynExporterHTML.FormatAttributeInit(BackgroundChanged,
ForegroundChanged: boolean; FontStylesChanged: TFontStyles);
begin
if BackgroundChanged then
AddData('<span style="background-color: ' +
ColorToHtml(fLastBG) {Copy(ColorToHtml(fLastBG), 2, 9)} + '>');
if (BackgroundChanged or ForegroundChanged) and (fLastFG <> fFont.Color) then
AddData('<font color="' + ColorToHtml(fLastFG) + '">');
if BackgroundChanged or ForegroundChanged or (FontStylesChanged <> []) then
begin
if fsBold in fLastStyle then
AddData('<b>');
if fsItalic in fLastStyle then
AddData('<i>');
if fsUnderline in fLastStyle then
AddData('<u>');
if fsStrikeout in fLastStyle then
AddData('<strike>');
end;
end;
{begin} //mh 2000-10-10
procedure TSynExporterHTML.FormatBeforeFirstAttribute(BackgroundChanged,
ForegroundChanged: boolean; FontStylesChanged: TFontStyles);
begin
if BackgroundChanged then
AddData('<span style="background-color: ' +
ColorToHtml(fLastBG) {Copy(ColorToHtml(fLastBG), 2, 9)} + '>');
AddData('<font color="' + ColorToHtml(fLastFG) + '">');
if FontStylesChanged <> [] then begin
if fsBold in fLastStyle then
AddData('<b>');
if fsItalic in fLastStyle then
AddData('<i>');
if fsUnderline in fLastStyle then
AddData('<u>');
if fsStrikeout in fLastStyle then
AddData('<strike>');
end;
end;
procedure TSynExporterHTML.FormatBeforeFirstAttributeImmediate(BG, FG: TColor);
var
Span: String;
begin
{$ifdef debug_synexporthtml}
debugln(['TSynExporterHTML.FormatBeforeFirstAttributeImmediate']);
{$endif}
// if not heoFragmentOnly this is handled in GetHeader
if (heoFragmentOnly in Options) then
begin
Span := MakeFontSpan(FG, BG);
AddData(Span);
end;
end;
procedure TSynExporterHTML.FormatAfterLastAttributeImmediate;
begin
{$ifdef debug_synexporthtml}
debugln(['TSynExporterHTML.FormatAfterLastAttributeImmediate']);
{$endif}
if (heoFragmentOnly in Options) then
AddData('</span>');
end;
procedure TSynExporterHTML.FormatAttributeInitImmediate(
Attri: TSynHighlighterAttributes; IsSpace: Boolean);
var
Span, StyleStr: String;
FG, BG: TColor;
begin
{$ifdef debug_synexporthtml}
debugln(['TSynExporterHTML.FormatAttributeInitImmediate']);
{$endif}
FG := ValidatedColor(Attri.Foreground, fFont.Color);
BG := ValidatedColor(Attri.Background, fBackgroundColor);
if (not IsSpace and (FG <> fFont.Color)) or
(UseBackGround and (BG <> fbackGroundColor)) then
begin
Span := MakeFontSpan(FG, BG);
AddData(Span);
end;
if (Attri.Style <> []) then
begin
StyleStr := StyleToHtml(Attri.Style, IsSpace, True);
AddData(StyleStr);
end;
end;
procedure TSynExporterHTML.FormatAttributeDoneImmediate(
Attri: TSynHighlighterAttributes; IsSpace: Boolean);
var
FG, BG: TColor;
StyleStr: String;
begin
{$ifdef debug_synexporthtml}
debugln(['TSynExporterHTML.FormatAttributeDoneImmediate']);
{$endif}
//reversed order compared to FormatAttributeInitImmediate
if (Attri.Style <> []) then
begin
StyleStr := StyleToHtml(Attri.Style, IsSpace, False);
AddData(StyleStr);
end;
FG := ValidatedColor(Attri.Foreground, fFont.Color);
BG := ValidatedColor(Attri.Background, fBackgroundColor);
if (not IsSpace and (FG <> fFont.Color)) or
(UseBackGround and (BG <> fbackGroundColor)) then
begin
AddData('</span>');
end;
end;
{end} //mh 2000-10-10
procedure TSynExporterHTML.FormatNewLine;
begin
AddNewLine;
end;
function TSynExporterHTML.GetFooter: string;
begin
Result := FontEnd + LineEnding + CodeEnd;
if (heoWinClipHeader in Options) then
Result := Result + EndFragmentComment;
if not (heoFragmentOnly in Options) then
begin
if (Result <> '') then Result := Result + LineEnding;
Result := Result + DocumentEnd;
end;
end;
function TSynExporterHTML.GetFormatName: string;
begin
Result := SYNS_ExporterFormatHTML;
end;
function TSynExporterHTML.GetHeader: string;
var
sFontSize: string; //eb 2000-10-12
DocHeader, HeadText, WinClipHeader, SFooter: String;
WinClipHeaderSize, FooterLen: Integer;
begin
Result := '';
DocHeader := '';
if not (heoFragmentOnly in Options) then
begin
if (heoDocType in fOptions) then
DocHeader := DocHeader + DocType + LineEnding;
HeadText := Generator;
if (heoCharSet in fOptions) then
HeadText := HeadText + LineEnding + CharSet;
HeadText := HeadText + LineEnding + Format('<title>%s</title>',[Title]);
DocHeader := DocHeader + Format(DocumentStart,[HeadText,ColorToHtml(fFont.Color),ColorToHTML(fBackgroundColor)]);
if (heoWinClipHeader in fOptions) then
DocHeader := DocHeader + LineEnding + StartFragmentComment;
DocHeader := DocHeader + CodeStart; //Don't add LineEndings after this point, because of <pre> tag
end //not heoFragmentOnly
else
begin
if (heoWinClipHeader in fOptions) then
DocHeader := DocHeader + StartFragmentComment + CodeStart
else
DocHeader := DocHeader + CodeStart;
end;
if fFontSize <> fsDefault then
sFontSize := Format(' size=%d', [1 + Ord(fFontSize)])
else
sFontSize := '';
DocHeader := DocHeader + Format(FontStart,[sFontSize, fFont.Name]);
if (heoWinClipHeader in fOptions) then
begin
WinClipHeaderSize := Length(Format(WinClipHeaderFmt,[0,0,0,0]));
SFooter := GetFooter;
FooterLen := Length(SFooter);
{$ifdef debug_synexporthtml}
debugln(['TSynExporterHtml.GetHeader: WinClipHeaderSize=',WinClipHeadersize]);
debugln([' Footer="',Sfooter,'"']);
debugln([' FooterLen=',FooterLen]);
debugln([' BufferSize=',getBufferSize]);
debugln([' length(docHeader)=',length(docheader)]);
{$endif}
// Described in http://msdn.microsoft.com/library/sdkdoc/htmlclip/htmlclipboard.htm
WinClipHeader := Format(WinClipHeaderFmt,
[WinClipHeaderSize, //HtmlStart
WinClipHeaderSize + Length(DocHeader) + FooterLen + GetBufferSize - 1, //HtmlEnd
WinClipHeaderSize + Utf8Pos(StartFragmentComment, DocHeader) + Length(StartfragmentComment) - 1, //StartFragment
WinClipHeaderSize + Length(DocHeader) + Utf8Pos(EndFragmentComment, SFooter) + GetBufferSize - 1 //EndFragment
]);
DocHeader := WinClipHeader + DocHeader;
end;
Result := DocHeader;
end;
procedure TSynExporterHTML.SetExportAsText(Value: boolean);
begin
if (Value <> ExportAsText) then
begin
inherited SetExportAsText(Value);
if Value then
fOptions := fOptions - [heoWinClipHeader];
end;
end;
procedure TSynExporterHTML.SetExportHtmlOptions(Value: TExportHtmlOptions);
begin
if (fOptions <> Value) then
begin
Clear;
fOptions := Value;
if ExportAsText then fOptions := fOptions - [heoWinClipHeader];
if (heoFragmentOnly in Value) then
begin
fOptions := fOptions - [heoDoctype, heoCharSet];
end;
end;
end;
function TSynExporterHTML.GetCreateHTMLFragment: Boolean;
begin
Result := (heoFragmentOnly in fOptions);
end;
procedure TSynExporterHTML.SetCreateHTMLFragment(Value: Boolean);
begin
if (GetCreateHTMLFragment <> Value) then
begin
if Value then
Options := Options + [heoFragmentOnly]
else
Options := Options - [heoFragmentOnly];
end;
end;
function TSynExporterHTML.MakeFontSpan(FG, BG: TColor): String;
begin
Result := '<span style="color: ';
FG := ValidatedColor(FG, fFont.Color);
Result := Result + ColorToHtml(FG);
BG := ValidatedColor(BG, fBackgroundColor);
if UseBackGround then
begin
Result := Result + '; background-color: ' + ColorToHtml(BG);
end;
Result := Result + ';">';
end;
function TSynExporterHTML.StyleToHtml(AStyle: TFontStyles; IsSpace, DoSet: Boolean): String;
begin
Result := '';
if DoSet then
begin
if not IsSpace then
begin
if (fsBold in AStyle) then Result := Result + '<b>';
if (fsItalic in AStyle) then Result := Result + '<i>';
if (fsUnderline in AStyle) then Result := Result + '<u>';
end;
//the only style that actually is applied to whitespace in HTML
if (fsStrikeOut in AStyle) then Result := Result + '<strike>';
end
else
begin //unset in the opposite order as set
if (fsStrikeOut in AStyle) then Result := Result + '</strike>';
if not IsSpace then
begin
if (fsUnderline in AStyle) then Result := Result + '</u>';
if (fsItalic in AStyle) then Result := Result + '</i>';
if (fsBold in AStyle) then Result := Result + '</b>';
end;
end;
end;
end.
|