Return Html with TrackChange and with Accepted Track Change

2 Answers 45 Views
Editor
Emin Sadigov
Top achievements
Rank 2
Iron
Iron
Iron
Emin Sadigov asked on 28 Jun 2024, 04:11 PM

Hello,

Is any way to return:

1. Html with Track Change marks and comments to store it in the database for next edit session?

2. Auto accepted html.

I tried in cs: RadEditor1.Content - but it return content without changes, RadEditor1.GetHtml(EditorStripHtmlOptions.AcceptTrackChanges) - but also track changes were not accepted.

Can you provide any example, please?

Thank you!

Rumen
Telerik team
commented on 01 Jul 2024, 07:27 AM

Hi Emin,

Straight to the questions:

  1. You can obtain the specific Track Changes and Comments HTML formatting through the RadEditor1.Content property: 

            protected void Submit_Button_Click(object sender, EventArgs e)
            {
                TextArea1.Text = RadEditor1.Content;
            }

  2. You can call the AcceptTrackChanges() method before the GetHtml one and the track changes will be accepted:

            protected void Submit_Button_Click(object sender, EventArgs e)
            {
                RadEditor1.AcceptTrackChanges();
                TextArea1.Text = RadEditor1.GetHtml(EditorStripHtmlOptions.AcceptTrackChanges);
            }

2 Answers, 1 is accepted

Sort by
0
Accepted
Emin Sadigov
Top achievements
Rank 2
Iron
Iron
Iron
answered on 03 Jul 2024, 02:39 PM

Thank you, Rumen. My fault was that I haven`t used Page.IsPostBack, so it is fixed by this code:

if (!Page.IsPostBack)
{
    RadEditor1.Content = "Initial text";
}

 

So, now I try to get Content with accepted TrackChanges and without Comments. This code seems correct, however empty Comments <span> remain when I use this parameter:

EditorStripHtmlOptions.Comments

in the code:

protected void Submit_Button_Click(object sender, EventArgs e)
{
      RadEditor1.AcceptTrackChanges();
      TextArea1.Text = RadEditor1.GetHtml(EditorStripHtmlOptions.AcceptTrackChanges | EditorStripHtmlOptions.Comments);
}

Seems UI Remove All Comments command is working better and remove <span> tag also.

Also UI Accept Track Change is working better and remove <strong> if word was removed, but code above remain empty <strong> tag. Or is it Filters? How can I use them in backend in the code above to clean from comments and accept track changes without empty tags?

Rumen
Telerik team
commented on 04 Jul 2024, 09:46 AM

If there are empty span tags left after programmatically accepting the track changes, you can perform a regexp-based stripping of the empty tags, e.g.

protected void Submit_Button_Click(object sender, EventArgs e)
{
    // Accept all track changes
    RadEditor1.AcceptTrackChanges();

    // Get HTML with accepted track changes and strip comments
    string acceptedHtml = RadEditor1.GetHtml(EditorStripHtmlOptions.AcceptTrackChanges | EditorStripHtmlOptions.Comments);

    // Clean up empty tags
    acceptedHtml = System.Text.RegularExpressions.Regex.Replace(acceptedHtml, @"<[^/>][^>]*></[^>]+>", string.Empty);
    TextArea1.Text = acceptedHtml;
    // Save to the database logic here
}

0
Emin Sadigov
Top achievements
Rank 2
Iron
Iron
Iron
answered on 04 Jul 2024, 10:26 AM

Hello, Rumen. Thank you, It is better. However the code after Comments is still bad. Look before:


<h2>Key <span class="reComment reU0" author="Alen Landar" comment="test" title="Alen Landar: test: 7/4/2024, 2:06:12 PM" timestamp="1720087572798">settings </span>and features</h2>


After code above converts into:

<h2>Key <span>settings </span>and features</h2>

 

So, it is possible to write regex to cleans spans without attributes. But if any other solution is available, which work like a UI Remove All Comments, it will be better.

Rumen
Telerik team
commented on 04 Jul 2024, 10:34 AM

I see, you can try this to strip the span tags without attributes like this:

 // Remove empty span tags and other empty tags
    acceptedHtml = System.Text.RegularExpressions.Regex.Replace(acceptedHtml, @"<span[^>]*>\s*</span>", string.Empty);

// Remove <span> tags without attributes
    acceptedHtml = System.Text.RegularExpressions.Regex.Replace(acceptedHtml, @"<span>\s*(.*?)\s*</span>", "$1");

Tags
Editor
Asked by
Emin Sadigov
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Emin Sadigov
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or