Take for instance this XHTML snippet:
<!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>
<title>A webpage</title>
</head>
<body>
<p>
<form action="something.php" method="get">
<input type="submit" value="Hello"/>
</form>
</p>
</body>
</html>
The tree should be valid, however this won't parse correctly in a browser.
Look at the error messages that you get when you try that with http://validator.w3.org
Apart from a warning that you haven't specified a character encoding (and that it's therefore assuming UTF-8), the main error is that a <p> isn't allowed to contain non-inline content. You can either remove the <p> and </p> completely, or, move them inside the <form>.
As for 'why', it's because that's how it's defined in the schema which defines what is and what is not valid XHTML. If you look at this section of the XHTML definition you'll see that <p> is only allowed to contain text or 'inline' (not 'block') tags. However a <form> counts as 'block' content not as 'inline' content.
In other words, a form can contain paragraphs, but a paragraph cannot contain forms.
According to this, because:
Line 8, Column 44: document type does
not allow element "form" here; missing
one of "object", "ins", "del", "map"
start-tag ✉
The mentioned element is not allowed
to appear in the context in which
you've placed it; the other mentioned
elements are the only ones that are
both allowed there and can contain the
element mentioned. This might mean
that you need a containing element, or
possibly that you've forgotten to
close a previous element.
One possible cause for this message is
that you have attempted to put a
block-level element (such as "p" or
"table") inside an inline element
(such as "a", "span", or
"font").
Line 9, Column 40: document type does
not allow element "input" here;
missing one of "p", "h1", "h2", "h3",
"h4", "h5", "h6", "div", "pre",
"address", "fieldset", "ins", "del"
start-tag
input type="submit" value="Hello" The mentioned
element is not allowed to appear in
the context in which you've placed it;
the other mentioned elements are the
only ones that are both allowed there
and can contain the element mentioned.
This might mean that you need a
containing element, or possibly that
you've forgotten to close a previous
element.
One possible cause for this message is
that you have attempted to put a
block-level element (such as "p" or
"table") inside an inline element
(such as "a", "span", or
"font").
Try using the W3C Markup Validator, which will tell your what is invalid with most (X)HTML and CSS documents.
You can't put form inside paragraph. Write like this:
<body>
<form action="something.php" method="get">
<p>
<input type="submit" value="Hello"/>
</p>
</form>
</body>
I ran a test with your HTML code through validator.w3.org and the result is that you need to swap the P and FORM tags for it to pass as valid W3C 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>
<title>A webpage</title>
</head>
<body>
<form action="something.php" method="get">
<p>
<input type="submit" value="Hello"/>
</p>
</form>
</body>
</html>
Related
Is there a way to change the "Exam 1" to another word like "Homework 1" by passing arguments?
If not, is there a default template I can modify?
My last resort is to modify the built html files but it's not very convenient.
The exams2html() function takes an argument template which defaults to "plain.html". This template is shipped with the exams package and contains:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Exam ##ID##</title>
<style type="text/css">
body{font-family: Arial, Helvetica, Sans;}
</style>
<meta charset="utf-8" />
</head>
<body>
<h2>Exam ##ID##</h2>
##\exinput{exercises}##
</body>
</html>
The ##ID## is replaced by the ID (from 1 to n) and the ##\exinput{exercises}## is replaced by an ordered list <ol> containing the questions and optionally also the solutions. You can modify this template in any way you need and call it, say, homework.html. Then you can call:
exams2html(..., template = "/path/to/homework.html",
question = "<h4>Exercise</h4>", solution = FALSE)
which sets the template and also modifies the way the question is displayed while suppressing the solution.
Remark: The placeholders ##ID## and ##\exinput{exercises}## are a bit awkward (analogous to the placeholders in LaTeX templates for exams2pdf()) and not very flexible. It has been on my wishlist to make this more flexible, e.g., using {{mustache}} templating via the whisker package, but so far I didn't get round to tackle that.
I have a very simple webpage.
<html>
<head>
<title/>
</head>
<body>
<h1>hello</h1>
</body>
</html>
breaks my webpage ,both in Chrome and Firefox
the issue is with self-closing Title tag ,removing TITLE tag or adding a title fix the issue
<title>Test Page</title>
Whats the issues with self-closing TITLE tags , couldn't find any reference to say its invalid
If you have a void element:
<img />
<br />
Then they have no content, because there's nowhere to put it. Images can be thought of as an empty <div> with a background image.
Compared to these elements:
<h1>Hello</h1>
<section>World</section>
Which actually contain stuff (in this case, text).
The reason that the <title/> breaks your page is because you need a title in a webpage - if you don't have one, it'll just display the URL of the page, for example:
google.com/index.html
You need to have a valid title, and <title> is not a void element. This is why it breaks. To see this, go to a HTML validation website (e.g. https://validator.w3.org) and see what it tells you.
In short - <title> is not a void element - it requires an opening and closing tag.
EDIT: Research showed me this website, which says:
Self-closing: No
So in short they're not self-closing elements. You can find a list of self-closing elements here.
The following code segment for an FAQ, which uses XHTML 1.0, will not validate successfully in the W3C validator.
I’m inserting the Q&A into a definition list in order to maintain the question & answer relationship semantically. The problem is, the questions can be multiple paragraphs. And the <dt> tag, at least in XHTML 1.0, only allows for inline elements. So I can’t put a <p> tag in there without throwing an error in the W3C validator.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<dl>
<dt>
<p>This is a very long question.</p>
<p>It has multiple paragraphs.</p>
</dt>
<dd>
<p>This is the answer</p>
</dd>
</dl>
</body>
</html>
Is there a semantically better way of coding this using XHMTL 1.0 Transitional?
For reference, the latest similar thread I can find on the topic is this is What is the best way to semanticly structure a FAQ?. The thread was useful, however it does not cover multiple paragraphs in the question.
Using the dl element doesn’t seem to be appropriate.
XHTML 1.0 uses the element definitions from HTML 4.01, where the dl element is defined to be a "definition list". A list of Q&As is probably not a definition list (unless, maybe, the term to be defined is just phrased as question, e.g., "What is the definition of foo?").
HTML5 re-defines the dl element: it’s no longer a definition list, but an "association list", or "description list". It might be appropriate to use it for Q&As, and the dt element can now also contain most of the flow content elements (which includes p). So this might be suitable if you want to use (X)HTML5. (The example for dt even shows a FAQ.)
Possible alternatives, depending on the actual content and context:
Just use p and rely on textual semantics, i.e., the "?" makes clear that it’s a question. You could also prefix them with "Question:" and "Answer:" (e.g., in b).
Use a heading (h1-h6) for each Q&A. As they neither may contain p elements, you might have to use something like "Question 1" as heading content, and rely on the text again.
I have a grok'ed plone.directives.form code below:
class EditForm(TreeFormMixin, form.SchemaForm):
"""
Edit form for our model.
We got one dummy button which allows us to manually inspect the data postback values.
"""
grok.context(ISiteRoot)
grok.name("dgftreeselect-test")
grok.require('zope2.View')
ignoreContext = True
schema = IFormSchema
label = u"Tree selection demo and manual testing"
#button.buttonAndHandler(u'Turbo boost')
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
raise ActionExecutionError(Invalid(u"Please see that data stays intact over postback"))
it results to this form - which is not that good looking:
Since it is a demo form I'd like to keep all the related material in the same .py file. However, as the form is ugly looking, I'd like to inject a <style> CSS block on the page from a Python source code string to fix some of the most outstanding issues with the CSS styles.
What kind of hooks plone.app.forms / BrowserViews provide to inject your own <style> block in the <head> or in any part of the resulting HTML page? I prefer not to create any additional files and CSS registrations for this task.
Full source:
https://github.com/miohtama/collective.z3cform.dgftreeselect/blob/master/src/collective/z3cform/dgftreeselect/testform.py
plone.app.z3cform and Zope browser views don't provide any hooks to inject custom things into the head directly, but you can use a custom template by specifying the template attribute in the form class:
template = grok.Template('path/to/template.pt')
And then in template.pt, fill the style_slot to include your styles. The entire template could look like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="plone">
<body>
<metal:block fill-slot="style_slot">
<style type="text/css">
/* insert styles here */
</style>
</metal:block>
<metal:content-core fill-slot="main">
<metal:content-core define-macro="content-core">
<tal:button metal:use-macro="context/##ploneform-macros/titlelessform" />
</metal:content-core>
</metal:content-core>
</body>
</html>
This is not a best practice since the styles must be served every time the widget is rendered. Instead it's usually better to register CSS in the portal_css tool.
Which tags are can be self closing and which ones must have a closing tag in XHTML 1.0 Strict?
Example:
<br/>
<input />
Are there certain tags that must have a closing tag, can be self closing, or eigther way works in XHTML 1.0 Strict?
Every element, that’s content model is EMPTY in the XHTML 1.0 Strict DTD (i.e. <!ELEMENT element-name EMPTY>), is an empty element and “must either have an end tag or the start tag must end with />.” Namely it’s base, meta, link, hr, br, param, img, area, and input. Every other element must have an end tag.
You are asking about "EMPTY Elements" including <hr /> <input /> <img /> <meta /> <link /> which can all be closed in a single tag. Non-empty elements which should contain text or sub-elements could technically be closed this way if they have no child or text but you are not supposed to do it. For example <p></p> should not be <p /> but that could pass strict validation.
http://www.w3.org/TR/xhtml1/#guidelines