Create HTML page as string.
171739
def html_page(title="Page Title", body=""):
    """"""
    html = "<html>\n<head><title>%s</title></head>\n<body>\n" % (title)
    html += "<h1>%s</h1>\n" % (title)
    html += body
    html += "</body>\n</html>\n"
    return html
977196
def write(url, object_, **args):
    """"""
    default_content_type = ('text/plain', {'charset': 'US-ASCII'})
    content_encoding = args.get('content_encoding', 'base64')
    content_type, params = args.get('content_type', default_content_type)
    data = content_types.get(content_type).format(object_, **params)
    args['data'].write('data:{}'.format(content_type))
    for param, value in params.items():
        args['data'].write(';{}={}'.format(param, value))
    if content_encoding == 'base64':
        args['data'].write(';base64,{}'.format(base64.b64decode(data)))
    else:
        args['data'].write(',{}', urllib.quote(data))
    args['data'].seek(0)
573789
def as_html(self):
        
        url = '{prefix}{code}.html?download'.format(prefix=EPSG_IO_URL,
                                                    code=self.id)
        return requests.get(url).text
1175015
def to_html(threshold=50)
      html = "<html><table><tr><td></td>"
      html += @labels.map{|label| "<th>" + label.to_s +  "</th>"}.join
      html += "</tr>"
      self.each_row.with_index do |row, pos|
        next if pos > threshold && pos != self.length-1
        html += "<tr><th>" + @index[pos].to_s + "</th>"
        html += @labels.map{|label| "<td>" + row[label].to_s + "</td>"}.join
        html += "</tr>"
        html += "<tr><th>...</th>" + "<td>...</td>"*@labels.length + "</tr>" if pos == threshold
      end
      html += "</table>"
    end
1002824
def html(self, data='', py=True):
        

        if py:
            value = self.to_html(data)
        else:
            value = data
        if self.static:
            return str('<span class="value">%s</span>' % safe_str(value))
        else:
            if self.hidden:
                build = Hidden
            else:
                build = self.build
            self._get_http_attrs()
            return str(build(name=self.name, value=value, id=self.id, **self.html_attrs))
1158580
function buildHTML(segments) {
		var html = '';
		for (var i=0; i<segments.length; i++) {
			html += buildHTMLForSegment(segments[i]);
		}
		return html;
	}
931994
def _tmp_html(data):
    """"""
    filepath = ''
    try:
        fid, filepath = tempfile.mkstemp(suffix='.html', prefix='folium_')
        os.write(fid, data.encode('utf8'))
        os.close(fid)
        yield filepath
    finally:
        if os.path.isfile(filepath):
            os.remove(filepath)
1366816
def create_page(title, space, parrent_page_id=nil)
            params = { 'type' => 'page',
                'title' => title,
                'space' => {'key' => space},
                'body' => {
                    'storage' => {
                        'value' => ("#{ @body_message.to_json.gsub("&&", "&amp;&amp;").gsub(/\\u001b.../, "   ") }").force_encoding('UTF-8'),
                        'representation' => 'storage'
                        }
                    }
                }
            if parrent_page_id
                params['ancestors'] = [{'type' => 'page', 'id' => parrent_page_id}]
            end

            uri = URI.parse(@base_url)
            https = Net::HTTP.new(uri.host,uri.port)
            https.use_ssl = true
            # https.set_debug_output $stderr
            req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
            req.basic_auth(@user, @password)
            req['Accept'] = 'application/json'
            req.body = "#{params.to_json}"
            response = https.request(req)
            response = JSON.parse(response.body)
            if response["statusCode"] == 400
                puts response.inspect
                puts req.body.inspect
                puts "Create page: Error reporting to confluence: #{response["message"]}"
                raise "Create page: Error reporting to confluence: #{response["message"]}"
            else
                puts "Reported page creation."
            end
        end
729955
def main(api_key, markup):
    ''''''
    match = GIPHY.search(markup)

    attrs = None

    if match:
        attrs = dict(
            [(key, value.strip())
             for (key, value) in match.groupdict().items() if value])

    else:
        raise ValueError('Error processing input. '
                         'Expected syntax: {}'.format(SYNTAX))

    return create_html(api_key, attrs)
914511
def build_document(html_content, base_href=None):
    """"""
    assert html_content is not None

    if isinstance(html_content, unicode):
        html_content = html_content.encode("utf8", "xmlcharrefreplace")

    try:
        document = document_fromstring(html_content, parser=UTF8_PARSER)
    except (ParserError, XMLSyntaxError):
        raise ValueError("Failed to parse document contents.")

    if base_href:
        document.make_links_absolute(base_href, resolve_base_href=True)
    else:
        document.resolve_base_href()

    return document
362036
def je(self):
        
        """
        text = self._process()
        return self.make_string(text,join_str='',return_if_none='')
871263
def convert_msg_to_html(msg):
    """"""

    msg = re.sub("\n", "<br />", msg, flags=re.MULTILINE)
    return msg
987071
public function createPage()
    {
        $data = [
            "name" => request()->name,
            "description" => request()->description,
            "amount" => request()->amount
        ];

        $this->setRequestOptions();
        $this->setHttpResponse('/page', 'POST', $data);
    }
491151
def html_to_dom(html, default_encoding=DEFAULT_ENCODING, encoding=None, errors=DEFAULT_ENC_ERRORS):
    """"""
    if isinstance(html, unicode):
        decoded_html = html
        # encode HTML for case it's XML with encoding declaration
        forced_encoding = encoding if encoding else default_encoding
        html = html.encode(forced_encoding, errors)
    else:
        decoded_html = decode_html(html, default_encoding, encoding, errors)

    try:
        dom = lxml.html.fromstring(decoded_html, parser=lxml.html.HTMLParser())
    except ValueError:
        # Unicode strings with encoding declaration are not supported.
        # for XHTML files with encoding declaration, use the declared encoding
        dom = lxml.html.fromstring(html, parser=lxml.html.HTMLParser())

    return dom
1267822
function html(req, res) {
  fs.readFile(path.join(__dirname, 'index.html'), function read(err, file) {
    if (err) throw err;

    res.setHeader('Content-Length', file.length);
    res.writeHead(200, { 'Content-Type': 'text/html' });

    res.end(file);
  });
}
1201483
def to_html(input, context = {}, result = nil)
      result = call(input, context, result = nil)
      output = result[:output]
      if output.respond_to?(:to_html)
        output.to_html
      else
        output.to_s
      end
    end
183115
def create_html(self):
        """"""

        roc_dicts = []
        with open(self._roc_fn, "r") as roc:
            for line in roc:
                line = line.strip()
                if line != "" and line[0] != "#":
                    (q, M, w, m, P, U, u, T, t, x, a) = map(int, line.split("\t"))
                    roc_dict = {
                        "q": q,
                        "M": M,
                        "w": w,
                        "m": m,
                        "P": P,
                        "U": U,
                        "u": u,
                        "T": T,
                        "t": t,
                        "x": x,
                        "a": a,
                        "mapped": M + w + m + P,
                        "unmapped": U + u + T + t + x,
                    }
                    roc_dicts.append(roc_dict)
        tbody = os.linesep.join(
            [
                """
				<tr>
					<td>        {quality}                   </td>
					<td>        {mapped}                    </td>
					<td><small> {mapped_proc:.2f}   </small></td>
					<td>        {M}                         </td>
					<td><small> {M_proc:.2f}        </small></td>
					<td>        {w}                         </td>
					<td><small> {w_proc:.2f}        </small></td>
					<td>        {m}                         </td>
					<td><small> {m_proc:.2f}        </small></td>
					<td>        {P}                         </td>
					<td><small> {P_proc:.2f}        </small></td>
					<td>        {unmapped}                  </td>
					<td><small> {unmapped_proc:.2f} </small></td>
					<td>        {U}                         </td>
					<td><small> {U_proc:.2f}        </small></td>
					<td>        {u}                         </td>
					<td><small> {u_proc:.2f}        </small></td>
					<td>        {T}                         </td>
					<td><small> {T_proc:.2f}        </small></td>
					<td>        {t}                         </td>
					<td><small> {t_proc:.2f}        </small></td>
					<td>        {x}                         </td>
					<td><small> {x_proc:.2f}        </small></td>
					<td>        {sum}                       </td>
					<td>        {prec_proc:.3f}              </td>
				</tr>
			""".format(
                    quality=roc_dict["q"],
                    mapped=roc_dict["mapped"],
                    mapped_proc=100.0 * (roc_dict["mapped"]) / roc_dict["a"],
                    M=roc_dict["M"],
                    M_proc=100.0 * (roc_dict["M"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    w=roc_dict["w"],
                    w_proc=100.0 * (roc_dict["w"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    m=roc_dict["m"],
                    m_proc=100.0 * (roc_dict["m"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    P=roc_dict["P"],
                    P_proc=100.0 * (roc_dict["P"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                    unmapped=roc_dict["unmapped"],
                    unmapped_proc=100.0 * (roc_dict["unmapped"]) / roc_dict["a"],
                    U=roc_dict["U"],
                    U_proc=100.0 * (roc_dict["U"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    u=roc_dict["u"],
                    u_proc=100.0 * (roc_dict["u"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    T=roc_dict["T"],
                    T_proc=100.0 * (roc_dict["T"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    t=roc_dict["t"],
                    t_proc=100.0 * (roc_dict["t"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    x=roc_dict["x"],
                    x_proc=100.0 * (roc_dict["x"]) / (roc_dict["unmapped"]) if (roc_dict["unmapped"]) != 0 else 0,
                    sum=roc_dict["a"],
                    prec_proc=100.0 * (roc_dict["M"]) / (roc_dict["mapped"]) if (roc_dict["mapped"]) != 0 else 0,
                ) for roc_dict in roc_dicts
            ]
        )

        with open(self._html_fn, "w+") as html:
            program_info = ["No information available (PG header is essing)."]
            for x in rnftools.utils.shell(
                '"{samtools}" view -H "{bam}"'.format(
                    samtools="samtools",
                    bam=self._bam_fn,
                ), iterable=True
            ):
                x = x.strip()

                if x[:3] == "@PG":
                    pg_header = x[4:].strip()
                    parts = pg_header.split("\t")

                    program_info = ["<table>"]
                    for part in parts:
                        (lvalue, _, rvalue) = part.partition(":")
                        program_info.append(
                            '<tr><td style="font-weight:bold">{}:</td><td style="text-align:left">{}</td></tr>'.format(
                                lvalue, rvalue
                            )
                        )

                    program_info.append("</table>")

            eval_info = ["<table>"]
            for (lvalue, rvalue) in [
                ("BAM file", self._bam_fn),
                ("Allowed delta", self.report.allowed_delta),
            ]:
                eval_info.append(
                    '<tr><td style="font-weight:bold">{}:</td><td style="text-align:left">{}</td></tr>'.format(
                        lvalue, rvalue
                    )
                )

            eval_info.append("</table>")

            css_src = textwrap.dedent(
                """
					table            {border-collapse:collapse;}
					td               {border: solid #aaaaff 1px;padding:4px;text-align:right;}
					colgroup, thead  {border: solid black 2px;padding 2px;}
					.link_to_top     {font-size:10pt;}
					.desc            {color:#aaa;}
					.formats         {text-align:left;margin-bottom:20px;}
				"""
            )

            html_src = """<!DOCTYPE html>
				<html>
				<head>
					<meta charset="UTF-8" />
					<title>{name}</title>
					<style type="text/css">
					{css}
					</style>
				</head>
				<body>
					<h1 id="top">
						{name}
						<span class="link_to_top">
							[<a href="{homepage}">Back to main report</a>]
						</span>
					</h1>
	
					<p>
						<a href="#info_eval">Information about evaluation</a> -
						<a href="#info_prog">Information about program</a> -
						<a href="#roctable">ROC table</a> -
						<a href="#graphs">Graphs</a>
					</p>
	
					<h2 id="info_eval">
						Information about evaluation
						{headline_links}
					</h2>
	
					{eval_info}
	
					<h2 id="info_prog">
						Information about program
						{headline_links}
					</h2>
	
	
					{program_info}
	
					<h2 id="roctable">
						ROC table
						{headline_links}
					</h2>
	
					<p style="font-size:80%">
						<strong>M</strong>:
							mapped correctly
							<span class="desc">
								(all segments of tuple are mapped once and correctly),
							</span>
						<strong>w</strong>:
							mapped to wrong position
							<span class="desc">
								(at least one segment was mapped to a wrong position),
							</span>
						<strong>m</strong>:
							mapped but should be unmapped
							<span class="desc">
								(at least one segment was mapped but the read should not be mapped),
							</span>
						<strong>P</strong>:
							multimapped
							<span class="desc">
								(read should be mapped but it at least one segment was mapped several
								times and all segments were mapped correctly at least once),
							</span>
						<strong>U</strong>:
							unmapped correctly
							<span class="desc">
								(all segments of the read were correctly marked as unmapped),
							</span>
						<strong>u</strong>:
							unmapped but should be mapped
							<span class="desc">
								(at least one segment was mapped but entire read should be unmapped),
							</span>
						<strong>T</strong>:
							thresholded correctly
							<span class="desc">
								(read shoud not be mapped),
							</span>
						<strong>t</strong>:
							thresholded incorrectly
							<span class="desc">
								(read should be mapped),
							</span>
						<strong>x</strong>:
							unknown
							<span class="desc">
								(read is probably not reported by mapper)
							</span>
					</p>
					<table>
						<colgroup span="1" style="">
						<colgroup span="2" style="background-color:#ddd">
						<colgroup span="8" style="">
						<colgroup span="2" style="background-color:#ddd">
						<colgroup span="10" style="">
						<colgroup span="1" style="background-color:#ddd">
						<colgroup span="1" style="">
						<thead style="font-weight:bold;background-color:#ddddff">
							<tr style="font-weight:bold;background-color:#ddddff">
								<td>q</td>
								<td>mapped</td>
								<td>%</td>
								<td>M</td>
								<td>%</td>
								<td>w</td>
								<td>%</td>
								<td>m</td>
								<td>%</td>
								<td>P</td>
								<td>%</td>
								<td>unmapped</td>
								<td>%</td>
								<td>U</td>
								<td>%</td>
								<td>u</td>
								<td>%</td>
								<td>T</td>
								<td>%</td>
								<td>t</td>
								<td>%</td>
								<td>x</td>
								<td>%</td>
								<td>sum</td>
								<td>prec. (%)</td>
							</tr>
						</thead>
						<tbody>
							{tbody}
						</tbody>
					</table>
	
					<h2 id="graphs">
						Graphs
						{headline_links}
					</h2>
	
					<div class="formats">
						<img src="{svg}" />
						<br />
						<a href="{svg}">SVG version</a>
						|
						<a href="{roc}" type="text/csv">ROC file</a>
						|
						<a href="{gp}" type="text/plain">GP file</a>
					</div>
	
	
				</body>
				</html>
				""".format(
                name=self.name, tbody=tbody, css=css_src,
                svg=os.path.relpath(self._svg_fn, os.path.dirname(self._html_fn)),
                roc=os.path.relpath(self._roc_fn, os.path.dirname(self._html_fn)),
                gp=os.path.relpath(self._gp_fn, os.path.dirname(self._html_fn)), eval_info=os.linesep.join(eval_info),
                program_info=os.linesep.join(program_info),
                homepage=os.path.relpath(self.report.html_fn(), os.path.dirname(self._html_fn)), headline_links='''
							<span class="link_to_top">
								[<a href="#top">Top of this page</a>]
								[<a href="{homepage}">Back to main report</a>]
							</span>
						'''.format(homepage=os.path.relpath(self.report.html_fn(), os.path.dirname(self._html_fn)), )
            )

            tidy_html_src = bs4.BeautifulSoup(html_src).prettify()
            html.write(tidy_html_src)