Markdown on Firemonkey version ?

General TRichView support forum. Please post your questions here
Post Reply
Fab85
Posts: 9
Joined: Tue Apr 09, 2024 6:02 am

Markdown on Firemonkey version ?

Post by Fab85 »

Hello,

Test in version 22.4.
Markdown work fine under VCL but not with Firemonkey = TrichView FMX (On Windows) ?

How to reproduce ?
1) Try demo called "RichViewEdit demo" (in Demos\Delphi.FMX\Editors\Editor 1).
2) Try open a markdown file -> It will be displayed like a text file...
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Markdown on Firemonkey version ?

Post by Sergey Tkachenko »

Markdown loading is identical in VCL and FireMonkey version. The problem is in distinguishing text and markdown files.

In VCL, the program can use the open dialog's FilterIndex property to know which format is chosen.
In FireMonkey, it cannot (this property cannot be used). So, the demo recognizes the file format by the file extension.
On desktop OS, FireMonkey demo uses the following function to recognize format:

Code: Select all

function GetFileOpenFormat(const FileName: String): TRVLoadFormat;
var
  Ext: String;
begin
  Ext := ExtractFileExt(FileName).ToLower;
  if Ext = '.rvf' then
    Result := rvlfRVF
  else if Ext = '.rtf' then
    Result := rvlfRTF
  else if Ext = '.docx' then
    Result := rvlfDocX
  else if Pos('htm', Ext) <> 0 then
    Result := rvlfHTML
  else if (Ext = '*.markdown') or (Ext = '*.mdown') or (Ext = '*.mkdn') or
    (Ext = '*.md') or (Ext = '*.mkd') or (Ext = '*.mdwn') or (Ext = '*.mdtxt') then
    Result := rvlfMarkdown
  else
    Result := rvlfText;
end;
As you can see, Markdown is loaded only if the file extension is one of: markdown, mdown, mkdn, md, mkd, mdwn, mdtxt.
Fab85
Posts: 9
Joined: Tue Apr 09, 2024 6:02 am

Re: Markdown on Firemonkey version ?

Post by Fab85 »

Hello Sergey,


Sorry I was using your Demos\Delphi.FMX\Editors\Editor 2 which doesn't work !
With you answer certainly because your code is not correct is this demo :

Code: Select all

function GetFileFormatByFileName(const FileName: String): TRVSaveFormat;
var
  Ext: String;
begin
  Ext := ExtractFileExt(FileName).ToLower;
  if Ext = '.rvf' then
    Result := rvsfRVF
  else if Ext = '.rtf' then
    Result := rvsfRTF
  else if Ext = '.docx' then
    Result := rvsfDocX
  else if (Ext = '.htm') or (Ext = '.html') then
    Result := rvsfHTML
  else if (Ext = '*.markdown') or (Ext = '*.mdown') or (Ext = '*.mkdn') or
    (Ext = '*.md') or (Ext = '*.mkd') or (Ext = '*.mdwn') or (Ext = '*.mdtxt') then
    Result := rvsfMarkdown
  else
    Result := rvsfText;
end;
Correct must be :

Code: Select all

function GetFileFormatByFileName(const FileName: String): TRVSaveFormat;
var
  Ext: String;
begin
  Ext := ExtractFileExt(FileName).ToLower;
  if Ext = '.rvf' then
    Result := rvsfRVF
  else if Ext = '.rtf' then
    Result := rvsfRTF
  else if Ext = '.docx' then
    Result := rvsfDocX
  else if (Ext = '.htm') or (Ext = '.html') then
    Result := rvsfHTML
  else if (Ext = '.markdown') or (Ext = '.mdown') or (Ext = '.mkdn') or
    (Ext = '.md') or (Ext = '.mkd') or (Ext = '.mdwn') or (Ext = '.mdtxt') then
    Result := rvsfMarkdown
  else
    Result := rvsfText;
end;
'*.md' -> '.md'
etc.
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Markdown on Firemonkey version ?

Post by Sergey Tkachenko »

Thank you!
I'll fix the demos in the next update.
Post Reply