Can I modify the code auto-format behaviour of the visual editor?

Topics: Visual editor
May 24, 2011 at 9:50 AM

Hi,

Is there a way to modify the code auto-format behaviour of the visual editor?

I want the auto-format to consider a line break after a <br /> tag. The current (default) setting does not insert a line break, which leads to long lines and therefore scrolling horizontally a lot :-(

Thanx for help,
steschu

Developer
May 25, 2011 at 9:02 AM

Hi

You can modify Composite\services\SourceEditor\MarkupFormatService.asmx method AutoIndentDocument

by adding :

 

               var re = new Regex(@"\n(\s+)(<[^\n]+)<br />");
                while (re.Match(result).Success)
                    result = re.Replace(result, "\n$1$2\n$1\t<br />");

 

before line

 return server.UrlEncode(result).Replace("+", "%20");

 

 

Result function:

 

 [WebMethod]
        public string AutoIndentDocument(string xml)
        {
            try
            {
                var server = HttpContext.Current.Server;

                string decodedXml = server.UrlDecode(xml);
                string result = XhtmlPrettifier.Prettify(decodedXml);

                var re = new Regex(@"\n(\s+)(<[^\n]+)<br />");
                while (re.Match(result).Success)
                    result = re.Replace(result, "\n$1$2\n$1\t<br />");
              
                return server.UrlEncode(result).Replace("+", "%20");
            }
            catch (Exception)
            {
                throw;
            }
        }