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...
Insert as Markdown ?
-
Sergey Tkachenko
- Site Admin
- Posts: 18240
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Insert as Markdown ?
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):
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 ?
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.
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.
-
Sergey Tkachenko
- Site Admin
- Posts: 18240
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Insert as Markdown ?
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.
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 ?
Thank you for answer.Does your editor use style templates? (UseStyleTemplates property = True).
Does do this (disable UsestyleTemplate while inserting) is a good idea :
Code: Select all
Myrve.UseStyleTemplates:=false;
InsertMarkdown(MDClipboardText,Myrve);
Myrve.UseStyleTemplates:=true;
-
Sergey Tkachenko
- Site Admin
- Posts: 18240
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Insert as Markdown ?
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.
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.