src/friendly-iframe-embed.js
/**
 * Merges base and fonts into html document.
 * @param {!FriendlyIframeSpec} spec
 */
Merges base and fonts into html document.
Merges base and fonts into html document .
function mergeHtml(spec) {
  const originalHtml = spec.html;
  const originalHtmlUp = originalHtml.toUpperCase();
  let ip = originalHtmlUp.indexOf('<HEAD');
  if (ip != -1) {
    ip = originalHtmlUp.indexOf('>', ip + 1) + 1;
  }
  if (ip == -1) {
    ip = originalHtmlUp.indexOf('<BODY');
  }
  if (ip == -1) {
    ip = originalHtmlUp.indexOf('<HTML');
    if (ip != -1) {
      ip = originalHtmlUp.indexOf('>', ip + 1) + 1;
    }
  }
  const result = [];
  if (ip > 0) {
    result.push(originalHtml.substring(0, ip));
  }
  result.push(`<base href="${escapeHtml(spec.url)}">`);
  if (spec.fonts) {
    spec.fonts.forEach(font => {
      result.push(
          `<link href="${escapeHtml(font)}" rel="stylesheet" type="text/css">`);
    });
  }
  if (ip > 0) {
    result.push(originalHtml.substring(ip));
  } else {
    result.push(originalHtml);
  }
  return result.join('');
}
function mergeHtml ( spec ) { const originalHtml = spec . html ; const originalHtmlUp = originalHtml . toUpperCase ( ) ; let ip = originalHtmlUp . indexOf ( '<HEAD' ) ; if ( ip != - 1 ) { ip = originalHtmlUp . indexOf ( '>' , ip + 1 ) + 1 ; } if ( ip == - 1 ) { ip = originalHtmlUp . indexOf ( '<BODY' ) ; } if ( ip == - 1 ) { ip = originalHtmlUp . indexOf ( '<HTML' ) ; if ( ip != - 1 ) { ip = originalHtmlUp . indexOf ( '>' , ip + 1 ) + 1 ; } } const result = [ ] ; if ( ip > 0 ) { result . push ( originalHtml . substring ( 0 , ip ) ) ; } result . push ( ` ${ escapeHtml ( spec . url ) } ` ) ; if ( spec . fonts ) { spec . fonts . forEach ( font => { result . push ( ` ${ escapeHtml ( font ) } ` ) ; } ) ; } if ( ip > 0 ) { result . push ( originalHtml . substring ( ip ) ) ; } else { result . push ( originalHtml ) ; } return result . join ( '' ) ; }
Merges base and fonts into html document.
Merges base and fonts into html document .
// Find the insertion point. // Preambule. // Add <BASE> tag. // Load fonts. // Postambule.