如何处理HTML文档和剪贴板

如何处理HTML文档和剪贴板,第1张

使用带有Windows

剪贴板的CF_HTML

Clipboard

Format的确容易让人搞胡涂,一部分是因为它不是clipboard

format中自带的剪贴板;它是一个注册格式(registered

format),所以不是一个常量,因为它的值会因为系统的不同而产生变化。你可以通过一个简单的API调用

--

RegisterClipboardFormat来获得一个注册剪贴板格式的值。这个函数的首次调用会通过一个给定的字符串来执行,它返回一个范围在C000-FFFF之间的唯一值。每一个在系统上处理的后续调用(subsequent

call)会返回同样的值。用于这种格式中的关键字符串就是“HTML

Format”:

你必须首先构建一个描述性的header,并在将HTML数据放入剪贴板之前先把它放到数据中。这个header会给其他程序提供描述版本信息、HTML起始数据的偏移量(offset),以及有关实际选择范围(actual

selection)起始地方的信息。用户可能会选择的HTML文档的一部分甚至只是一个元素(比如一个table中的几行)作为一个选择区域。页面的其他部分,比如内联样式定义(inline

style

definitions)则可能会被要求进行完全渲染(render)。你不仅需要将最初所选择的HTML区域放入剪贴板,而且还需要放入一个header,它看起来就像是这样:

Version:1.0

StartHTML:000000258

EndHTML:000001491

StartFragment:000001172

EndFragment:000001411

应应用程序通过StartFragment和EndFragment属性来决定哪些数据需要粘贴,这些数据或许会(也可能不会)用剩下的HTML对所选择的部分进行格式安排。你必须将HTML注释放入数据中以便将来对所选部分进行识别。很明显,你必须在构建最后的header之前完成它,否则偏移量会有变化。一个用于所选数据的opening/closing注释标签分别是“

StartFragment

”和“

EndFragment

可以自动格式化的。

先打开Brackets编辑器,可以看到左边是目录,右边是代码区。

打开一个HTML文件,右上角有个闪电样子的图标就是实时预览功能,需要电脑中安装Chrome浏览器

其他的编辑器比如sublime之所以强大是因为有很多插件的支持,可以打造最适合自己的编辑器,那Brackets有没有插件呢?经过一番寻找终于找到:

点击文件--扩展管理器

可以看到里面有很多插件

3、而格式化代码是比较常用的功能,里面会不会有呢?先模糊搜索一下把,输入format关键字搜索,看见的第一个插件Beautify,名字听起来不 错,再看下介绍:Format JavaScript, HTML, and CSS files,正和我们的需要,点击安装它:

安装完成先别着急关掉扩展管理器,点击Beautify下面的更多信息,进入它在github的主页,往下看可以看到这样一行字:

Format HTML, CSS, and JavaScript files by Edit >Beautify menu or Cmd-Alt-L(Mac) / Ctrl-Alt-L(Win) key.

也就是说从Edit-Beautify可以找到它,而且快捷键是Ctrl+Alt+L

邮件有很多中显示形式,显示形式主要取决于其MIME类型,每种显示形式有相应的内容,他们之间用分割符号分开。一下是一个构造邮件主体内容的类:

<?php

//

// Definition of tsNotificationMailHandle

r class

//

// Created on: <01-Nov-2002 13:51:17

amos>

//

// SOFTWARE NAME: eZ Publish

// SOFTWARE RELEASE: 4.0.1

// BUILD VERSION: 22260

// COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS

// SOFTWARE LICENSE: GNU General Public License v2.0

// NOTICE: >

// This program is free

softwareyou can redistribute it and/or

// modify it under the terms of

version 2.0 of the GNU General

// Public License as published

by the Free Software Foundation.

//

// This program is distributed

in the hope that it will be useful,

// but WITHOUT ANY WARRANTY

without even the implied warranty of

// MERCHANTABILITY or FITNESS

FOR A PARTICULAR PURPOSE. See the

// GNU General Public License

for more details.

//

// You should have received a

copy of version 2.0 of the GNU General

// Public License along with

this programif not, write to the Free

// Software Foundation, Inc.,

51 Franklin Street, Fifth Floor, Boston,

// MA 02110-1301, USA.

//

//

class tsNotificationMailHandler

{

public

function __construct( $plainText = false, $htmlText = false )

{

$this->setPlainText( $plainText )

$this->setHtmlText( $htmlText )

}

function

setPlainText( $text )

{

$this->plainText = $text

}

function

setHtmlText( $text )

{

$this->htmlText = $text

}

function

getRandomBoundary($offset = 0)

{

srand(time()+$offset)

return ( "----" . ( md5( rand() ) ) )

}

function

build()

{

$mailBody = false

$bodyBoundary = $this->getRandomBoundary()

//add the

body and boundary of the mail

if

($this->plainText != "")

{

$mailBody .=

"--".$bodyBoundary. "\n"

$textHeader

= $this->formatTextHeader()

$mailBody .=

$textHeader

}

if

($this->htmlText != "")

{

$mailBody .=

"--".$bodyBoundary. "\n"

$htmlHeader

= $this->formatHTMLHeader()

$mailBody .=

$htmlHeader

}

$mailBody .=

"\n--".$bodyBoundary. "--"

return

$mailBody

}

function

formatTextHeader()

{

$outTextHeader = ""

$outTextHeader .= "Content-Type: text/plain

charset=utf-8\n"

$outTextHeader .= "Content-Transfer-Encoding: 7bit\n\n"

$outTextHeader .= $this->plainText. "\n"

return $outTextHeader

}

function

formatHTMLHeader()

{

$outHTMLHeader = ""

$outHTMLHeader .= "Content-Type: text/htmlcharset=utf-8\n"

$outHTMLHeader .= "Content-Transfer-Encoding: 7bit\n\n"

$outHTMLHeader .= $this->htmlText. "\n"

return $outHTMLHeader

}

private

$htmlText

private

$plainText

}

两个私有属性分别存放两种类型的内容,内容是在构造函数中传参的,调用自身的build()方法去构造最终的显示内容并且返回。

在外部可以这样调用:

$mail->extractEmail( $addressItem, $email, $name

)

$mail->addBcc( $email, $name )

$mail->addReceiver( $email, $name )

$mail->setContentType('multipart/alternative','utf-8',false,false,$parameters['boundary'])

$mail->setSender( $emailSender )

$mail->setSubject( $subject )

$mail->setBody( $body )

这个$body 就是调用类中的build方法返回的内容。

这个$mail对象的类型不定,这儿只是一个例子,mail的具体类型可以自己写,无非就是设置头部,设置发送人,接受人之类的信息。

需要特别注意的是内容是纯文本和html两种格式的头部设置邮件的类型为:multipart/alternative另一个参数是分割服,boundary,这个分割符可以调用上边类的方法getRandomBoundary()。

最终邮件源码发送出来以后就是下面这样的 形式,分割符号把不同的内容分割开来:

From - Thu Oct 14 14:44:52 2010

X-Account-Key: account3

X-UIDL: 1tbiEAVqTUiNYqIyFAAAsR

X-Mozilla-Status: 0001

X-Mozilla-Status2: 00000000

X-Mozilla-Keys:

Received: from xiuji.cai (unknown [220.248.96.170])

by mx14 (Coremail) with SMTP id QMCowLBbLySDprZMTt4mBw--.179S2

Thu, 14 Oct 2010 14:43:16 +0800 (CST)

Received: from xiuji.cai (localhost [127.0.0.1])

by xiuji.cai (8.14.3/8.14.3) with ESMTP id o9E6hkhO024008

for <xiujixin@163.com>Thu, 14 Oct 2010 14:43:46 +0800

Received: (from hannes@localhost)

by xiuji.cai (8.14.3/8.14.3/Submit) id o9E6hkIe024007

Thu, 14 Oct 2010 14:43:46 +0800

X-Authentication-Warning: xiuji.cai: hannes set sender to jinxiudaxin@hotmail.com using -f

To: xiujixin@163.com

Subject: Article "rrrrrrr" was published [admin.trustedsources.co.uk - China Blog]

Date: Thu, 14 Oct 2010 06:43:46 +0000

From: Hannes Cai <jinxiudaxin@hotmail.com>

MIME-Version: 1.0

Content-Type: multipart/alternativecharset=utf-8boundary="----c0459eef8a3391dc84f2418f0d8722a1"

Content-Transfer-Encoding:

8bit

Content-Disposition: inline

User-Agent: eZ Publish, Version 4.0.1

Message-ID: <node.16075.eznotification@admin.trustedsources.co.uk>

References: <node.1.eznotification@admin.trustedsources.co.uk>

<node.2.eznotification@admin.trustedsources.co.uk>

<node.15808.eznotification@admin.trustedsources.co.uk>

<node.15809.eznotification@admin.trustedsources.co.uk>

In-Reply-To:

<node.15809.eznotification@admin.trustedsources.co.uk>

X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73

VFW2AGmfu7jjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUyppBDUUUU

------c0459eef8a3391dc84f2418f0d8722a1

Content-Type: text/plaincharset=utf-8

Content-Transfer-Encoding: 7bit

This email is to inform you that a new item has been published at admin.trustedsources.co.uk.

The item can be viewed by using the URL below.

rrrrrrr - Hannes Cai http://admin.trustedsources.co.uk/blog/china/rrrrrrr

If you do not want to continue receiving these notifications,

please change your settings at:

http://admin.trustedsources.co.uk/notification/settings

-----------------

admin.trustedsources.co.uk notification system

------c0459eef8a3391dc84f2418f0d8722a1

Content-Type: text/htmlcharset=utf-8

Content-Transfer-Encoding: 7bit

<html>

<head>

</head>

<body>

<font color="#00ff00">this is the html template!</font>

</body>

</html>

------c0459eef8a3391dc84f2418f0d8722a1--


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7414002.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存