I am using this plugin:
compile ":html-cleaner:0.2"
I want to keep \n characters in my strings
def s = "a\nb\nc\n"
println s
Prints:
a
b
c
When I use:
println cleanHtml(s, 'none')
It prints:
a b c
You can create a whitelist using:
htmlcleaner {
whitelists = {
whitelist("sample") {
startwith "none"
allow "b", "p", "i", "span"
}
}
}
How can I keep the \n characters from being stripped?
Disclaimer: I'm not all that familiar with Jsoup or the html-cleaner plugin.
However, I can read the source and documentation for both and it would appear this is not possible with the plugin. Looking at the plugin source code for HtmlCleaner you will see the following relevant line:
return Jsoup.clean(unsafe, whitelists[whitelist])
This is relevant because in order to preserve new line characters in Jsoup you need to set printPretty(false) on the output settings, which is true by default. This SO question & answer outlines this.
It would appear that you will need to use Jsoup directly instead of using the plugin. Alternatively you could fork and patch the plugin to allow this to be configured.
Related
I am new to vim and esp. in lua scripting. I want to create an autocmd such that all the jinja files will get yaml syntax highlighting.
local a = vim.api
a.nvim_create_autocmd( { "BufNewFile", "BufRead" }, {
pattern = { "*.j2" },
command = [[ lua(syntax = "html")]],
})
but this is not working. Could someone point the obvious.
DD.
I give you an Example on how i do Lua Syntaxhighlightning for my own *.luado files.
Before i have copied ( as super Q User: root.root ) /usr/share/nvim/runtime/syntax/lua.vim to /usr/share/nvim/runtime/syntax/luado.vim.
So i can change it independently from original lua.vim.
It is not necessary to change luado.vim for the Example below.
~/.config/nvim/lua/init.lua required by ~/.config/nvim/init.vim
( At First and off course before: syntax on )
--[[ Automatic Execution of Lua Oneliner if file extension *.luado
With Lua Syntaxhighlighting ]]
vim.api.nvim_create_autocmd({"BufEnter"},{
pattern = {"*.luado"},
command = "luado vim.api.nvim_command('setfiletype luado') load(line, 'koys_nvim_auto_luado')()"
})
Triggers at "BufEnter" and shows that "BufNewFile", "BufRead" not really needed.
( Every time before it is shown from Buffer ;-) )
Impression
Now lets change to next Buffer with :bn to test3.luado
And back with :bp to test2.luado (Output of set)
(test2.luado will be shown after ENTER/RETURN)
I have the following groovy instructions applied on Jenkins.
stage('Replace content') {
steps {
contentReplace(
configs: [
fileContentReplaceConfig(
configs: [
fileContentReplaceItemConfig(
search: ".appName.*",
replace: ''
)
],
fileEncoding: 'UTF-8',
filePath: 'register.scala')
])
}
}
What is the meaning of the pattern ".appName.*"? Every line which contains the word 'appName', the entire line will be removed in register.scala file?
Content Replace plugin
The Content Replace plugin site states the following
Regex expression for search. e.g. (Version=)([0-9]+.[0-9]+.[0-9]+)
It is a regular expression. It's not necessarily the entire line. Here is an example string: asdfasdfappNameasdf this would be replaced with asdfasd. So it will replace appName, a character before appName, and everything after appName
Below is a pattern matching example from regexr
I'm trying to use groovy to update Jenkins job config.xml by the following code
def updateParameter(String key, String value){
println "changing defult value as $value for key $key"
def xml = new XmlSlurper().parseText(jobConfig)
xml.properties.'hudson.model.ParametersDefinitionProperty'.'parameterDefinitions'.'hudson.model.StringParameterDefinition'.each {
println 'found parameter: ' + it.name
if(it.name.text() == key){
println('default value changed')
it.defaultValue=value
}
}
jobConfig = XmlUtil.serialize(xml)
}
When running jobConfig = XmlUtil.serialize(xml), it changes the format, which is pretty, but I lost link break in pipeline plugin, so pipeline script doesn't work anymore. Is there a way to convert GPathResult to String without format changing?
Best Regards,
Eric
It is all my fault, the line breaks were removed when I read the xml. It seems XmlUtil.serialize(xml) doen't format the text of a xml tag, which is good :)
Best Regards,
Eric
I need to convert string to letter case (proper case or title case), is there any default function on Groovy support for this or I need to manual sub string convert first character?
assert org.apache.commons.lang.WordUtils.capitalizeFully('man OF stEEL') == 'Man Of Steel'
The WordUtils class is provided by Apache Commons Lang, which is available on the classpath of Grails apps by defatult
Until i know there is no such a function or method but i use to do it with this sentence
assert "John Doe" == "john dOE".tokenize(" ")*.toLowerCase()*.capitalize().join(" ")
I hope it help you
yes, you can use the method capitalize()
http://groovy.codehaus.org/groovy-jdk/java/lang/String.html#capitalize%28%29
I got it, here is solution for those who needed
def capitalize(s) { s[0].toUpperCase() + s[1..-1].toLowerCase() }
caps = "man OF stEEL".replaceAll(/\w+/) { w -> capitalize(w) }
I want to parse a random website, modify the content so that every word is a link (for a dictionary tooltip) and then display the website in an iframe.
I'm not looking for a complete solution, but for a hint or a possible strategy. The linking is my problem, parsing the website and displaying it in an iframe is quite simple. So basically I have a String with all the html content. I'm not even sure if it's better to do it serverside or after the page is loaded with JS.
I'm working with Ruby on Rails, jQuery, jRails.
Note: The content of the href tag depends on the word.
Clarification:
I tried a regexp and it already kind of works:
#site.gsub!(/[A-Za-z]+(?:['-][A-Za-z]+)?|\\d+(?:[,.]\\d+)?/) {|word| '' + word + ''}
But the problem is to only replace words in the text and leave the HTML as it is. So I guess it is a regex problem...
Thanks for any ideas.
I don't think a regexp is going to work for this - or, at least, it will always be brittle. A better way is to parse the page using Hpricot or Nokogiri, then go through it and modify the nodes that are plain text.
It sounds like you have it mostly planned out already.
Split the content into words and then for each word, create a link, such as whatever
EDIT (based on your comment):
Ahh ... I recommend you search around for screen scraping techniques. Most of them should start with removing anything between < and > characters, and replacing <br> and <p> with newlines.
I would use Nokogiri to remove the HTML structure before you use the regex.
no_html = Nokogiri::HTML(html_as_string).text
Simple. Hash the HTML, run your regex, then unhash the HTML.
<?php
class ht
{
static $hashes = array();
# hashes everything that matches $pattern and saves matches for later unhashing
function hash($text, $pattern) {
return preg_replace_callback($pattern, array(self,'push'), $text);
}
# hashes all html tags and saves them
function hash_html($html) {
return self::hash($html, '`<[^>]+>`');
}
# hashes and saves $value, returns key
function push($value) {
if(is_array($value)) $value = $value[0];
static $i = 0;
$key = "\x05".++$i."\x06";
self::$hashes[$key] = $value;
return $key;
}
# unhashes all saved values found in $text
function unhash($text) {
return str_replace(array_keys(self::$hashes), self::$hashes, $text);
}
function get($key) {
return self::$hashes[$key];
}
function clear() {
self::$hashes = array();
}
}
?>
Example usage:
ht::hash_html($your_html);
// your word->href converter here
ht::unhash($your_formatted_html);
Oh... right, I wrote this in PHP. Guess you'll have to convert it to ruby or js, but the idea is the same.