Setting HTML meta elements with knitr - html

I'm generating HTML reports using knitr, and I'd like to include author and generation date meta tags.
My Rhtml page looks something like this.
<html>
<head>
<meta name="author" content="<!--rinline Sys.getenv('USERNAME') -->">
<meta name="date" content="<!--rinline as.character(Sys.time()) -->">
</head>
<body>
</body>
</html>
Unfortunately, after I knit("test.Rhtml"), the HTML that knitr generates is
<meta name="author" content="<code class="knitr inline">RCotton</code>">
<meta name="date" content="<code class="knitr inline">2013-01-02 14:38:16</code>">
which isn't valid HTML. What I'd really like to generate is something like
<meta name="author" content="RCotton">
<meta name="date" content="2013-01-02 14:38:16">
Can I generate R code that doesn't get a code tag wrapping it? Or is there another way to specify tag attributes (like these content attributes)?
So far my least-worst plan is to manually fix the content with readLines/str_replace/writeLines, but this seems rather kludgy.

Another (undocumented) approach is to add I() around your inline code to print the characters as is without the <code> tag, e.g.
<html>
<head>
<meta name="author" content="<!--rinline I(Sys.getenv('USERNAME')) -->">
<meta name="date" content="<!--rinline I(as.character(Sys.time())) -->">
</head>
<body>
</body>
</html>

Not really nice, but seems to work without adding a hook:
<head>
<!--begin.rcode results='asis', echo=FALSE
cat('
<meta name="author" content="', Sys.getenv('USERNAME'), '">
<meta name="date" content="', as.character(Sys.time()),'-->">
',sep="")
end.rcode-->
</head>

Related

Explanation of html:5, html:xml, html5-boilerplate

Can anyone explain the difference between the different html options show in the vscode screenshot below? When to use each one. Thanks!
For me, html and html:xml only generate the opening and closing html tags.
html generates <html></html>
html:xml generates <html xmlns="http://www.w3.org/1999/xhtml"></html>
But html:5 generates a basic boilerplate for any html5 compatible html file. It contains some basic stuff like, doctype, head, body, title tags etc.
html: create only <html></html> tag
html:5 : create a basic html 5 template as below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
html:xml : Usually a <!DOCTYPE> declaration is used to distinguish between versions of HTMLish languages (in this case, HTML or XHTML). More detail about it

Suggestions for <head> tags for Meteor

Fellow Meteor users,
During my searches for tutorials and example applications, I found one that uses a unique head structure:
<meta charset="utf-8">
<title>Title</title>
<meta name="description" content="Top10">
<meta name="viewport" content="width=device-width" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1">
This particular example app didn't even have a <body> tag anywhere, just a file called head.html which contained the above code. I also learned that it seems that Meteor just automatically makes a body tag for you, so technically, just a head.html is fine.
So, it got me wondering, does anyone define specific head tags for Meteor apps? What's the rationale? Is the above code a good starting point?
When Meteor parses your various html files, any files that contain a <head></head> tag outside of a <template></template> will be concatenated together into one <head></head> tag in every page of your app. This is good for including stuff like title, various meta tags, and 3rd party resources that you want to use on every page. However handlebars support for title tags still does not exist in Meteor so it is definitely limited in what you can do with it (No dynamic meta information).
In the end if you want dynamic information you'll have to resort to something like jquery
You can find more discussion revolving around the <head> tag here:
https://github.com/meteor/meteor/issues/266
You can easily set dynamic titles using iron:router for example with:
onAfterAction: function(){
document.title = 'my awesome site: ' + Router.current().route.getName();
}
I use a head.html that includes various SEO settings:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="fragment" content="!"/>
<meta name="description" content="your description"/>
<meta property="og:title" content="your site title"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content="https://yourimageurl"/>
<meta property="og:url" content="https://hostname"/>
<meta property="og:description" content="your description"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:url" content="https://hostname"/>
<meta name="twitter:title" content="your site title"/>
<meta name="twitter:description" content="your site description"/>
<meta name="twitter:image" content="https://yourimageurl">
<noscript>You must have Javascript enabled in order to use this site</noscript>
<link rel="shortcut icon" href="/your-ico" type="image/x-icon" />
</head>
Looking into https://github.com/kadirahq/meteor-dochead I found one way to dynamically add data to <head> tag
var meta = '<div>just an example</div>'
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', meta);
Or just add that package if you need more functionality

how can i display a "é" using <h2>

I want to display a special caracter but when i used <h2></h2> this caracter does not appear on the web-site page.
<h2>Aéroport Tunis Carthage </h2>
on the web-site the text is: Arport Tunis Carthage.
<h2>Aéroport Tunis Carthage</h2> will do it.
Handy info on encoding can be found here and info on html character entities here.
There are two ways for displaying special characters in HTML:
1) Using HTML entities. For example:
Aéroport
2) Encoding the source HTML file appropriately (e.g. using UTF-8) and then indicating such encoding in the HTML head:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Aéroport Tunis Carthage </h2>
</body>
</html>
Of course, you have to use a text editor capable of writing files in the desired encoding. Otherwise you should indicate in the <head> the encoding used by the editor.
Try adding this to your meta tags:
HTML4:
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
HTML5:
<meta charset="UTF-8">
Source:
http://www.w3schools.com/tags/att_meta_http_equiv.asp
EXAMPLE:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Meta Tag -->
<meta charset="UTF-8"> <!-- HTML5 -->
<title> Your title here </title>
</head>

Difference between <meta name="title"> tag and <title></title> tag

Please clarify what is the difference between <meta name="title"> tag and <title></title> tag.
<title>Page title</title>
<meta name="title" content="Page title">
If both are used, which is most prioritised?
I observed some sites that have both <meta name="title"> and <title></title> tags and both are the same, which is expected, please confirm?
If we didn't use <meta name="title"> tag title, would I have any problem regarding SEO?
<head>
<title>Stackoverflow</title>
<meta name="description" content="free source">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
</head>
<title> is a required element on any HTML page to be valid markup, and will be what is displayed as the page title in your browser's tab/window title. For instance, try inputting the following markup into the W3C Markup Validator (via "Direct Input"):
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>
This will produce an error that there is no instance of <title> in <head>.
The <meta name="title" content="page-title"> element is just that -- metadata about your page, that any client browser or web crawler can use or not use as it wants. Whether it is used or not will depend on the crawler/client in question, as none of them are required to look for or not look for it.
So in short, you should have a <title> element if you want valid markup. The <meta> tag is going to depend on whether you want to provide for crawlers/clients, and you'd probably have to check documentation for if a particular crawler uses it.
The first is to display page name.
<title> This will be displayed in the title bar of your Browser. </title>
Second is for crawling.
<meta name="title" content="Whatever you type in here will be displayed on search engines.">
The <title> tag will actually display the page name at the top of the page. The <meta> tag, while used for crawling, could be omitted and the page still should crawl over the <title> tag. I think you could just stick with the <title> tag if you wanted.
I have noticed that for some blog sites google will use
<meta name="description"
for a general description of the site.
So, if you have a blog site where the home page also shows the latest blog post you don't want the site description to be the same as the blog post name defined in
So I'd try meta description for an overview and
<title>
for specific content.

Suggested meta tags for HTML 5 that should be considered a must have

I am looking at migrating over pages written in XHTML 1.0 to HTML 5 and am looking at the minimum requirements when including meta tags in the <head> element. For example, my current page which is XHTML 1.0 compliant has the following meta tags
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta http-equiv="content-language" content="en-us" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="copyright" content="© 2012" />
<meta name="robot" content="noindex, nofollow" />
Are the following sufficient for HTML 5 and can I also include them?
It is also my understanding that the meta element <meta http-equiv="content-language" content="en-us" /> can now be globally be applied to the <html> element.
<html lang="en-us">
<head>
<meta charset="UTF-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta name="copyright" content="©" />
<meta name="robot" content="noindex, nofollow" />
<title>sample code</title>
</head>
</html>
There is no such thing as minimum meta tags (unless of course I got your question wrong). As far as I am aware no meta tag is required and the ones you add are the ones for your specific needs.
Consider the following document:
<!DOCTYPE HTML>
<html>
<head>
<title>Some Title</title>
</head>
<body>
</body>
</html>
You can validate it and not get any warning whatsoever. The validator just reminds you that the default encoding is missing. This is not even a warning, just an information.
The working draft has this to say about meta tags:
The meta element represents various kinds of metadata that cannot be expressed using the title, base, link, style, and script elements.
And it goes on:
4.2.5.1 Standard metadata names
application-name, author, description, generator, keywords
Further it mentions some additional tags concerning a page's status, contextual representation and character encoding.
Although none of these ar explicitly required by the standard, there are in fact best practices, especially concerning search engine optimization (SEO). This has nothing to do with the HTML standard but with web (search) crawlers.
You can get some good advice which meta tags matter (for Google) at the Webmaster Tools meta tag support page
According to http://validator.w3.org/ the following is an absolutely minimal example of a valid HTML5 document, literally everything else is optional.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Valid HTML5 Document!</title>
</head>
</html>
So, you absolutely must have the charset meta tag defined, and everything else is a matter of accomplishing your goals (search engine related stuff, cache control, etc).
No meta tag is required by any HTML5 draft. (HTML5 is work in progress and may change at any moment without prior notice.)
Many of the tags you list, including the one with content-language, aren’t even allowed (conforming) according to HTML5 drafts. In practice, most of them are useless, but some of them are actively harmful (such as the one that excludes robots, and in most cases those that try to prevent all caching).
Your latter fragment of code is invalid: the html element must contain all other elements, and the head element must contain a title element (in all HTML versions).
Consult the newest W3C HTML5 draft and use the experimental checker http://validator.nu.