防止 HTML Tidy 添加 li 元素

发布于 2024-12-21 10:50:50 字数 1092 浏览 3 评论 0原文

我正在使用 HTML Tidy 输出漂亮的 HTML 源代码并作为最终的编码检查。

然而,它采用了一个非常简单的列表,例如:

<ul id="navigation">
            <a href="index.php"><li>Summary</li></a>
            <a href="#"><li>Upload</li></a>
            <a href="accounts.php"><li>Accounts</li></a>
        </ul>

并将其转换为这个怪物:

 <ul id="navigation">
        <li style="list-style: none">
          <a href="index.php"></a>
        </li>
        <li id="active">Summary
        </li>

        <li style="list-style: none">
          <a href="#"></a>
        </li>
        <li>Upload
        </li>
        <li style="list-style: none">
          <a href="accounts.php"></a>
        </li>
        <li>Accounts
        </li>

      </ul>

我如何优雅地告诉它不要管我的列表?

我搜索了这些配置选项,但是我经常发现它们的命名不直观或解释不正确。

I am using HTML Tidy to output pretty HTML source and as a final encoding check.

However it is taking a very simple list such as:

<ul id="navigation">
            <a href="index.php"><li>Summary</li></a>
            <a href="#"><li>Upload</li></a>
            <a href="accounts.php"><li>Accounts</li></a>
        </ul>

and converting it to this monstrosity:

 <ul id="navigation">
        <li style="list-style: none">
          <a href="index.php"></a>
        </li>
        <li id="active">Summary
        </li>

        <li style="list-style: none">
          <a href="#"></a>
        </li>
        <li>Upload
        </li>
        <li style="list-style: none">
          <a href="accounts.php"></a>
        </li>
        <li>Accounts
        </li>

      </ul>

How do I gracefully tell it to leave my list alone?

I have searched these configuration options, however I often find they are not named intuitively or explained properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风铃鹿 2024-12-28 10:50:50

它实际上是在尝试更正您的标记以使其符合标准,您的

  • 标签应该位于 标签周围,而不是相反,也许如果你解决这个问题,那么它就不会尝试向列表中添加额外的项目。
  • 不过,您可以删除样式部分,只需修改您的 css 即可:

    ul.navigation li
    {
        list-style: none;
    }
    

    It's actually trying to correct your markup to make it conform to standards, your <li> tags should be around the <a> tags, not the other way around, maybe if you fix up that then it won't try to add extra items to the list.

    You can remove the style part though, just modify your css to have:

    ul.navigation li
    {
        list-style: none;
    }
    
    痴情 2024-12-28 10:50:50

    唯一的答案:首先给它有效的标记。 ul 的唯一合法子元素是 lia 元素不能是 ul 的子元素。

    <ul id="navigation">
        <li><a href="index.php">Summary</a></li>
        <li><a href="#">Upload</a></li>
        <li><a href="accounts.php">Accounts</a></li>
    </ul>
    

    如果您希望整个 li 可点击,请将 a 元素设置为 display: block

    #navigation li a {
        display: block;
    }
    

    The only answer: give it valid markup to start with. The only legal child element of a ul is an li. An a element cannot be a child of a ul.

    <ul id="navigation">
        <li><a href="index.php">Summary</a></li>
        <li><a href="#">Upload</a></li>
        <li><a href="accounts.php">Accounts</a></li>
    </ul>
    

    If you want the whole li to be clickable, style the a element as display: block:

    #navigation li a {
        display: block;
    }
    
    江湖彼岸 2024-12-28 10:50:50

    您的列表是无效标记; ul 元素只能包含 li 元素。 Tidy 实际上正在应用最明智的通用方法来修复此类损坏的标记:它将任何非 li 内容转换为 li 元素,列表公告将被抑制。

    因此,手动更改标记,

    <a href="index.php"><li>Summary</li></a>
    

    <li><a href="index.php">Summary</a></li>
    

    就像您想要的那样 如果他们期望当前的标记,这可能需要更改 CSS 或 JavaScript 代码。

    Your list is invalid markup; an ul element may only contain li elements. Tidy is actually applying the most sensible general approach to fixing such broken markup: it turns any non-li content to an li element for which the list bullter is suppressed.

    So manually change markup like

    <a href="index.php"><li>Summary</li></a>
    

    to

    <li><a href="index.php">Summary</a></li>
    

    which is probably what you want. This may require changes to CSS or JavaScript code, if they expect the current markup.

    ○闲身 2024-12-28 10:50:50

    标签移至

  • -s 中:
  • <li><a href="index.php">Summary</a></li>
    

    Move your <a> tags into <li>-s:

    <li><a href="index.php">Summary</a></li>
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文