Page 1 of 1

Insert as Markdown ?

Posted: Mon Sep 07, 2026 3:59 pm
by Fab85
Hello,

A InsertText method exists.
There is also a InsertMarkdownFromStreamEd and a PasteMarkdown.

But what I need is to insert a text containing markdown (without using/overriding clipboard with PasteMarkdown) :
A function like InsertMarkdownText ?

I need this to insert a AI response markdown text by code...

Re: Insert as Markdown ?

Posted: Mon Sep 07, 2026 7:48 pm
by Sergey Tkachenko
You can save a string to stream and call InsertMarkdownFromStreamEd.
For simplicity, you can use the RVU_UnicodeStringToUTF8Stream function from RVUni.pas (fmxRVUni.pas in FireMonkey vesion):

Code: Select all

uses
  RVUni;

procedure InsertMarkdown(const S: UnicodeString; rve: TCustomRichViewEdit);
var
  Stream: TStream;
begin
  Stream := RVU_UnicodeStringToUTF8Stream(S);
  Stream.Position := 0;
  rv.InsertMarkdownFromStreamEd(Stream);
  Stream.Free;
end;

Re: Insert as Markdown ?

Posted: Tue Sep 08, 2026 10:18 am
by Fab85
Hello,

Thank you for your answer.

However, I have a small issue when inserting Markdown content into an existing RTF document, especially when the Markdown contains formatting such as bold text, headings, or numbered lists :
The font size does not seem to be consistent: some parts of the inserted text appear larger or smaller than others.

Currently, to fix this, I have to select the inserted Markdown text manually and force the font size, for example to 14 pt.

Do you know if there is a way to ensure that the inserted Markdown uses a consistent font size automatically?

Thank you for your help.

Re: Insert as Markdown ?

Posted: Tue Sep 08, 2026 11:59 am
by Sergey Tkachenko
Does your editor use style templates? (UseStyleTemplates property = True).
If yes, properties of certain style templates are applied on loading, such as 'Strong', 'Emphasis', 'HTML Code'. If these style templates have defined font size, it is applied to loaded text.

Re: Insert as Markdown ?

Posted: Wed Sep 09, 2026 4:25 pm
by Fab85
Does your editor use style templates? (UseStyleTemplates property = True).
Thank you for answer.

Does do this (disable UsestyleTemplate while inserting) is a good idea :

Code: Select all

Myrve.UseStyleTemplates:=false;
InsertMarkdown(MDClipboardText,Myrve);
Myrve.UseStyleTemplates:=true;

Re: Insert as Markdown ?

Posted: Wed Sep 09, 2026 8:48 pm
by Sergey Tkachenko
Without StyleTemplates, Markdown will be loaded using default character attributes.
For example, *text* will be loaded as an italic text, instead of using properties of 'Emphasis' StyleTemplate.

But I think, if the style like 'Emphasis' has a font size specified, this means that the user wants to emphasize text by changing its size.