Appends a <link> tag to the document's head.

@param {!string} url URL to a style sheet
@param {$.Deferred=} deferred Optionally check for load and error events
@return {!HTMLLinkElement} The generated HTML node
186901
function addLinkedStyleSheet(url, deferred) {
        var attributes = {
            type: "text/css",
            rel:  "stylesheet",
            href: url
        };

        var $link = $("<link/>").attr(attributes);

        if (deferred) {
            $link.on('load', deferred.resolve).on('error', deferred.reject);
        }

        $link.appendTo("head");

        return $link[0];
    }
315627
function scriptTag(src, callback)  {
		
		var elem = doc.createElement('script');		
		elem.type = 'text/' + (src.type || 'javascript');
		elem.src = src.src || src;  
			
		elem.onreadystatechange = elem.onload = function() {
			var state = elem.readyState;

			if (!callback.done && (!state || /loaded|complete/.test(state))) {
				callback.call();
				callback.done = true;
			}
			
			// cleanup. IE runs into trouble
			if (!ie) {			
				head.removeChild(elem);
			}
		}; 
		
		head.appendChild(elem); 
	}
531751
function (dom) {
            var html = '';
            dom.forEach(function (node) {
                if (node.type === 'tag') {
                    var tag = node.name;
                    html += '<' + tag;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += (voidTags[tag] ? '/>' : '>');
                    if (!voidTags[tag]) {
                        html += this.vdomToHtml(node.children);
                        html += '</' + tag + '>';
                    }
                } else if (node.type === 'text') {
                    var text = node.data || '';
                    html += this.htmlEncode(text); //escape <,> and &.
                } else if (node.type === 'comment') {
                    html += '<!-- ' + node.data.trim() + ' -->';
                } else if (node.type === 'script' || node.type === 'style') {
                    //No need to escape text inside script or style tag.
                    html += '<' + node.name;
                    Object.keys(node.attribs).forEach(function (attr) {
                        html += ' ' + attr + '=' + this.generateAttribute(node.attribs[attr]);
                    }, this);
                    html += '>' + ((node.children[0] || {}).data || '') + '</' + node.name + '>';
                } else if (node.type === 'directive') {
                    html += '<' + node.data + '>';
                }
            }, this);
            return html;
        }
491190
function(source, callback) {
        callback = callback || noop;

        //if there's a queue
        if (queue[source] instanceof Array) {
            //just call the callback
            return callback();
        }

        //otherwise there is not a queue
        //so let's create one
        queue[source] = [];

        var style     = document.createElement('link');
        var head     = document.getElementsByTagName('head')[0];

        style.type = 'text/css';
        style.rel = 'stylesheet';
        style.href = source;

        head.appendChild(style);
        callback();
    }
1030773
function(url){

                var self    = this;
                var head    = document.querySelector('head') || document.querySelector('body');
                var async   = data.sync !== true;
                var script;

                if(!head){
                    throw new Error('Ok, wait a second, you want to load a script, but you don\'t have at least a head or body tag...');
                }

                script = document.createElement('script');
                script.async = async;
                script.src = url;
                script.onerror = function onScriptError(){
                    self.trigger('error', arguments);
                    head.removeChild(script);
                };
                script.onload = function onScriptLoad(){
                    self.trigger('success', arguments);
                };

                head.appendChild(script);
            }
1340637
function appendUrl(url, urls) {
    var i = urls.length
        found = false;
    while (i--) {
        if (utils.compareUrl(urls[i], url)) 
          found = true; 
    }
    if (found === false && utils.isUrl(url)) 
      urls.push(url);
}
395520
function _appendNode(parent, child) {
  var parentName = _getHTMLNodeName(parent);

  var childName = _getHTMLNodeName(child);

  if (doc.createStyleSheet) {
    if (parentName === 'script') {
      parent.text = child.nodeValue;
      return;
    }

    if (parentName === 'style') {
      parent.cssText = child.nodeValue; // This will not apply it--just make it available within the DOM cotents

      return;
    }
  }

  if (parentName === 'template') {
    parent.content.appendChild(child);
    return;
  }

  try {
    parent.appendChild(child); // IE9 is now ok with this
  } catch (e) {
    if (parentName === 'select' && childName === 'option') {
      try {
        // Since this is now DOM Level 4 standard behavior (and what IE7+ can handle), we try it first
        parent.add(child);
      } catch (err) {
        // DOM Level 2 did require a second argument, so we try it too just in case the user is using an older version of Firefox, etc.
        parent.add(child, null); // IE7 has a problem with this, but IE8+ is ok
      }

      return;
    }

    throw e;
  }
}
1053186
function appendStyle(style, doc) {
    if (!_.isString(style) || !doc) {
        console.log('invalid document or style string...', style, doc);
        return;
    }
    let docEl = (doc.getElementsByTagName('document')).item(0);
    let styleString = ['<style>', style, '</style>'].join('');
    let headTag = doc.getElementsByTagName('head');

    headTag = headTag && headTag.item(0);
    if (!headTag) {
        headTag = doc.createElement('head');
        docEl.insertBefore(headTag, docEl.firstChild);
    }
    headTag.innerHTML = styleString;
}
587632
function(string) {
  if (!string) {
    var fragment = document.createDocumentFragment();
    fragment.appendChild(document.createTextNode(''));
    return fragment;
  }
  var templateElement;
  templateElement = document.createElement('template');
  templateElement.innerHTML = string;
  return templateElement.content;
}
514340
public ParagraphBuilder link(final String text, final URL url) {
		final ParagraphElement paragraphElement = Link.create(text, url);
		this.paragraphElements.add(paragraphElement);
		return this;
	}
762517
protected String createExternalLinkElement(final DocBookVersion docBookVersion, final String title, final String url) {
        final StringBuilder linkEle = new StringBuilder();
        if (docBookVersion == DocBookVersion.DOCBOOK_50) {
            linkEle.append("<link xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"").append(url).append("\">");
            linkEle.append(title);
            linkEle.append("</link>");
        } else {
            linkEle.append("<ulink url=\"").append(url).append("\">");
            linkEle.append(title);
            linkEle.append("</ulink>");
        }
        return linkEle.toString();
    }
255077
function(file) {
    var link = document.createElement("link")
    link.href = file
    link.type = "text/css"
    link.rel = "stylesheet"
    link.media = "screen,print"
    document.getElementsByTagName("head")[0].appendChild(link)
  }
1016616
function createScript(url, appID) {
    if (!document) { return; }
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = url+appID;
    // Attach the script tag to the document head
    var s = document.getElementsByTagName('head')[0];
    s.appendChild(script);
  }
729142
function appendToHead(document, tagName, attrs) {
	var elt = document.createElement(tagName);
	DOMDataUtils.addAttributes(elt, attrs || Object.create(null));
	document.head.appendChild(elt);
}
101987
function addScriptUrlsByHeaderInsertion(html, missingScriptUrls) {
  const escapedPlaceholder = new RegExp('([^\\S\\r\\n]*)'
      + escapeRegex('</head>'), 'i');

  const indentedUrls = Array.from(missingScriptUrls).map((u) => '  ' + u);
  indentedUrls.push('</head>');
  whitespaceUrls = indentedUrls.map((u) => '$1' + u);
  return html.replace(escapedPlaceholder, whitespaceUrls.join('\n'));
}
847122
function appendChild(child, element, context, appended) {
                    /*jshint validthis: true */

                    // ignore appending to the node that's not yet added to DOM tree
                    if (!element.parentNode) {
                        return;
                    }

                    // don't count elements added to fragments as a DOM inserts (issue #350)
                    // DocumentFragment > div[0]
                    if (context.indexOf('DocumentFragment') === 0) {
                        return;
                    }

                    phantomas.incrMetric('DOMinserts');
                    phantomas.addOffender('DOMinserts', '"%s" appended to "%s"', appended, context);

                    //phantomas.log('DOM insert: node "%s" appended to "%s"', appended, context);
                }
1165758
function( pathToHTMLFile ){
        var deferred = Q.defer(),
            targetHTML = new TargetHTML( pathToHTMLFile );

        targetHTML.init()
            .then( function( targetHTML ){ return this.getTemplate( targetHTML.detectTemplateId() ); }.bind( this ) )
            .then( function( template ){ return template.generateCode( targetHTML.pickOutValues(), pathToHTMLFile ); } )
            .then( function( HTMLCode ){ return targetHTML.update( HTMLCode ); } )
            .catch( function( error ){ deferred.reject( error ); } )
            .finally( function(){ deferred.resolve( pathToHTMLFile ); } );

        return deferred.promise;
    }