I have read two answers on here for a similar issue, one mentions an example with colon, another mentions an example where there is a popup. I am new to emmet. This one is just html<tab>
When emmet is disabled, I can see it expands html<tab> based on the file html.sublime-snippet so html<tab> becomes
<<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
But with emmet enabled, when I do html it just expands to <html></html> like any other tag.
I thought ok so it ignores html.sublime-snippet and it uses its emmet snippets file of snippets.json
So I added an html line to the relevant looking part of the snippets.json file
I added this line to the end
"html": "<html>\n<head>\n<title></title>\n</head>\n<body>\n</body>\n</html>"
"html": {
"filters": "html",
"profile": "html",
"snippets": {
"!!!": "<!DOCTYPE html>",
"!!!4t": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">",
"!!!4s": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">",
"!!!xt": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">",
"!!!xs": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",
"!!!xxs": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">",
"c": "<!-- |${child} -->",
"cc:ie6": "<!--[if lte IE 6]>\n\t${child}|\n<![endif]-->",
"cc:ie": "<!--[if IE]>\n\t${child}|\n<![endif]-->",
"cc:noie": "<!--[if !IE]><!-->\n\t${child}|\n<!--<![endif]-->",
"html": "<html>\n<head>\n<title></title>\n</head>\n<body>\n</body>\n</html>"
},
But still when I type html<tab> it expands to <html></html> rather than the whole thing with the nested tags in between that it expands to when emmet is disabled .
Similarly with script With emmet disabled it expands to <script type="text/javascript"></script> Whereas with emmet enabled it only expands to <script></script>
Related
I'm trying to generate an html file to a file. I'm using with-html-output-to-string, but I can't seem to figure out how to get the functionality to work. I'm not sure if I should use a file stream, with-open-file, and how to get the syntax to work. I've been messing with this for a day, but the code just doesnt run.
CL-USER> (who:with-html-output-to-string (out nil :prologue t :indent t)
(:html
(:head
(:title "home"))
(:body
(:p "Hello cl."))))
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html>
<head>
<title>home
</title>
</head>
<body>
<p>Hello cl.
</p>
</body>
</html>"
I'm trying to use Nokogiri to convert some template files from one format to another. But it keeps adding tags. I'm trying to prevent it from adding Doctype and meta tags, but can't figure it out. I've tried
#doc = Nokogiri::HTML.parse(r)
but that adds the tags. I've also tried
#doc = Nokogiri::HTML.fragment(r)
as suggested in "How to prevent Nokogiri from adding <DOCTYPE> tags?", but that removes any <html>, <head>, or <body> tags that are in the document.
If it matters, my code for reading the file is:
f = File.read(infile)
r = f.gsub(/<tmpl_var ([^>]*)>/, '{{{\1}}}')
#doc = Nokogiri::HTML.fragment(r)
I need to do a gsub beforehand because I need to replace <tmpl_var> tags which aren't proper HTML and cause more problems.
When using HTML.fragment(r), I do get an htmlParseStartTag: misplaced <html> tag error (as well as similar errors for <body> and <head>).
Is there a way to prevent it from making these additions?
An example conversion:
Before:
<html>
<head>
<script>
var x = "y";
</script>
</head>
<body>
<div>
Stuff
</div>
</body>
</html>
After using Parse:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
var x = "y";
</script>
</head>
<body>
<div>
Stuff
</div>
</body>
</html>
After using HTML.fragment or HTML::DocumentFragment.parse:
<script>
var x = "y";
</script>
<div>
Stuff
</div>
In this case, I want it to just output the before section. (In the real script I make a bunch of changes though).
Nokogiri can be told to not add the standard HTML headers. Consider these:
require 'nokogiri'
doc = Nokogiri::HTML('<p>foo</p>')
doc.to_html # => "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><p>foo</p></body></html>\n"
doc = Nokogiri::HTML.fragment('<p>foo</p>')
doc.to_html # => "<p>foo</p>"
tmpl_var is a bad tag name in HTML, as is {{{\1}}}, so asking Nokogiri to try to parse either will result in problems:
doc = Nokogiri::HTML.fragment('<templ_var p1="baz">foo</templ_var>')
doc.errors # => [#<Nokogiri::XML::SyntaxError: Tag templ_var invalid>]
But you can still munge the DOM:
doc.to_html # => "<templ_var p1=\"baz\">foo</templ_var>"
doc.search('templ_var').each { |t| t.name = 'bar'}
doc.to_html # => "<bar p1=\"baz\">foo</bar>"
Or:
doc.to_html # => "<div><templ_var p1=\"baz\">foo</templ_var></div>"
doc.search('templ_var').each { |t| t.replace('{{{\1}}}') }
doc.to_html # => "<div>{{{\\1}}}</div>"
Putting that stuff together, plus a bit of chicanery:
doc = Nokogiri::HTML.fragment('<div><templ_var p1="baz">foo</templ_var></div>')
doc.to_html # => "<div><templ_var p1=\"baz\">foo</templ_var></div>"
doc.search('templ_var').each { |t| t.replace('{{{\1}}}') }
doc.to_html # => "<div>{{{\\1}}}</div>"
header = Nokogiri::XML.fragment('<html><body>')
header.at('body').children = doc
header.to_html # => "<html><body><div>{{{\\1}}}</div></body></html>"
So, I'd go after it something like that.
Now, why is Nokogiri stripping the <html> tag when parsing a fragment? I don't know. It leaves <body> alone if <head> or <html> is missing:
Nokogiri::HTML.fragment('<p>foo<p>').to_html
# => "<p>foo</p><p></p>"
Nokogiri::HTML.fragment('<body><p>foo<p></body>').to_html
# => "<body>\n<p>foo</p>\n<p></p>\n</body>"
But it gets funky if <head> or <html> exists:
Nokogiri::HTML.fragment('<head><style></style></head><body><p>foo<p></body>').to_html
# => "<style></style><p>foo</p><p></p>"
Nokogiri::HTML.fragment('<html><head><style></style></head><body><p>foo<p></body></html>').to_html
# => "<style></style><p>foo</p><p></p>"
That smells like a bug in Nokogiri to me as I haven't seen anything to document that behavior.
You can get around this by using Nokogiri::XML::DocumentFragment instead of Nokogiri::HTML::DocumentFragment. The XML version won't remove the html, head, or body tags.
I'm using libxml2.2.7.3 to parse html pages and I'm having difficulties getting it work correctly with CDATA in HTML. Here's the code:
xmlDocPtr doc = htmlReadMemory(data, length, "", NULL, 0);
xmlBufferPtr buffer = xmlBufferCreate();
xmlNodeDump(buffer, doc, doc->children, 0, 0);
printf("%s", (char*)buffer->content);
and the HTML data:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div>
<script type="text/javascript">
//<![CDATA[
document.write('</div>');
//]]>
</script>
</div>
</body></html>
The parser erroneously recognizes the </div> inside the quotes as a real html tag and prints out error messages as follows:
:8: HTML parser error : Unexpected end tag : script
</script>
^
:9: HTML parser error : Unexpected end tag : div
</div>
^
And the result printed out and debugging also imply that parsing went wrong:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div>
<script type="text/javascript"><![CDATA[
//<![CDATA[
document.write(']]></script></div>');
//]]>
</body></html>
So the question is, is this a bug of libxml2? Or am I doing something wrong?
Any insightful advices would be greatly appreciated.
Thanks!
In HTML, the <script> element contains CDATA by definition, so <![CDATA[ has no effect.
In short, the source document is broken.
That section would be more properly written as:
<script type="text/javascript">
document.write('<\/div>');
</script>
I would like to know if the opengraph markup is W3C valid,
I'm getting the following error when I try to validate it:
Line 14, Column 17: there is no attribute "PROPERTY"
<meta property="og:site_name" content="sitename">
In case it's not valid, will it impact my pagerank and other search engines algo?
Is it possible to cloak those properties?
It's not valid in the normal HTML doctypes, but there is a doctype you can use to validate XHTML documents including Open Graph:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
See this question: Html validation error for property attribute
No, it isn't. That is why the validator reports an error.
<html version="HTML+RDFa 1.1" lang="en">
<head>
<title>Example Document</title>
</head>
<body>
<p>Moved to example.org.</p>
</body>
</html>
With this seems to work:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="http://rdf.data-vocabulary.org/#">
With this you are solving the issue:
<!DOCTYPE html>
<html vocab="http://www.w3.org/2011/rdfa-context/rdfa-1.1">
With this you can use lines in your html like this:
<meta property="og:title dc:title" content="m.clinic.pt - Está em boas mãos!">
or from other vocabularies listed (http://www.w3.org/2011/rdfa-context/rdfa-1.1) like this one:
cat: http://www.w3.org/ns/dcat#
qb: http://purl.org/linked-data/cube#
grddl: http://www.w3.org/2003/g/data-view#
ma: http://www.w3.org/ns/ma-ont#
owl: http://www.w3.org/2002/07/owl#
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfa: http://www.w3.org/ns/rdfa#
rdfs: http://www.w3.org/2000/01/rdf-schema#
rif: http://www.w3.org/2007/rif#
rr: http://www.w3.org/ns/r2rml#
skos: http://www.w3.org/2004/02/skos/core#
skosxl: http://www.w3.org/2008/05/skos-xl#
wdr: http://www.w3.org/2007/05/powder#
void: http://rdfs.org/ns/void#
wdrs: http://www.w3.org/2007/05/powder-s#
xhv: http://www.w3.org/1999/xhtml/vocab#
xml: http://www.w3.org/XML/1998/namespace
xsd: http://www.w3.org/2001/XMLSchema#
prov: http://www.w3.org/ns/prov#
sd: http://www.w3.org/ns/sparql-service-description#
org: http://www.w3.org/ns/org#
gldp: http://www.w3.org/ns/people#
cnt: http://www.w3.org/2008/content#
dcat: http://www.w3.org/ns/dcat#
earl: http://www.w3.org/ns/earl#
ht: http://www.w3.org/2006/http#
ptr: http://www.w3.org/2009/pointers#
cc: http://creativecommons.org/ns#
ctag: http://commontag.org/ns#
dc: http://purl.org/dc/terms/
dc11: http://purl.org/dc/elements/1.1/
dcterms: http://purl.org/dc/terms/
foaf: http://xmlns.com/foaf/0.1/
gr: http://purl.org/goodrelations/v1#
ical: http://www.w3.org/2002/12/cal/icaltzd#
og: http://ogp.me/ns#
rev: http://purl.org/stuff/rev#
sioc: http://rdfs.org/sioc/ns#
v: http://rdf.data-vocabulary.org/#
vcard: http://www.w3.org/2006/vcard/ns#
schema: http://schema.org/
describedby:http://www.w3.org/2007/05/powder-s#describedby
license: http://www.w3.org/1999/xhtml/vocab#license
role: http://www.w3.org/1999/xhtml/vocab#role
You can validate it through http://validator.w3.org/ or http://html5.validator.nu/ very well.
So instead of this:
<div vocab="http://schema.org/" typeof="Product">
<img property="image" src="dell-30in-lcd.jpg" />
<span property="name">Dell UltraSharp 30" LCD Monitor</span>
</div>
You can have this:
<!-- The schema: prefix is defined in the vocabulary http://www.w3.org/2011/rdfa-context/rdfa-1.1 -->
<div typeof="schema:Product">
<img property="schema:image" src="dell-30in-lcd.jpg" />
<span property="schema:name">Dell UltraSharp 30" LCD Monitor</span>
</div>
Some resources http://www.w3.org/TR/rdfa-primer/ http://manu.sporny.org/2012/mythical-differences/ http://rdfa.info/
I want to display an iframe in a .aspx page, and the iframes source should be the same page.
I need to use a relative uri.
What value should I give the 'src' attribute?
I realise this is a little unusual - the page will be displayed in different states depending on parameters passed in, so the iframe won't be displayed within itself.
If you do this you will get an endless loop... the processsing will "never end". maybe thats why it is white? it is really processing pages..
- is that what you want ? if you for example want just 2-3 pages in depth, you can youse querystring and for example disable the iframe when the querystrings are incremented to 3.
MyPage.aspx?depth=1 --MyPage.aspx?depth=2 --MyPage.aspx?depth=3 etc
The literal relative path should work. IE: MyPage.aspx
Here is an ASP.NET Example...
Seemed to work fine for me with the following...
Markup:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<iframe runat="server" id="myFrame" src="Default.aspx?message=Hello%20World"></iframe>
<div id="myDiv" runat="server"></div>
</div>
</form>
</body>
</html>
Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string message = Request.QueryString["message"];
if (null != message)
{
myDiv.InnerText = message;
myFrame.Visible = false;
}
else
{
myDiv.Visible = false;
}
}
}
}
The short answer is src="localfilename.aspx" within the iframe tag. The web standard, loosely applied, says anything not proceeded by a '/' is relative to the location of the current page. Sometimes src="" might even work for substituting the current file name (at the browser level)