Is there any way to remove HTML comments from a string using Liquid? Here is my current code:
{{ post.content | strip | xml_escape }}
Is there any way to do something like:
{{ post.content | strip | xml_escape | strip_comments }}
That removes all HTML comments? I could do this with RegEx and replace (/<!--.-->/g), but liquid doesn't support that.
It is for an RSS feed, so I cannot use any JavaScript.
There is no way to do this. You could, however, use liquid {% comment %} tags inside of your post instead.
To remove all HTML comments from a string using Liquid, you could try:
{{ post.content | strip_html | escape }}
Related
I have a Ansible line that fails linting:
tags: "{{ deployment_id | resource_tags('asg', base_resource_tags, deployment=deployment_id, deployment_env=deployment_env, deployment_name=deployment_name, purpose=deployment_purpose_tag, cpu_utilization=deployment_cpu_utilization_tag, disk_io_class=deployment_disk_io_tag, prom_exporters=deployment_prom_exporter_tags) | asg_tag_list }}"
How do I make this pass linting?
You need to use YAML Folding Scalars, > without quotes. Then add 'block chomping' 'strip'docs indicator to remove the trailing newline. The below example will work correctly, with each newline translating to a space. Adding quotes will break it e.g.
tags: >-
{{ deployment_id | resource_tags('asg', base_resource_tags, deployment=deployment_id,
deployment_env=deployment_env, deployment_name=deployment_name, Purpose=deployment_purpose_tag,
cpu_utilization=deployment_cpu_utilization_tag, disk_io_class=deployment_disk_io_tag,
prom_exporters=deployment_prom_exporter_tags) | asg_tag_list }}
Folks,
I'm trying to achieve the below by using the groups parameter in Ansible.
{{ groups['kafka'] | map('extract',hostvars,'ansible_host') | list | join(':{{ zookeeper_port }},') + ':{{ zookeeper_port }}' }}
variable zookeeper_port is given as:
zookeeper_port: 2181
While running my playbook with the above parameter for groups included, it gives me the result as:
IP:{{ zookeeper_port }},IP:{{ zookeeper_port }}
instead I'm trying to get the result as :
IP:2181,IP:2181
Can anyone help me figuring out what went wrong at my groups parameter declaration.
Anything inside '' inside {{}} treated as literal string. To access variables you type them right away - without any surrounding characters. In your case you need something like:
{{ groups['kafka'] | map('extract',hostvars,'ansible_host') | list | join(':' + zookeeper_port|string + ',') + ':' + zookeeper_port|string }}"
Notice the string filter - if your zookeeper_port defined as integer, then without it the task will fail
I have this helm template for secret object:
...
data:
{{- range $key, $val := fromYaml .Values.secretmap }}
{{- $type := printf "%T" $val }}
{{ $key }}: {{ if eq $type "float64"}}{{ printf "%.0f" $val | b64enc | quote }}{{ else }}{{ $val | b64enc | quote }}{{ end }}
{{- end }}
kind: Secret
...
And I load it as follows:
helm template --set-file secretmap="secretmap.yaml"
I create the secretmap.yaml from env var like so:
env | sed -n "s/^K8S_SECRET_\(.*\)$/\1/p" | sed s/=/': '/ \ >secretmap.yaml
The problem is with multiline values.
When I set a multi-line pem key as env var, only the first line inserted to the secretmap.yaml.
How can I load multi-line env var correctly to a yaml so helm could create a secret of it?
I'd reach for a more powerful tool than a shell script to write out the secretmap.yaml file.
The Helm template itself looks fine. Assuming the content is valid YAML, it will echo it out, base64 encoding each value. You'd be happier if every node in the YAML were a string so you didn't have to reinterpret it based on a dynamic type lookup.
So the actual problem is generating the YAML file. You can take advantage of the fact that (a) YAML tries hard to make all valid JSON be valid YAML, and (b) almost every programming language includes JSON support in its standard library. (Or you can use Helm's fromJson function too.) Here's a minimal Python script that could write it out for you, in place of your sed command:
#!/usr/bin/env python3
import json
import os
PREFIX = 'K8S_SECRET_'
result = {}
for k in os.environ.keys():
if k.startswith(PREFIX):
kk = k[len(PREFIX):]
v = os.environ[k]
result[kk] = v
print(json.dumps(result))
Or, a denser one-liner based on jq
jq -n 'env | with_entries(select(.key | startswith("K8S_SECRET_")) | .key |= ltrimstr("K8S_SECRET_"))'
If the environment variables have newlines embedded in them, it's almost impossible to process this reliably with basic shell tools. As a minimal example try (bash/zsh specific syntax)
K8S_SECRET_FOO=$'bar\nK8S_SECRET_BAZ=quux' env
You want just one variable, but with the embedded newline, env will print this in a way indistinguishable from two separate variables.
In the laravel framework we can use blade to add PHP code in html file.
We are using both {{ }} and {{{ }}} syntax in blade files of Laravel.
What is the difference between them?
i have a code in a blade file like this
{{{ $errors->has('slider') ? 'has-error' : '' }}}
Before Laravel 5:
{{{ $var }}} escapes the contents of $var
{{ $var }} echoes $var unescaped
Since Laravel 5:
{{ $var }} AND {{{ $var }}} escape the contents of $var
{!! $var !!} echoes $var unescaped
There is no difference between {{ }} and {{{ }}} in Laravel 5 at all.
In version 4 it included the following two styles: “{{” and “{{{“. The double
curly bracket was a raw echo and the triple curly bracket escaped.
Currently in 5.0 both the double and triple curly brackets escape the
variable and a new “{!! $var !!}” is for raw.
https://laravel-news.com/2014/09/laravel-5-0-blade-changes/
{{{ renders HTML data but {{ shows data and elements without rendering.
ex :
$str = "<h3>Hello world!</h3>";
{{ $str }} output : <h3>Hello world!</h3>
{{{ $str }}} output : Hello world!
In Laravel 4 {{{ $var }}} is used to render data by escaping HTML entities that uses PHP htmlentities function to prevent XSS attacks.
{{ $var }} is used to render data without escaping HTML entities.
In Laravel 5 it slightly different you can use either {{ $var }} or {{{ $var }}} to escape data and to render unescaped data you can use {!! $var !!}.
Something I don't see mentioned here but which can be handy to know. If you have a translation text with a parameter that should become a Vue variable in the resulting html then the triple curly braces come in handy.
E.g.:
{{{ __('This window will close in :timeout seconds', ['timeout' => '#{{timeoutSecs}}']) }}}
Attempting this with any other combination of curly braces will throw some error.
I have the following code snippet from a HTML file:
<div id="rwImages_hidden" style="display:none;">
<img src="http://example.com/images/I/520z3AjKzHL._SL500_AA300_.jpg" style="display:none;"/>
<img src="http://example.com/images/I/519z3AjKzHL._SL75_AA30_.jpg" style="display:none;"/>
<img src="http://example.com/images/I/31F-sI61AyL._SL75_AA30_.jpg" style="display:none;"/>
<img src="http://example.com/images/I/71k-DIrs-8L._AA30_.jpg" style="display:none;"/>
<img src="http://example.com/images/I/61CCOS0NGyL._AA30_.jpg" style="display:none;"/>
</div>
I want to extract the code
520z3AjKzHL
519z3AjKzHL
31F-sI61AyL
71k-DIrs-8L
61CCOS0NGyL
from the HTML.
Please note that: <img src="" style="display:none;"/> must be used because there are other similar urls in HTML file but I only what the ones between <img src="" style="display:none;"/>.
My Code is:
cat HTML | grep -Po '(?<img src="http://example.com/images/I/).*?(?=.jpg" style="display:none;"/>)'
Something seems to be wrong.
You can solve it by using positive look ahead / look behind:
cat HTML | grep -Po "(?<=<img src=\"http://example.com/images/I/).*?(?=\._.*.jpg\" style=\"display:none;\"/>)"
Demonstration:
ideone.com link
Regexp breakdown:
.*? match all characters reluctantly
(?<=<img src=...ges/I/) preceeded by <img .../I/
(?=\._...ne;\"/>) succeeded by ._...ne;\"/>
I assume you were looking for a lookbehind to start, which is what was throwing the error.
(?<=foo) not (?<foo).
This gives the result case you specified, but I do not know if you need up until the JPG or not:
cat HTML | grep -Po '(?<=img src="http://example.com/images/I/)[^.]*'
Up until and excluding the JPG would be:
cat HTML | grep -Po '(?<=img src="http://example.com/images/I/).*(?=.jpg)'
And if you consider gawk as being a valid bash solution:
awk -F'[/|\._]' -v img='/<img src="" style="display:none;"\/>/' '/img/{print $7}' file