Copies the given HTML as the content of the current document's <head>
element. If the current document's head already contains identical
markup, copying is skipped. <script> elements are omitted.
333337
function copyHead(headHtml, doc) {
        var head = doc.getElementsByTagName('head')[0];

        if (head.innerHTML == headHtml) {
            // the content is already correct
            return;
        }

        jQuery.init(head).empty();

        appendHTML(headHtml, head);
    }
110942
def render_copy from_source_path
      source_path = "#{ActiveCopy.content_path}/#{from_source_path}.md"

      if File.exists? source_path
        raw_source = IO.read source_path
        source = raw_source.split("---\n")[2]
        template = ActiveCopy::Markdown.new
        template.render(source).html_safe
      else
        raise ArgumentError.new "#{source_path} does not exist."
      end
    end
1091020
private void normaliseStructure(String tag, Element htmlEl) {
        Elements elements = this.getElementsByTag(tag);
        Element master = elements.first(); // will always be available as created above if not existent
        if (elements.size() > 1) { // dupes, move contents to master
            List<Node> toMove = new ArrayList<>();
            for (int i = 1; i < elements.size(); i++) {
                Node dupe = elements.get(i);
                toMove.addAll(dupe.ensureChildNodes());
                dupe.remove();
            }

            for (Node dupe : toMove)
                master.appendChild(dupe);
        }
        // ensure parented by <html>
        if (!master.parent().equals(htmlEl)) {
            htmlEl.appendChild(master); // includes remove()            
        }
    }
640567
def clone_bs4_elem(el):
    
    if isinstance(el, NavigableString):
        return type(el)(el)

    copy = Tag(None, el.builder, el.name, el.namespace, el.nsprefix)
    # work around bug where there is no builder set
    # https://bugs.launchpad.net/beautifulsoup/+bug/1307471
    copy.attrs = dict(el.attrs)
    for attr in ('can_be_empty_element', 'hidden'):
        setattr(copy, attr, getattr(el, attr))
    for child in el.contents:
        copy.append(clone_bs4_elem(child))
    return copy
1097542
protected String transformHtmlLinks(String content, ReferenceContext references) {
		if (!isPureHtmlReferenceTransformation()) {
			return content;
		}

		// Prepare replacement data structures
		final Map<String, String> replacements = new TreeMap<>();

		// Visit the links and record the transformations
		final org.jsoup.select.NodeVisitor visitor = new org.jsoup.select.NodeVisitor() {
			@Override
			public void tail(org.jsoup.nodes.Node node, int index) {
				//
			}

			@Override
			public void head(org.jsoup.nodes.Node node, int index) {
				if (node instanceof Element) {
					final Element tag = (Element) node;
					if ("a".equals(tag.nodeName()) && tag.hasAttr("href")) { //$NON-NLS-1$ //$NON-NLS-2$
						final String href = tag.attr("href"); //$NON-NLS-1$
						if (!Strings.isEmpty(href)) {
							URL url = FileSystem.convertStringToURL(href, true);
							url = transformURL(url, references);
							if (url != null) {
								replacements.put(href, convertURLToString(url));
							}
						}
					}
				}
			}
		};
		final Document htmlDocument = Jsoup.parse(content);
		htmlDocument.traverse(visitor);

		// Apply the replacements
		if (!replacements.isEmpty()) {
			String buffer = content;
			for (final Entry<String, String> entry : replacements.entrySet()) {
				final String source = entry.getKey();
				final String dest = entry.getValue();
				buffer = buffer.replaceAll(Pattern.quote(source), Matcher.quoteReplacement(dest));
			}
			return buffer;
		}
		return content;
	}
387418
def copy(self, dest, src):
        
        doc = fragment = deepcopy(self.document)
        for token in Pointer(src):
            fragment = token.extract(fragment, bypass_ref=True)

        return Target(doc).add(dest, fragment)
1113104
public void copyFrom(XElement other) {
        content = other.content;
        userObject = other.userObject;
        attributes.putAll(other.attributes);
        for (XElement c : other.children) {
            add(c.copy());
        }
    }
551454
def __set_html(self, html=None):
        

        self.__html = self.__get_html(html)
        self.__view.setHtml(self.__html)
59532
function getCopiedFragment(opts: Options, value: Value): ?Document {
    // Outside of tables, do not alter copy behavior
    if (!isSelectionInTable(opts, value)) {
        return undefined;
    }
    // else the selection is a fragment of one table

    const { selection, document } = value;
    const startPosition = TablePosition.create(
        opts,
        document,
        selection.startKey
    );
    const endPosition = TablePosition.create(opts, document, selection.endKey);

    // Fragment as it would be copied by Slate
    const baseFragment = value.fragment;

    if (endPosition.cell === startPosition.cell) {
        // The selection is inside a single cell. Only copy the content of that cell
        const copiedCell = baseFragment
            .getAncestors(baseFragment.getFirstText().key)
            .findLast(n => n.type === opts.typeCell);

        return baseFragment.merge({
            nodes: copiedCell.nodes
        });
    }

    // We want to pad with empty cells to put a valid table into the clipboard
    const table = baseFragment.nodes.first();
    const firstRow = table.nodes.first();
    const endRow = table.nodes.last();

    const startPadding = List(Array(startPosition.getColumnIndex()).fill()).map(
        () => createCell(opts)
    );

    const endPadding = List(
        Array(
            endPosition.getWidth() - (endPosition.getColumnIndex() + 1)
        ).fill()
    ).map(() => createCell(opts));

    return baseFragment.mapDescendants(node => {
        if (node === firstRow) {
            return firstRow.merge({
                nodes: startPadding.concat(firstRow.nodes)
            });
        }

        if (node === endRow) {
            return endRow.merge({
                nodes: endRow.nodes.concat(endPadding)
            });
        }

        return node;
    });
}
1294610
private static void replaceOrAppend(Element oldElement, Element newElement) {
    assert oldElement != null && newElement != null;

    if (matchesTags(oldElement, appendingTags)) {
      GQuery.$(oldElement).html("").append(newElement);
    } else {
      GQuery.$(oldElement).replaceWith(newElement);

      // copy class
      String c = oldElement.getClassName();
      if (!c.isEmpty()) {
        newElement.addClassName(c);
      }
      // copy id
      newElement.setId(oldElement.getId());
      // ensure no duplicate id
      oldElement.setId("");
    }
  }
665376
function clone(node) {
  const copy = node.clone();
  copy.changeGroup = node.changeGroup;
  if (node.args) {
    node.args.forEach((child, i) => {
      copy.args[i] = clone(child);
    });
  }
  else if (node.content) {
    copy.content = clone(node.content);
  }
  return copy;
}
960325
function append(element, content) {
  if (isElement(content)) {
    element.appendChild(content);
  } else {
    const div = document.createElement('div');
    div.innerHTML = content || '';

    while (div.firstChild) {
      element.appendChild(div.firstChild);
    }
  }
}
729142
function appendToHead(document, tagName, attrs) {
	var elt = document.createElement(tagName);
	DOMDataUtils.addAttributes(elt, attrs || Object.create(null));
	document.head.appendChild(elt);
}
568233
function (value, elem) {
        var tmpl = elem.firstElementChild
        elem.removeChild(tmpl)

        value.forEach(function (text) {
            var clone = tmpl.cloneNode(true)
            clone.textContent = text
            elem.appendChild(clone)
        })
    }
1225197
function( html ) {
					try {
						var $ = this.$;

						// Fix the case when setHtml is called on detached element.
						// HTML5 shiv used for document in which this element was created
						// won't affect that detached element. So get document fragment with
						// all HTML5 elements enabled and set innerHTML while this element is appended to it.
						if ( this.getParent() )
							return ( $.innerHTML = html );
						else {
							var $frag = this.getDocument()._getHtml5ShivFrag();
							$frag.appendChild( $ );
							$.innerHTML = html;
							$frag.removeChild( $ );

							return html;
						}
					}
					catch ( e ) {
						this.$.innerHTML = '';

						var temp = new CKEDITOR.dom.element( 'body', this.getDocument() );
						temp.$.innerHTML = html;

						var children = temp.getChildren();
						while ( children.count() )
							this.append( children.getItem( 0 ) );

						return html;
					}
				}
247547
public static Document html( Example example, String name, String externalLink )
	{
		return new Document( "html", example, name, externalLink );
	}
690191
protected void write(Element element, int indent) throws IOException {
        Properties styleAttributes = null;
        switch(element.type()) {
        	case Element.MARKED: {
        		try {
					add(element);
				} catch (DocumentException e) {
					e.printStackTrace();
				}
        		return;
        	}
            case Element.CHUNK:
            {
                Chunk chunk = (Chunk) element;
                // if the chunk contains an image, return the image representation
                Image image = chunk.getImage();
                if (image != null) {
                    write(image, indent);
                    return;
                }
                
                if (chunk.isEmpty()) return;
                HashMap attributes = chunk.getAttributes();
                if (attributes != null && attributes.get(Chunk.NEWPAGE) != null) {
                    return;
                }
                boolean tag = isOtherFont(chunk.getFont()) || markup.size() > 0;
                if (tag) {
                    // start span tag
                    addTabs(indent);
                    writeStart(HtmlTags.SPAN);
                    if (isOtherFont(chunk.getFont())) {
                        write(chunk.getFont(), null);
                    }
                    writeMarkupAttributes(markup);
                    os.write(GT);
                }
                if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) {
                    // start sup or sub tag
                    if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
                        writeStart(HtmlTags.SUP);
                    }
                    else {
                        writeStart(HtmlTags.SUB);
                    }
                    os.write(GT);
                }
                // contents
                write(HtmlEncoder.encode(chunk.getContent()));
                if (attributes != null && attributes.get(Chunk.SUBSUPSCRIPT) != null) {
                    // end sup or sub tag
                    os.write(LT);
                    os.write(FORWARD);
                    if (((Float)attributes.get(Chunk.SUBSUPSCRIPT)).floatValue() > 0) {
                        write(HtmlTags.SUP);
                    }
                    else {
                        write(HtmlTags.SUB);
                    }
                    os.write(GT);
                }
                if (tag) {
                    // end tag
                    writeEnd(Markup.HTML_TAG_SPAN);
                }
                return;
            }
            case Element.PHRASE:
            {
                Phrase phrase = (Phrase) element;
                styleAttributes = new Properties();
                if (phrase.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, phrase.getLeading() + "pt");
                
                // start tag
                addTabs(indent);
                writeStart(Markup.HTML_TAG_SPAN);
                writeMarkupAttributes(markup);
                write(phrase.getFont(), styleAttributes);
                os.write(GT);
                currentfont.push(phrase.getFont());
                // contents
                for (Iterator i = phrase.iterator(); i.hasNext(); ) {
                    write((Element) i.next(), indent + 1);
                }
                // end tag
                addTabs(indent);
                writeEnd(Markup.HTML_TAG_SPAN);
                currentfont.pop();
                return;
            }
            case Element.ANCHOR:
            {
                Anchor anchor = (Anchor) element;
                styleAttributes = new Properties();
                if (anchor.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, anchor.getLeading() + "pt");
                
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.ANCHOR);
                if (anchor.getName() != null) {
                    write(HtmlTags.NAME, anchor.getName());
                }
                if (anchor.getReference() != null) {
                    write(HtmlTags.REFERENCE, anchor.getReference());
                }
                writeMarkupAttributes(markup);
                write(anchor.getFont(), styleAttributes);
                os.write(GT);
                currentfont.push(anchor.getFont());
                // contents
                for (Iterator i = anchor.iterator(); i.hasNext(); ) {
                    write((Element) i.next(), indent + 1);
                }
                // end tag
                addTabs(indent);
                writeEnd(HtmlTags.ANCHOR);
                currentfont.pop();
                return;
            }
            case Element.PARAGRAPH:
            {
                Paragraph paragraph = (Paragraph) element;
                styleAttributes = new Properties();
                if (paragraph.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, paragraph.getTotalLeading() + "pt");
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.DIV);
                writeMarkupAttributes(markup);
                String alignment = HtmlEncoder.getAlignment(paragraph.getAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.ALIGN, alignment);
                }
                write(paragraph.getFont(), styleAttributes);
                os.write(GT);
                currentfont.push(paragraph.getFont());
                // contents
                for (Iterator i = paragraph.iterator(); i.hasNext(); ) {
                    write((Element)i.next(), indent + 1);
                }
                // end tag
                addTabs(indent);
                writeEnd(HtmlTags.DIV);
                currentfont.pop();
                return;
            }
            case Element.SECTION:
            case Element.CHAPTER:
            {
                // part of the start tag + contents
                writeSection((Section) element, indent);
                return;
            }
            case Element.LIST:
            {
                List list = (List) element;
                // start tag
                addTabs(indent);
                if (list.isNumbered()) {
                    writeStart(HtmlTags.ORDEREDLIST);
                }
                else {
                    writeStart(HtmlTags.UNORDEREDLIST);
                }
                writeMarkupAttributes(markup);
                os.write(GT);
                // contents
                for (Iterator i = list.getItems().iterator(); i.hasNext(); ) {
                    write((Element) i.next(), indent + 1);
                }
                // end tag
                addTabs(indent);
                if (list.isNumbered()) {
                    writeEnd(HtmlTags.ORDEREDLIST);
                }
                else {
                    writeEnd(HtmlTags.UNORDEREDLIST);
                }
                return;
            }
            case Element.LISTITEM:
            {
                ListItem listItem = (ListItem) element;
                styleAttributes = new Properties();
                if (listItem.hasLeading()) styleAttributes.setProperty(Markup.CSS_KEY_LINEHEIGHT, listItem.getTotalLeading() + "pt");
                
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.LISTITEM);
                writeMarkupAttributes(markup);
                write(listItem.getFont(), styleAttributes);
                os.write(GT);
                currentfont.push(listItem.getFont());
                // contents
                for (Iterator i = listItem.iterator(); i.hasNext(); ) {
                    write((Element) i.next(), indent + 1);
                }
                // end tag
                addTabs(indent);
                writeEnd(HtmlTags.LISTITEM);
                currentfont.pop();
                return;
            }
            case Element.CELL:
            {
                Cell cell = (Cell) element;
                
                // start tag
                addTabs(indent);
                if (cell.isHeader()) {
                    writeStart(HtmlTags.HEADERCELL);
                }
                else {
                    writeStart(HtmlTags.CELL);
                }
                writeMarkupAttributes(markup);
                if (cell.getBorderWidth() != Rectangle.UNDEFINED) {
                    write(HtmlTags.BORDERWIDTH, String.valueOf(cell.getBorderWidth()));
                }
                if (cell.getBorderColor() != null) {
                    write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(cell.getBorderColor()));
                }
                if (cell.getBackgroundColor() != null) {
                    write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(cell.getBackgroundColor()));
                }
                String alignment = HtmlEncoder.getAlignment(cell.getHorizontalAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.HORIZONTALALIGN, alignment);
                }
                alignment = HtmlEncoder.getAlignment(cell.getVerticalAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.VERTICALALIGN, alignment);
                }
                if (cell.getWidthAsString() != null) {
                    write(HtmlTags.WIDTH, cell.getWidthAsString());
                }
                if (cell.getColspan() != 1) {
                    write(HtmlTags.COLSPAN, String.valueOf(cell.getColspan()));
                }
                if (cell.getRowspan() != 1) {
                    write(HtmlTags.ROWSPAN, String.valueOf(cell.getRowspan()));
                }
                if (cell.getMaxLines() == 1) {
                	write(HtmlTags.STYLE, "white-space: nowrap;");
                }
                os.write(GT);
                // contents
                if (cell.isEmpty()) {
                    write(NBSP);
                } else {
                    for (Iterator i = cell.getElements(); i.hasNext(); ) {
                        write((Element) i.next(), indent + 1);
                    }
                }
                // end tag
                addTabs(indent);
                if (cell.isHeader()) {
                    writeEnd(HtmlTags.HEADERCELL);
                }
                else {
                    writeEnd(HtmlTags.CELL);
                }
                return;
            }
            case Element.ROW:
            {
                Row row = (Row) element;
                
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.ROW);
                writeMarkupAttributes(markup);
                os.write(GT);
                // contents
                Element cell;
                for (int i = 0; i < row.getColumns(); i++) {
                    if ((cell = (Element)row.getCell(i)) != null) {
                        write(cell, indent + 1);
                    }
                }
                // end tag
                addTabs(indent);
                writeEnd(HtmlTags.ROW);
                return;
            }
            case Element.TABLE:
            {
            	Table table;
            	try {
            		table = (Table) element;
            	}
            	catch(ClassCastException cce) {
            		try {
						table = ((SimpleTable)element).createTable();
					} catch (BadElementException e) {
						throw new ExceptionConverter(e);
					}
            	}
                table.complete();
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.TABLE);
                writeMarkupAttributes(markup);
                os.write(SPACE);
                write(HtmlTags.WIDTH);
                os.write(EQUALS);
                os.write(QUOTE);
                write(String.valueOf(table.getWidth()));
                if (!table.isLocked()){
                    write("%");
                }
                os.write(QUOTE);
                String alignment = HtmlEncoder.getAlignment(table.getAlignment());
                if (!"".equals(alignment)) {
                    write(HtmlTags.ALIGN, alignment);
                }
                write(HtmlTags.CELLPADDING, String.valueOf(table.getPadding()));
                write(HtmlTags.CELLSPACING, String.valueOf(table.getSpacing()));
                if (table.getBorderWidth() != Rectangle.UNDEFINED) {
                    write(HtmlTags.BORDERWIDTH, String.valueOf(table.getBorderWidth()));
                }
                if (table.getBorderColor() != null) {
                    write(HtmlTags.BORDERCOLOR, HtmlEncoder.encode(table.getBorderColor()));
                }
                if (table.getBackgroundColor() != null) {
                    write(HtmlTags.BACKGROUNDCOLOR, HtmlEncoder.encode(table.getBackgroundColor()));
                }
                os.write(GT);
                // contents
                Row row;
                for (Iterator iterator = table.iterator(); iterator.hasNext(); ) {
                    row = (Row) iterator.next();
                    write(row, indent + 1);
                }
                // end tag
                addTabs(indent);
                writeEnd(HtmlTags.TABLE);
                return;
            }
            case Element.ANNOTATION:
            {
                Annotation annotation = (Annotation) element;
                writeComment(annotation.title() + ": " + annotation.content());
                return;
            }
            case Element.IMGRAW:
            case Element.JPEG:
            case Element.JPEG2000:
            case Element.IMGTEMPLATE:
            {
                Image image = (Image) element;
                if (image.getUrl() == null) {
                    return;
                }
                
                // start tag
                addTabs(indent);
                writeStart(HtmlTags.IMAGE);
                String path = image.getUrl().toString();
                if (imagepath != null) {
                    if (path.indexOf('/') > 0) {
                        path = imagepath + path.substring(path.lastIndexOf('/') + 1);
                    }
                    else {
                        path = imagepath + path;
                    }
                }
                write(HtmlTags.URL, path);
                if ((image.getAlignment() & Image.RIGHT) > 0) {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_RIGHT);
                }
                else if ((image.getAlignment() & Image.MIDDLE) > 0) {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_MIDDLE);
                }
                else {
                    write(HtmlTags.ALIGN, HtmlTags.ALIGN_LEFT);
                }
                if (image.getAlt() != null) {
                    write(HtmlTags.ALT, image.getAlt());
                }
                write(HtmlTags.PLAINWIDTH, String.valueOf(image.getScaledWidth()));
                write(HtmlTags.PLAINHEIGHT, String.valueOf(image.getScaledHeight()));
                writeMarkupAttributes(markup);
                writeEnd();
                return;
            }
            
            default:
                return;
        }
    }