I get an error when adding this line of code to my javascript file,
Parse error: syntax error, unexpected T_STRING
var data = "<?xml-stylesheet type='text/css' href='css/main.css' ?>"+
"<svg xmlns='http://www.w3.org/2000/svg' width='800' height='800'>"+
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml'>"+$("#mainbody").html()
+ "</div></foreignObject></svg>";
the problem disaaperas when I remove this part:
"<?xml-stylesheet type='text/css' href='css/main.css' ?>"
moreever I have the same line in another file, but no problems at all
what could be the problem?
This is a PHP error. You need to escape the <? or ?> sequences, which of course have a special meaning to PHP.
HOWEVER, even after you fix that and make PHP happy, what you are trying to do will not work. When you try to set the "html" property of some DOM node to this data variable you're defining, you'll get a different error saying the DOM string is malformed (or, possibly, the <?xml-stylesheet?> pseudo-instruction will be ignored). That's because xml-stylesheet is something that comes at the beginning of an XML document, not within a textual DOM fragment of the sort that can be assigned to an element's html property. It takes takes effect when an SVG document is displayed, not on an SVG fragment within an HTML page.
What are you trying to accomplish here? The main.css file contains css declarations that are particular just to that fragment of SVG? Why not just include the CSS file in the HEAD of the HTML file?
Another possible solution is to externalize the SVG as a separate file, and include that using an IMG element or something--in that case the <?xml-stylesheet?> pseudo-instruction will work just fine. But that will not allow you to do what you seem to be trying to do with the $("#mainbody") thing--which is...what? To somehow wrap the HTML in SVG? Why?
Related
I have this less file that contains this line &::after{content: '▼';} but when compiled to css using less compiler (lessc) I get the following result &::after{content: 'Ôû╝';} in the css file.
On the website, the weird characters are displayed instead of the arrow down.
How can I make this content unchanged even though compilation process ?
The code you need to replace this with is:
content: '\25BC';
Not all servers will recognize the actual character - but the code will be recognized every time.
If you want to simply use the character “▼” directly – you just need to save and open your file using the same, agreed on encoding. Otherwise you get the garbled symbol. The best encoding to use is UTF-8.
You can do this in your HTML
<head>
<meta charset="UTF-8">
</head>
I know I can just put the <link> tag in the body and apparently it works, but I know it's not "valid" html and I want to avoid issues with strict browsers like firefox, which ignore every behavior a web designer expects if it's not defined in the official specification.
So is there some official way to load a stylesheet in the body area of the html?
You can add your css in the head dynamically as well like below:
jsCode:
var head = document.getElementsByTagName("head")[0],
cssLink = document.createElement("link");
cssLink.href = "path/to/filenam.css";
cssLink.id="dynamic-css";
cssLink.media="screen";
cssLink.type="text/css";
head.appendChild(cssLink);
document.head.appendChild( linkElement );
…where linkElement is your style link. Nobody's forcing you to add stuff to the body, just add it to the head.
It is valid to link to a stylesheet in the body
The stylesheet keyword may be used with link elements. This keyword creates an external resource link that contributes to the styling processing model. This keyword is body-ok.
https://html.spec.whatwg.org/multipage/semantics.html#body-ok
https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet
Actually in older versions of HTML it was illegal to put a link element in the body element and must be only in the head section of the HTML document. From this link, there is a section that states this
it may only appear in the HEAD section of a document
So, just simply load the stylesheet into the head element, there is no possible reason for you, or for anyone to write illegal documents that do not satisfy the rules of W3.org.
<head>
<link rel="stylesheet" href="~/css/file.css" />
</head>
However, there is another question that you might be interested in reading, and in which condition you can add link element to the body section. Read the answer here.
I've been playing around with SimpleHTMLDOM Parser (http://simplehtmldom.sourceforge.net/) which is a great tool, however, I've been running into a problem collecting img elements from inside the body. This is best illustrated through an example:
Here are 2 URL's of the same image. I run the following code on these URLS respectively:
$html = $this->DOMParser->file_get_html($url);
foreach($html->find('img') as $element){
print($element->src);
}
http://imageshack.us/photo/my-images/412/71banksy89789ll7.jpg/
(SHTMLD picks up the images here)
and
http://imageshack.us/scaled/landing/412/71banksy89789ll7.jpg
(SHTMLD picks up nothing)
I've tried for a few days now to figure out what's going on, but the only different in this example would be in the html tags.
Any ideas?
Your second url is pointing to an jpeg file directly, instead of a html page holding img tags. SimpleHTMLDOM Parser can only parse html pages, so it won't work when you fed it an image file instead of a html page.
Simple, Your second URL is not HTML, Its a Jpg! :)
I have in an xsl file a transform that contains <TEXTAREA></TEXTAREA> (no spaces) and when it is transformed the results are
<TEXTAREA>
</TEXTAREA>
I can't find the right properties to stop this from happening.
We are using XslCompiledTransform and XmlTextWriter
Thank you.
XmlTextWriter has a Formatting property that by default is set to Formatting.None. Check that this is the case - if this property were set to Formatting.Indent it would account for the unwanted line-feed.
Use the xsl:strip-space element at the beginning of the styleheet.
<xsl:strip-space elements='TEXTAREA'>
Unwanted whitespace in the output generally comes from one of three places: it's copied from the source document (often by implicitly applying the built-in template rules to whitespace text nodes in the source); or it's generated by using indent="yes", or (rarely, but worth looking for because it's the last place most people think of) it's copied from the stylesheet because someone put xml:space="preserve" in the stylesheet source.
I'd like to print http://www.delicious.com/tags/engmark to PDF (Using Firefox on Linux, if possible), but the result looks rubbish. How can I print without taking into account the print-specific CSS (which I think is loaded by the enormous JS on the site)? I tried to disable print CSS in the Web Developer extension, but that didn't affect the print output.
I looked through the HTML file and found that there's a link tag with the attribute of media="screen"
If you just remove that attribute, the CSS would then load.