Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用样式定义解析类属性_C#_Html_Css_Regex_Styles - Fatal编程技术网

C# 使用样式定义解析类属性

C# 使用样式定义解析类属性,c#,html,css,regex,styles,C#,Html,Css,Regex,Styles,我将具体说明: 如何替换 <style type="text/css"> .class1 {font-weight:bold; font-size:10pt;} .class2 {font-weight:bold; font-size:12pt;} ... .classN {font-weight:bold; font-size:8pt; vertical-align:sub;} </style> <div class="class2" s

我将具体说明:

如何替换

<style type="text/css">
   .class1 {font-weight:bold; font-size:10pt;}
   .class2 {font-weight:bold; font-size:12pt;}
   ...
   .classN {font-weight:bold; font-size:8pt; vertical-align:sub;}
</style>

<div class="class2" style="color:blue;">
   Bold Text
</div>

.class1{字体大小:粗体;字体大小:10pt;}
.class2{字体大小:粗体;字体大小:12pt;}
...
.classN{字体大小:粗体;字体大小:8pt;垂直对齐:子;}
粗体文本
为此:

<div style="color:blue; font-weight:bold; font-size:12pt;">
   Bold Text
</div>

粗体文本
**注意 -节点可以是任何节点 -我不在乎。 -类属性不需要剥离

有没有HTML方法(C#)可以做到这一点?正则表达式?有什么想法吗


提前谢谢

如果您正在使用jquery,您可以使用以下插件:

/*
 * getStyleObject Plugin for jQuery JavaScript Library
 * From: http://upshots.org/?p=112
 *
 * Copyright: Unknown, see source link
 * Plugin version by Dakota Schneider (http://hackthetruth.org)
 */

(function($){
    $.fn.getStyleObject = function(){
        var dom = this.get(0);
        var style;
        var returns = {};
        if(window.getComputedStyle){
            var camelize = function(a,b){
                return b.toUpperCase();
            }
            style = window.getComputedStyle(dom, null);
            for(var i=0;i<style.length;i++){
                var prop = style[i];
                var camel = prop.replace(/\-([a-z])/g, camelize);
                var val = style.getPropertyValue(prop);
                returns[camel] = val;
            }
            return returns;
        }
        if(dom.currentStyle){
            style = dom.currentStyle;
            for(var prop in style){
                returns[prop] = style[prop];
            }
            return returns;
        }
        return this.css();
    }
})(jQuery);
/*
*jQuery JavaScript库的getStyleObject插件
*发件人:http://upshots.org/?p=112
*
*版权:未知,请参阅源链接
*达科塔施耐德插件版本(http://hackthetruth.org)
*/
(函数($){
$.fn.getStyleObject=函数(){
var dom=this.get(0);
var风格;
var返回={};
if(window.getComputedStyle){
var camelize=函数(a,b){
返回b.toUpperCase();
}
style=window.getComputedStyle(dom,null);

对于(var i=0;i使用此工具将HTML/CSS转换为内联CSS=


仅在必要时使用此选项,例如设置基于HTML的电子邮件的样式等。

您想从样式块中删除样式规则并将其内联移动?并且您想在运行时执行此操作?对,内联和运行时。我认为您在一开始就违背了创建样式的全部目的。您为什么不让浏览器来处理这些问题呢ouCause不是使用它的浏览器,它是一个所见即所得的应用程序,它从html(剪贴板)转换数据我不明白你为什么要这样做,特别是因为你说类属性不需要剥离。为什么不把样式表修改成.class1、.class2、.class3、…classN{color:blue,font-weight:bold;font-size:12pt;}让风格发挥作用?…啊,我们同时回答了,很抱歉好吧,我发现了一个类似的问题,解决了我在c中的问题#谢谢大家![[1][1]:
<div class="class2" style="color:blue;">
   Bold Text
</div>
<script type="text/javascript">
  var computedStyle;
  $("div[class^='class']").each(function(){
    computedStyle = $(this).getStyleObject();
    $(this).css(computedStyle);
    $(this).attr('class','');
  });
</script>