Page 1 of 1
Markdown Issue with Last Word Styling and Trailing Space
Posted: Wed Jan 17, 2024 12:13 pm
by a.mancini
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
Re: Markdown Issue with Last Word Styling and Trailing Space
Posted: Wed Jan 17, 2024 2:10 pm
by Sergey Tkachenko
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
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;
Of course, the resulting document will be not exactly the same as the original. But this is a necessary compromise.
Re: Markdown Issue with Last Word Styling and Trailing Space
Posted: Wed Jan 17, 2024 5:19 pm
by a.mancini
the fix works well, thank you for the support
Re: Markdown Issue with Last Word Styling and Trailing Space
Posted: Sun Jan 28, 2024 12:18 pm
by Sergey Tkachenko
Fixed in TRichView 22.2