【问题标题】:Format HTML using tidymanaged使用 tidymanaged 格式化 HTML
【发布时间】:2016-08-05 08:57:17
【问题描述】:

我正在使用Tidymanaged 来格式化 HTML..

                using (Document doc = Document.FromFile(AppPath + "/" + DefaultFileName))
                {
                    doc.ShowWarnings = false;
                    doc.Quiet = true;
                    doc.DocType = TidyManaged.DocTypeMode.Strict;
                    doc.DropFontTags = true;
                    doc.UseLogicalEmphasis = true;
                    doc.OutputXhtml = false;
                    doc.OutputXml = false;
                    doc.MakeClean = true;
                    doc.DropEmptyParagraphs = true;
                    doc.CleanWord2000 = true;
                    doc.QuoteAmpersands = true;
                    doc.JoinStyles = false;
                    doc.JoinClasses = false;
                    doc.Markup = true;
                    doc.IndentSpaces = 4;
                    doc.IndentBlockElements = TidyManaged.AutoBool.Yes;
                    doc.CharacterEncoding = TidyManaged.EncodingType.Utf8;
                    doc.WrapSections = false;
                    doc.WrapAttributeValues = false;
                    doc.WrapScriptLiterals = false;
                    doc.CleanAndRepair();
                    parsed = doc.Save();
                }

它运行良好,但 HTML 格式不正确,在 4 5 个单词后它会换行...它提供 HTML 之类的

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta name="generator" content=
        "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
        <link rel="stylesheet" type="text/css" href=
        "../lib/styles/default/general_app.css">
        <link rel="stylesheet" type="text/css" href=
        "../lib/styles/default/agent_app.css">
        <link rel="stylesheet" type="text/css" href=
        "../lib/styles/default/calendar.css">
        <script type="text/javascript" src=
        "../lib/scripts/usertrap.js">
</script>
        <script type="text/javascript" src=
        "../lib/scripts/popup.js">
</script>

我想要的 HTML 是这样的,

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                <head>
                    <meta name="generator" content="HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
                    <link rel="stylesheet" type="text/css" href="../lib/styles/default/general_app.css">
                    <link rel="stylesheet" type="text/css" 
   href="../lib/styles/default/agent_app.css">
                    <link rel="stylesheet" type="text/css" 
   href="../lib/styles/default/calendar.css">
                    <script type="text/javascript" src="../lib/scripts/usertrap.js">
            </script>
                    <script type="text/javascript" src="../lib/scripts/popup.js">
            </script>

【问题讨论】:

    标签: c# jquery html


    【解决方案1】:

    要防止换行,请添加以下内容:

    doc.WrapAt = 0;
    

    默认值为 68,因此将在该行长度处换行。设置为零以防止换行:http://tidy.sourceforge.net/docs/quickref.html#wrap

    【讨论】:

    • 它有效..但它删除了 的结束标记..我想要链接标记,因为它在 html 文件中,无论它是 还是 ..有可能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多