How to convert InnerText to InnerHtml in Webbrowser Control in C #?

I am working on a WYSIWYG editor with built-in Hunspell spellchecking and online highlighting of misspelled words. I use Webbrowser control as an html handler. This is an easy way to check the validation text than html in managing your web browser, but after that I lose all html formatting. So the question is, is there any way to check the spelling of the inner text and then convert it to the innerhtml body with the previous formatting? (without using HtmlAgilityPack or Majestic12 or SgmlReader or ZetaHtmlTidy ).

Thanks in advance.

+3
source share
2 answers

Unlike spell-checking the properties of a innterTextgiven element, a loop through child elements might be a better approach, and instead check the spelling of each child element innerText.

This approach, although it may limit contextual spell checking, should keep markup intact.

Note. You might want to take into account that each child of a node can also contain additional children.

+1
source

innerText, innerHTML. . innerHTML .

Regex wordEx = new Regex(@"[A-Za-z]", RegexOptions.Compiled);
MatchCollection mcol = wordEx.Matches(webEditor.Document.Body.InnerHtml);

foreach (Match m in mcol)
{
  //Basic checking for whether this word is an HTML tag. This is not perfect.
  if (m.Value == e.Word && webEditor.Document.Body.InnerHtml.Substring(m.Index -1, 1) != "<")
  {
    wordIndeces.Add(m.Index);
  }
}

foreach (int curWordTextIndex in wordIndeces)
{
   Word word = Word.GetWordFromPosition(webEditor.Document.Body.InnerHtml, curWordTextIndex);
   string tmpText = webEditor.Document.Body.InnerHtml.Remove(word.Start, word.Length);
   webEditor.Document.Body.InnerHtml = tmpText.Insert(word.Start, e.NewWord);
}

UpdateSpellingForm(e.TextIndex);

InnerText, , . innerHTML, .

0

Source: https://habr.com/ru/post/1736833/


All Articles