Page 1 of 1

Markdown on Firemonkey version ?

Posted: Tue Oct 15, 2024 10:48 am
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...

Re: Markdown on Firemonkey version ?

Posted: Tue Oct 15, 2024 6:07 pm
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.

Re: Markdown on Firemonkey version ?

Posted: Wed Oct 16, 2024 11:02 am
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.

Re: Markdown on Firemonkey version ?

Posted: Wed Oct 16, 2024 1:46 pm
by Sergey Tkachenko
Thank you!
I'll fix the demos in the next update.