how can I disable <style> element's movement?

View: New views
4 Messages — Rating Filter:   Alert me  

how can I disable <style> element's movement?

by 石瑞 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

input:
 
<div>
<style>
xxx
</style>
</div>
 
tidy output:
 
<html>
<head>
<style>
xxx
</style>
</head>
<body>
<div></div>
</body>
</html>
 
but I want this:
 
<html>
<head>
</head>
<body>
<div>
<style>
xxx
</style>
</div>
</body>
</html>
 
How can I disable the style element's movement? Thanks a lot!
 

Re: how can I disable <style> element's movement?

by Rijk van Geijtenbeek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Op Fri, 18 Sep 2009 06:48:57 +0200 schreef 石瑞 <shirui@...>:

input:
 
<div>
<style>
xxx
</style>
</div>
 
tidy output:
 
<html>
<head>
<style>
xxx
</style>
</head>
<body>
<div></div>
</body>
</html>
 
but I want this:
 
<html>
<head>
</head>
<body>
<div>
<style>
xxx
</style>
</div>
</body>
</html>
 
How can I disable the style element's movement? Thanks a lot!
 

That's not possible I think. Note that in HTML, the style element is supposed to be in the head, it is not allowed in the body. So tidy does what its name implies: tidies up the wrong placement of the style element.

--
Rijk van Geijtenbeek
Opera Software ASA
http://my.opera.com/Rijk/blog/

"The most common way to get usability wrong is to listen to what users
say rather than actually watching what they do." - J.Nielsen

Re: how can I disable <style> element's movement?

by Keryx Web :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009-09-18 06:48, 石瑞 skrev:

> *How can I disable the style element's movement? Thanks a lot!*

You have already got an answer. Let me just elaborate on this issue.

When the browser parses the markup it will hoist the style-element to
the document head. Every single browser will put it there in its DOM.

Tidy just makes explicit what is already implicit, i.e. it makes your
code conform to the rules, so that the markup exactly matches the DOM.
That is a good thing.

There are two things you might be trying to achieve:

1. A local style, that really belongs in an attribute. Or better yet,
that you should reference with a selector, probably class- or id-.

2. A scoped style, which is a new concept in HTM5. Scoped styles will
not be hoisted to the head. But they are unsopprted in every browser
today, even Firefox 3.5, Opera 10, Safari 4 or Chrome 3. I.e. this
concept is not usable. When it becomes doable you stop the hoisting with
the attribute 'scoped="true"'.

Tidy is not HTML5 aware and will not honor such markup, though.

Scoped styles are not usable in real life projects for many years yet.

--
Keryx Web (Lars Gunther)
http://keryx.se/
http://twitter.com/itpastorn/
http://itpastorn.blogspot.com/


Re: Re: how can I disable <style> element's movement?

by 石瑞 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Keryx Web, thank you very much.

I have solved my problem through your first method, its really a clever way. Thanks a lot!






发件人: Keryx Web
发送时间: 2009-09-18  17:15:55
收件人: shirui
抄送: html-tidy
主题: Re: how can I disable <style> element's movement?
 
2009-09-18 06:48, 石瑞 skrev:
> *How can I disable the style element's movement? Thanks a lot!*
You have already got an answer. Let me just elaborate on this issue.
When the browser parses the markup it will hoist the style-element to
the document head. Every single browser will put it there in its DOM.
Tidy just makes explicit what is already implicit, i.e. it makes your
code conform to the rules, so that the markup exactly matches the DOM.
That is a good thing.
There are two things you might be trying to achieve:
1. A local style, that really belongs in an attribute. Or better yet,
that you should reference with a selector, probably class- or id-.
2. A scoped style, which is a new concept in HTM5. Scoped styles will
not be hoisted to the head. But they are unsopprted in every browser
today, even Firefox 3.5, Opera 10, Safari 4 or Chrome 3. I.e. this
concept is not usable. When it becomes doable you stop the hoisting with
the attribute 'scoped="true"'.
Tidy is not HTML5 aware and will not honor such markup, though.
Scoped styles are not usable in real life projects for many years yet.
--
Keryx Web (Lars Gunther)
http://keryx.se/
http://twitter.com/itpastorn/
http://itpastorn.blogspot.com/