Thymeleaf add css styles to html from variable - thymeleaf

Let's say I have a variable cssStyles which contains some css as String. I want to send it in my html file in this way
<style>
${cssStyles}
</style>
How can this be achieved with thymeleaf?
Thanks!

At the very least you need to mark the style object that you'r using inline thymeleaf and use proper inline syntax. Below a mock of what I think might work.
See https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#inlining for more information on how to do thymeleaf inlining
<style th:inline="text">
[(${cssStyles})]
</style>

Related

Customizing style of html string in WKWebView

First of all let me point that I am just the beginner and that I might be missing something out, but I really need help figuring out how to get things done.
I've been able to parse xml from web address using https://github.com/tadija/AEXML parser.
Next, on WKWebView I'm using .loadHTMLString method to take only the content node of xml:
webView.loadHTMLString(xml.root["channel"]["item"]["content"].string, baseURL: nil)
Now, my webView shows the content, but I need to format the style.
I've been searching for hours now and the closest answer I could find is that i should use .css file, which makes sense and I already have custom style css file, but I can not manage to implement it. As far as I could conclude from similar questions either: in .loadHTMLString method I should use that custom css file in baseURL (if that is the case I would appreciate if someone could explain how to do it); or the answer lies in WKUserContentController with which i'm quite unfamiliar.
I would greatly appreciate any help.
Thanks a lot.
You need to link the css file into your html. If you have an external css (which I believe you have:-)) file add
<link rel="stylesheet" type="text/css" href="mystyle.css">
Alternatively you could implement an inline or internal css
JFYI
Somewhere in the head tag add
Internal css:
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
Inline css:
<h1 style="color:blue;margin-left:30px;">This is a heading.</h1>
Hope it helps you! Happy coding :)

what means ${demo.css} in example files of highcharts ? That piece of code seems to be literal

what means ${demo.css} in example files of highcharts ? That piece of code
<style type="text/css">
${demo.css}
</style>
seems to be literal
This looks like a jQuery template tag to load a non-existent CSS file. According to this Highcharts form post it is not required, and all configuration should be managed through Javascript rather than CSS.
The Highcharts API Reference lists all of the Javascript configuration items.

How to use MathJax inside polymer dart element?

I am trying to use MathJax inside a polymer.dart element:
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
Any help would be appreciated. Update: Using this:
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"myDivWithMath"]);
MathJax very probably tries to find the element by using querySelector('myDivWithMath') which doesn't work because this selector doesn't find the element.
You can try
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"* /deep/ myDivWithMath"]);
don't use shadowDOM by adding the attribute 'lightdom' to the element. This is the only reference I found how to do this How to skip the Shadow DOM (and use the Light DOM) instead for Polymer templates (never used this myself yet).

How add a CSS Jelly file to Jenkins Plugin?

I have made my own stylesheet that I require to include on the Jenkins plugin.
<l:layout css="/plugin/myPlugin/css/jquery-ui.css">
<link rel="stylesheet" href="${rootURL}/plugin/myPlugin/jquery-ui.css" type="text/css" media="screen" />
Please advice me..
Thanks..
To link CSS files in Jelly files is deprecated, see jelly tags documentation:
This was originally added to allow plugins to load their stylesheets, but the use of thie
attribute is discouraged now. plugins should now do so by inserting <style> elements
and/or <script> elements in <l:header/> tag.
Please use inline css tags instead (code example).
Place your css file(s) under
/src/webapp/css
and reference them as ..
" href="${rootURL}/plugin//css/layout.css"
Using a <link> element with the $rootURL as noted above worked for me. The important thing that I noticed was to make sure to place the <link> element after <l:layout>. I had it right after the <j:jelly> tag originally and it wasn't able to render the ${rootURL}.
The <link> tag will be much cleaner than doing inline styling.

Strip Inline CSS and JavaScript in Rails

I'm working on a Rails application and I would like to know what's the best way to strip blocks of CSS or JavaScript.
<style>
...
</style>
-or-
<script>
...
</script>
I'm using the strip_tags helper to take care of most of the HTML, but it leaves a bunch of CSS when the content contains inline CSS. Thanks
Try to use Nokogiri library:
require 'nokogiri'
str = " ... " # some html from user
doc = Nokogiri::HTML(str)
doc.css("style,script").remove # remove all tags with content
new_string = doc.to_s
Nokogiri can much more, but this is what you asked for in questions :-)
The recommended way to do this is using the sanitize method. The strip_tags method is somewhat limited and less secure:
[strip_tags] Strips all HTML tags from the html,
including comments. This uses the
html-scanner tokenizer and so its HTML
parsing ability is limited by that of
html-scanner.
If you use sanitize, you will be much more secure, just come up with a white list of tags you intend to allow first.
If you need user-provided CSS for your application, you can try using http://github.com/courtenay/css_file_sanitize/tree/master as well.

Resources