Hello,
I've run into a snag while working with Markdown.
It seems there's an issue when the last word of my text is styled (e.g., bold) and ends with a space.
Any tips on resolving this or best practices to follow? Just want to make sure my text formats correctly according to Markdown rules.
Thanks for the help!
Best,
Alessandro Mancini
Markdown Issue with Last Word Styling and Trailing Space
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Markdown Issue with Last Word Styling and Trailing Space
I confirm the problem. It is in saving.
According to Markdown specification (TRichView uses CommonMark version), bold or italic fragment cannot end on a space character.
So in the code
bbb is not bold and asterisks must be displayed (check)
TRichView must modify saving procedure to avoid this problem. It already does it in the middle of paragraphs.
For example, in the text "aaa bbb ccc" bold space after "bbb" is saved as not bold:
instead of incorrect
We need to do the same thing at the end of paragraph.
Quick fix. Open RVMarkdownSave.pas, and change class procedure TRVMarkdownSavingData.FinalizeFormatting to
Of course, the resulting document will be not exactly the same as the original. But this is a necessary compromise.
According to Markdown specification (TRichView uses CommonMark version), bold or italic fragment cannot end on a space character.
So in the code
Code: Select all
aaa **bbb **
TRichView must modify saving procedure to avoid this problem. It already does it in the middle of paragraphs.
For example, in the text "aaa bbb ccc" bold space after "bbb" is saved as not bold:
Code: Select all
aaa **bbb** ccc
Code: Select all
aaa **bbb **ccc
Quick fix. Open RVMarkdownSave.pas, and change class procedure TRVMarkdownSavingData.FinalizeFormatting to
Code: Select all
class procedure TRVMarkdownSavingData.FinalizeFormatting(var CurS: TRVUnicodeString;
var CurStyle: TFontStyles);
var
Formatting: TRVUnicodeString;
CT: TRVMDCharType;
begin
if CurStyle <> [] then
begin
Formatting := '';
if rvfsBold in CurStyle then
Formatting := Formatting + '**';
if rvfsItalic in CurStyle then
Formatting := Formatting + '*';
if Formatting <> '' then
begin
CT := GetLastCharType(CurS);
if CT <> rvmdctWhitespace then
CurS := CurS + Formatting
else
InsertBeforeTrailingWhitespaces(CurS, Formatting);
end;
CurStyle := CurStyle - [rvfsBold, rvfsItalic];
end;
end;
Re: Markdown Issue with Last Word Styling and Trailing Space
the fix works well, thank you for the support
-
- Site Admin
- Posts: 17557
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Markdown Issue with Last Word Styling and Trailing Space
Fixed in TRichView 22.2