从MS Word粘贴到Textarea中 [英] Paste from MS Word into Textarea
本文介绍了从MS Word粘贴到Textarea中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 https://github.com/akzhan/jwysiwyg/,我想要实现从Word粘贴,但是我不确定要查找什么以及如何处理它.我正在寻找正则表达式模式或要捕获的字符列表以及用它们替换的字符.
I'm using https://github.com/akzhan/jwysiwyg/ and i want to implement pasting from Word, but I'm not sure what to look for and how to handle it. Im more looking for a regex pattern or a list of characters to catch and what to replace them with.
想法?
推荐答案
我最终使用了这个:
// Replaces commonly-used Windows 1252 encoded chars that do not exist in ASCII or ISO-8859-1 with ISO-8859-1 cognates.
var replaceWordChars = function(text) {
var s = text;
// smart single quotes and apostrophe
s = s.replace(/[\u2018|\u2019|\u201A]/g, "\'");
// smart double quotes
s = s.replace(/[\u201C|\u201D|\u201E]/g, "\"");
// ellipsis
s = s.replace(/\u2026/g, "...");
// dashes
s = s.replace(/[\u2013|\u2014]/g, "-");
// circumflex
s = s.replace(/\u02C6/g, "^");
// open angle bracket
s = s.replace(/\u2039/g, "<");
// close angle bracket
s = s.replace(/\u203A/g, ">");
// spaces
s = s.replace(/[\u02DC|\u00A0]/g, " ");
return s;
}
//Use like:
var newText = replaceWordChars(textToCheck);
来自 http ://www.andornot.com/blog/post/Replace-MS-Word-special-characters-in-javascript-and-C.aspx
这篇关于从MS Word粘贴到Textarea中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文