博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HTML Clipboard Format [MSDN资料]
阅读量:5809 次
发布时间:2019-06-18

本文共 8432 字,大约阅读时间需要 28 分钟。

 This article discusses cutting and pasting fragments of an HTML document. The CF_HTML clipboard format allows a fragment of raw HTML text and its context to be stored on the clipboard as ASCII. This allows the context of the HTML fragment, which consists of all preceding and surrounding tags, to be examined by an application so that the surrounding tags can be noted with their attributes. Although it is up to an application to interpret such fragments, some basic guidelines are included here based on MSHTML implementations.

This article covers the following topics:

  •  
    •  
    •  
    •  
  •  
    •  
    •  
    •  
    •  

Overview of CF_HTML

CF_HTML is entirely text format and uses the transformation format UTF-8. It includes a description, a context, and within the context, the fragment. The format name of a clipboard containing CF_HTML data is HTML Format. Therefore, if you use functions such as , pass "HTML Format" in the format name parameter. This section gives a code example of a clipboard using CF_HTML and discusses the three components of the CF_HTML clipboard format.

The following is an example of a clipboard fragment:

 
 
Version:0.9    StartHTML:71    EndHTML:170    StartFragment:140    EndFragment:160    StartSelection:140    EndSelection:160                The HTML Clipboard                 

The Fragment

Description

The description includes the clipboard version number and offsets, indicating where the context and the fragment start and end. The description is a list of ASCII text keywords followed by a string and separated by a colon (:).

Version vv Version number of the clipboard. Starting version is 0.9.
StartHTML Byte count from the beginning of the clipboard to the start of the context, or -1 if no context.
EndHTML Byte count from the beginning of the clipboard to the end of the context, or -1 if no context.
StartFragment Byte count from the beginning of the clipboard to the start of the fragment.
EndFragment Byte count from the beginning of the clipboard to the end of the fragment.
StartSelection Byte count from the beginning of the clipboard to the start of the selection.
EndSelection Byte count from the beginning of the clipboard to the end of the selection.

The StartSelection and EndSelection keywords are optional because sufficient information for basic pasting is included in the fragment description. However, the selection information indicates the exact HTML area the user has selected. This adds more information to the fragment description.

Other information may be added in the description section. For example, multiple pairs of StartFragment/EndFragment could be added to support noncontiguous selection of fragments. Also, Windows Internet Explorer places a  in the description section. This allows handlers of CF_HTML to resolve relative links within a file (such as when CF_HTML text is pasted into a DHTML Edit Control host).

The only character set supported by the clipboard is Unicode in its UTF-8 encoding. Because the first characters of UTF-8 and ASCII match, the description is always ASCII, but the bytes of the context (starting at StartHTML) may use any other characters coded in UTF-8. Ends of lines may be represented in a clipboard format header as Carriage Return (CR), carriage return/line feed (CR/LF), or Line Feed (LF).

Context

When working with a complete document, the context is the entire HTML document. Because this discussion is limited to copying and pasting a fragment of a document, the context is the selected fragment and all preceding and surrounding start and end tags. These tags represent all the parent nodes of the fragment, up to the HTML node. The context also contains the complete  element and allows the  and  elements to be included. Sufficient information is included in the fragment for a basic pasting operation. However, if your application requires information concerning the tags surrounding the fragment, you must store the context on the clipboard.

An application copying a fragment of HTML to the clipboard may choose to create a base element to include in the context so that partial URLs in the fragment can be resolved.

Fragment

The fragment contains valid HTML representing the area the user has selected. This includes the information required for basic pasting of an HTML fragment, as follows:

  • Selected text.
  • Opening tags and attributes of any element that has an end tag within the selected text.
  • End tags that match the included opening tags.

The fragment should be preceded and followed by the HTML comments <!--StartFragment--> and <!--EndFragment--> (no space allowed between the !-- and the text) to indicate where the fragment starts and ends. So the start and end of the fragment are indicated by these comments as well as by the StartFragment and EndFragment byte counts. Though redundant, this makes it easier to find the start of the fragment (from the byte count) and mark the position of the fragment directly in the HTML tree.

Scenarios

The following scenarios describe how the MSHTML HTML editor handles HTML cutting and pasting; other applications may or may not follow these scenarios. The clipboard format described here is intended to allow flexibility for the way an application functions. These scenarios show only well-formed HTML.

Simple Fragment of HTML

HTML text:

 
 
 This is normal. This is bold. This is bold italic. This is italic. 

This appears as:

This is normal. This is bold. This is bold italic. This is italic.

The text between the ** is selected and copied to the clipboard:

This is normal. This is **bold. This is bold italic. This** is italic.

In this scenario only the  element and the  element appear in the context as it precedes the selected fragment. Note that start tags and end tags are included in the context. The selection, delimited by StartSelection and EndSelection, is shown in bold. This is what will be on the clipboard (note this is MSHTML's interpretation).

 
 
Version:0.9 StartHTML:71 EndHTML:160 StartFragment:130 EndFragment:150 StartSelection:130 EndSelection:150      
bold. This is bold italic. This

Fragment of a Table in HTML

HTML text:

 
 
Head1 Item 1 Item 2 Item 3 Item 4
Item 5 Item 6 Item 7 Item 8
Head2 Item 9 Item 10 Item 11 Item 12

This appears as:

Head1 Item 1 Item 2 Item 3 Item 4
Item 5 Item 6 Item 7 Item 8
Head2 Item 9 Item 10 Item 11 Item 12

The Item 6, Item 7, Item 10, and Item 11 elements of the table are selected as a block and copied to the clipboard. The following is an MSHTML interpretation of what will be on the clipboard.

 
 
 
Item 6 Item 7
Item 10 Item 11

Pasting a Fragment of an Ordered List into Plain Text

HTML text:

 
 
  1. Item 1
  2. Item 2
  3. Item 3
  4. Item 4
  5. Item 5
  6. Item 6

This appears as:

  1. Item 1
  2. Item 2
  3. Item 3
  4. Item 4
  5. Item 5
  6. Item 6

The user selects and copies items 3 through 5 to the clipboard. The following HTML is in the clipboard.

 
 
  1. Item 3
  2. Item 4
  3. Item 5

If this fragment is now pasted into an empty document, the following HTML will be created:

 
 
  1. Item 3
  2. Item 4
  3. Item 5

This appears as:

  1. Item 3
  2. Item 4
  3. Item 5

Pasting a Partially Selected Region

HTML text:

MSHTML is a WYSIWYG Editor that supports:

  • Cut
  • Copy
  • Paste

This is a great tool!

This appears as:

MSHTML is a WYSIWYG Editor that supports:

  • Cut
  • Copy
  • Paste

This is a great tool!

The user selects from "WYSIWYG" to "Cop". The following HTML is in the clipboard.

WYSIWYG Editor that supports:

  • Cut
  • Cop

The user selects from "opy" to "great". The following HTML is in the clipboard.

 
 
  • opy
  • Paste

This is a great

参考资料:

 

 

转载于:https://www.cnblogs.com/08shiyan/archive/2011/11/22/2258779.html

你可能感兴趣的文章
【Visual Studio 扩展工具】如何在ComponentOne的DataTree中实现RightToLeft布局
查看>>
JS系列之BOM
查看>>
一次生产 CPU 100% 排查优化实践
查看>>
【跃迁之路】【661天】程序员高效学习方法论探索系列(实验阶段418-2018.12.05)...
查看>>
浅谈JS中的数据类型
查看>>
koa2系列教程:koa2使用模板引擎
查看>>
算法:插入排序
查看>>
传统企业装上“智慧大脑” 看阿里巴巴如何实践AI赋能
查看>>
git 详解及实用指南之二 (远程操作)
查看>>
Ubuntu 环境下的mysql 远程访问,redis 远程访问和设置密码 ,mongo 安装 ,设置用户密码,开启远程访问...
查看>>
【vuejs进阶】 vuejs路由实现原理
查看>>
推荐 9 个样式化组件的 React UI 库
查看>>
【数据科学系统学习】机器学习算法 # 西瓜书学习记录 [3] Logistic 回归实践
查看>>
小程序之图片懒加载[完美方案,你不来看看?]
查看>>
Slog32_漫谈生活和人生
查看>>
Swoole 源码分析——锁与信号量模块
查看>>
使用Sequelize连接数据库
查看>>
入门系列之 使用Winston记录Node.js应用程序
查看>>
前端每日实战:101# 视频演示如何用 CSS 和 D3 创作一组摆线
查看>>
encodeURI、encodeURIComponent、decodeURI、decodeURIComponent的区别
查看>>