function fixInlineMacros() {
  var contentDiv = document.getElementById("content");
  var spans = contentDiv.getElementsByTagName("span");
  var inlineSpans = new Array();
  for (var i = 0; i < spans.length; i++) {
    if (spans[i].className == "inline") inlineSpans.push(spans[i]);
  }
  for (var i = 0; i < inlineSpans.length; i++) {
    repairInlineMacroOutput(inlineSpans[i]);
  }
}

function repairInlineMacroOutput(inlineSpan) {
  var msg = "";
  var prevElement, nextElement;
  var children = inlineSpan.parentNode.children;
  for (var i = 0; i < children.length; i++) {
    if (children.length > i && children[i + 1] == inlineSpan)
      prevElement = children[i];
    if (children.length > i && children[i] == inlineSpan)
      nextElement = children[i + 1];
    if (prevElement != null && nextElement != null) break;
  }
  if (prevElement != null
        && nextElement != null
        && prevElement.tagName == nextElement.tagName) {
    var noSpaceChars = /^[\.,;]/; // if the next element begins with one of these characters, then we should not insert space before the element when concatenating
    var combinedElement = document.createElement(prevElement.tagName);
    combinedElement.innerHTML = prevElement.innerHTML + " "
            + inlineSpan.innerHTML
      + (noSpaceChars.test(nextElement.innerHTML) ? "" : " ")
            + nextElement.innerHTML;
    inlineSpan.parentNode.replaceChild(combinedElement, prevElement);
    inlineSpan.parentNode.removeChild(nextElement);
    inlineSpan.parentNode.removeChild(inlineSpan);
  }
}

// add the onLoad handlers to the window so that all of the client-side script gets init'ed
if (window.addEventListener) {
  window.addEventListener('load', fixInlineMacros, false);
}
else if (window.attachEvent) {
  window.attachEvent('onload', fixInlineMacros);
}
      

