Prototype

property OnSyntaxHighlighting: TSyntaxHighlightingEvent read FOnSyntaxHighlighting write SetOnSyntaxHighlighting;

Description

Occurs when a block of code needs to be highlighted.


aLanguage contains the language defined in the script if any. FIll aStyles either with presets or create your own.

if OnSyntaxHighlighting returns an empty list and the control is associated with a TMDStyle, TMDStyle.OnSyntaxHighlighting is invoked.

Example

uses Markdown.SyntaxHighlights;

procedure TForm1.MDStyle1SyntaxHighlighting(Sender: TObject; const aLanguage: string; var aStyles: TMDSyntaxStyles);
begin
  // Pascal or Delphi presets
  if MatchText(aLanguage, ['Pascal', 'Delphi']) then
    aStyles := TMDSyntax.Pascal(MDStyle1.Mode)

  // JSon presets
  else if SameText(aLanguage, 'JSon') then
    aStyles := TMDSyntax.JSon(MDStyle1.Mode)

  // Ini presets
  else if SameText(aLanguage, 'Ini') then
    aStyles := TMDSyntax.Ini(MDStyle1.Mode)

  // Custom
  else
    aStyles := [
      // Reserved words
      TMDSyntaxStyle.Create('\b(?>hello|world)\b', IfThen(MDStyle1.Mode = smDark, $bce0ff, clNavy), [fsBold]),
      // IP addresses
      TMDSyntaxStyle.Create('\b(?>(25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}\g<1>\b', IfThen(MDStyle1.Mode = smDark, $84e7bc, clGreen))
      // and so on!
    ];
end;

See also

TSyntaxHighlightingEvent

TMDSyntax

TMDSyntaxStyle

TMDStyle.OnSyntaxHighlighting