Skip to content

Instantly share code, notes, and snippets.

@sclarson
Created January 19, 2012 21:34
Show Gist options
  • Save sclarson/1642884 to your computer and use it in GitHub Desktop.
Save sclarson/1642884 to your computer and use it in GitHub Desktop.
Retaining headings getting stripped by the XForm cleaner
private void CleanupXFormHtmlMarkup(XFormControl formControl)
{
if (formControl.EditMode)
{
// We need to render the default table when in edit mode, otherwise the form wizard won't work
return;
}
bool firstLiteralControl = false;
LiteralControl literalControl = null;
ControlCollection controls = formControl.Controls;
var spanRegex = new Regex(@"(<span[^>]*>[^<]*</span>)");
foreach (object control in controls)
{
if (control is LiteralControl)
{
literalControl = control as LiteralControl;
// find the first literal control
if (!firstLiteralControl)
{
Match m = spanRegex.Match(literalControl.Text);
literalControl.Text = "<fieldset><p>";
if (m.Success)
literalControl.Text += m.Groups[0].Value + "</p><p>";
firstLiteralControl = true;
}
else
{
Match m = spanRegex.Match(literalControl.Text);
if (m.Success)
{
literalControl.Text = String.Format("</p><p>{0}</p><p>",m.Groups[0].Value);
continue;
}
literalControl.Text = "</p><p>";
}
}
}
// update markup for the last literal control
if (literalControl != null)
{
literalControl.Text = "</p></fieldset>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment