Does anyone have a good way to escape html tags in erlang (as for CGI.escapeHtml in Ruby)?
Thanks
Well, i would tell you to roll your own method using string and list processing But, i would also say that if you have yaws web server source, there is a method i have used and copied into my own libraries. yaws_api:url_encode(HtmlString). See it here in action.
1> Html = "5 > 4 = true".
"5 > 4 = true"
2> yaws_api:url_encode(Html).
"5%20%3E%204%20%3D%20true"
3>
I hope this is some how what u needed. If this is what you needed, you could just browse yaws web server source code and then copy out this function and use it in your own projects, notice that within the module yaws_api.erl, you will have to make sure that you copy out all the dependencies for this function as klacke did a lot of pattern matching, function clauses, recursion e.t.c. Just copy the whole function and the small support functions from that source file and paste it some where in your projects. The other way would be to do it by your own by manipulating strings and Lists. Those are my suggestions :)
Related
I'm trying to minify my HTML. I've just discovered and started using the gulp-htmlmin plugin
My gulp task...
gulp.task('build-html',function(){
return gulp.src(appDev+'test.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest(appProd));
});
fails when applied to this valid HTML, or any document with the < character:
<div> < back </div>
The error is:
Error: Parse Error: < back </div>
at new HTMLParser (html-minifier\src\htmlparser.js:236:13)
I can think of two solutions:
Replace < with < in all my templates. Doing so manually won't be fun, but that's life. Any idea how to do it in a gulp task?
Ditch this plugin in search for one that can parse and minify my templates. Any suggestions?
Guess I'm wondering how someone more experienced at building for deployment (I'm new) would handle this.
I'm afraid you're going to have to change them to <. The html-minifier team has specifically stated they won't support bare <s.
You want do this anyway, both to not trip up parsers and to protect against certain XSS attacks. See
When Should One Use HTML Entities,
the W3C's recommendations,
and OWASP's XSS prevention cheat sheet
for more info.
The good news is any text editor worth its coding salt supports project-wide or at least multi-file search and replace. Assuming all your HTML <tags> don't have whitespace after the <, you should be able to just replace "< " with "< ".
I decided to replace all < with < since I figured this will probably save me some grief down the road. Besides #henry made great points in his answer.
I was too big of a chicken though to trust my IDE to do a find and replace without breaking my code all kinds of ways. Instead I followed these steps:
Run gulp task from the OP
Notice the file that threw the parse error and go fix it
Run gulp task again
A new file throws the parse error. Go fix it
...
Eventually I fixed all the files.
I am creating a customized Wiki Markup parser/interpreter. There is a big task however in regards to interpreting functions like these:
{{convert|500|ft|m|0}}
which is converted like so:
500 feet (152 m)
I'd like to avoid having to manually code interpretations of these functions, and would rather employ a method where I query a string
+akiva#akiva-ThinkPad-X230:~$ wiki-to-text "convert|3|to(-)|6|ft|abbr=on}}"
and get a return of:
"3 to 6 ft (0.91–1.83 m)"
Is there a tool to do this? Offline is by far the most ideal solution, but I could live with having to query a server.
You could query the MediaWiki api to get a parsed text from wikitext. E.g. to parse the template Template:Done from the english wikipedia you could use: https://en.wikipedia.org/w/api.php?action=parse&text={{Template:done}}&title=Test (see the online docs for parse). You, however, need a MediaWiki instance that provides a template that you want to parse and which works in the exact same way. If you install a webserver locally, you can install your own MediaWiki instance and parse wikitext locally, too.
Btw.: There's the Parsoid project, too, which implements a node-based wikitext->html->wikitext parser. However, it, iirc, still needs to query the api of the wiki to parse templates.
I am using POEdit for translations in a web application.
However, when I start POEdit I can't find any sources when I run 'Catalog > Update from Sources'. I only have .CSHTML-Files where the texts need to be translated.
What I've already tried:
Set the source path in Catalog > Properties and the charset to
'UTF-8'.
Added additional keyword ("[[[w+]]]") for matching words in my files (the words to translate always have the following form: [[[wordToTranslate]]]
Added a cshtml-extractor (In File > Settings > Extractor). When I did this, the following error message appeared: "warning: unterminated string constant". Warning: ')' found where '}' was expected.
Browsing the web without finding any clue of how to include cshtml-files.
Any hints are appreciated.
Any solutions are MUCH appreciated. :-)
Added additional keyword ("[[[w+]]]") for matching words in my files
I don’t know why you assume the keyword values are regexes of all things; they are not. The GNU gettext manual makes it clear what “keyword” is in the gettext context: name of the function used to call gettext with translatable string literals as the argument.
Added a cshtml-extractor
You get errors coming from this, it would be reasonable to assume that’s the problem. Because you gloss over this crucial step and don’t reveal the details of how you configured it, it’s impossible to give you a concrete answer (not without a crystal ball, anyway).
So I can only make an educated guess: if you didn’t actually add a proper extractor that understands the syntax of the template language you use, and used some gross hack like using the Python parser, then that’s the cause of your errors, together with the use of keyword value that can’t possibly be valid.
I'm thoroughly confused about how to read/write into igraph's Python module. What I'm trying right now is:
g = igraph.read("football.gml")
g.write_svg("football.svg", g.layout_circle() )
I have a football.gml file, and this code runs and writes a file called football.svg. But when I try to open it using InkScape, I get an error message saying the file cannot be loaded. Is this the correct way to write the code? What could be going wrong?
The write_svg function is sort of deprecated; it was meant only as a quick hack to allow SVG exports from igraph even if you don't have the Cairo module for Python. It has not been maintained for a while so it could be the case that you hit a bug.
If you have the Cairo module for Python (on most Linux systems, you can simply install it from an appropriate package), you can simply do this:
igraph.plot(g, "football.svg", layout="circle")
This would use Cairo's SVG renderer, which is likely to generate the correct result. If you cannot install the Cairo module for Python for some reason, please file a bug report on https://bugs.launchpad.net/igraph so we can look into this.
(Even better, please file a bug report even if you managed to make it work using igraph.plot).
Couple years late, but maybe this will be helpful to somebody.
The write_svg function seems not to escape ampersands correctly. Texas A&M has an ampersand in its label -- InkScape is probably confused because it sees & rather than &. Just open football.svg in a text editor to fix that, and you should be golden!
I am developing a package in R
When I am debugging a particular function or set of functions, what is the best way to test the function?
Do I have to either use source('function.R') or R CMD build each time I want to check my changes?
(extra credit for associated emacs ess key-bindings)
See also http://github.com/hadley/devtools/ which provides some tools to make this task easier.
for example, after making changes to source code, you build, install, and reload a package with the function install():
library(devtools)
install("package_name")
devtools also makes it easier to:
Reload complete package:
load_all("pkg")
Create or update documentation using roxygen2
document("pkg")
run all scripts in /inst/test/:
test("pkg")
build and R CMD check:
check("pkg")
Take a look at ?insertSource, which is a new function in R 2.12.0, plus the other functions in the See Also section of that help page. Also, check out ?assignInNamespace if your package has a Namespace.
The above presumes you are talking about updating and debugging R sources, not compiled code.
I generally have used the source() route to load new versions of functions I am improving/debugging, alongside the usual R debugging tools. But I haven't got Namespaces in my packages as yet. My fingers have gotten quite used to the C-c C-l keybinding in emacs+ess for sourcing a buffer over the years.
You might want to have a look at the 'mvbutils' package. I use it to live-edit my packages all the time; I can add, remove, and edit functions and documentation while the package is loaded, and the changes are reflected both in the loaded version, in the installed version (so they're kept in the next R session), and [when I tell it] in the "source package". I only re-build via R CMD when I want to distribute a zipped version to someone else. To test code, I use the 'debug' package, which works fine on a loaded package.
I even use 'mvbutils' to live-edit 'mvbutils', which can be a bit hairy sometimes.
The 'mvbutils' documentation could really do with a full demo of this in action, but in theory the existing doco should show you how to proceed.
Can't help you with Emacs, sorry...
I had got the same issue and I solved it while using RStudio.
In the editor, I check the option "Source on save" for my R file that contains function. As I'm used to save my file each time I edit it (a good habit I think), the corresponding functions loaded in my R workspace is always up to date.