Freemarker condition #if not working, using XDocReport - freemarker

I am trying a hello world with Freemarker using xdocreport and put a condition in the docx file, but it does not work.
I tried:
[#if name?has_content]
Sdfsdfsdf sdf sdf
[/#if]
<#if name?has_content>
Sdfsdfsdf sdf sdf
</#if>
[#if name??]
Sdfsdfsdf sdf sdf
[/#if]
<#if name??>
Sdfsdfsdf sdf sdf
</#if>
The replacing fields is working fine but not the conditional fields. The output is exactly the same as the input.

Your problem comes from with your docx which doesn't use mergefield. You must use mergefield to write any Freemarker directive, otherwise MS Word will escape your directive with XML characters (and your Freemarker directive will not work like your problem).
Note you have already posted this question question at https://code.google.com/p/xdocreport/issues/detail?id=285

Related

Asciidoctor-pdf no parsing

First, thank you for this great resource. Beautiful pdf files it creates.
I have a bunch of text files with all kinds of text of which some are jebrish. Some text lines start with a dot, etc.
Asciidoctor-pdf barfs on many pages correctly so. I've spend days trying to clean the text files with sed but its a no end game.
Is there a way to tell Asciidoctor-pdf to simply convert the text document to pdf without parsing it with Asciidoctor-pdf command options?
You could create a new AsciiDoc file where you include the text files using the include macro. If you want the converter to ignore the syntax you should use a passthrough block. If you want to display a fileA.txt and fileB.txt inside an allfiles.adoc it could look like this:
allfiles.adoc
= all files
== content of fileA.txt
++++
include::fileA.txt[]
++++
== content of fileB.txt
++++
include::fileB.txt[]
++++

xmllint to parse a html file

I was trying to parse out text between specific tags on a mac in various html files. I was looking for the first <H1> heading in the body. Example:
<BODY>
<H1>Dublin</H1>
Using regular expressions for this I believe is an anti pattern so I used xmllint and xpath instead.
xmllint --nowarning --xpath '/HTML/BODY/H1[0]'
Problem is some of the HTML files contain badly formed tags. So I get errors on the lines of
parser error : Opening and ending tag mismatch: UL line 261 and LI
</LI>
Problem is I can't just do, 2>/dev/null as then I loose those files altogether. Is there any way, I can just use an XPath expression here and just say, relax if the XML isn't perfect, just give me the value between the first H1 headings?
Try the --html option. Otherwise, xmllint parses your document as XML which is a lot stricter than HTML. Also note that XPath indices are 1-based and that HTML tags are converted to lowercase when parsing. The command
xmllint --html --xpath '/html/body/h1[1]' - <<EOF
<BODY>
<H1>Dublin</H1>
EOF
prints
<h1>Dublin</h1>

Conditional sections in Pandoc markdown

I want some sections of my document to be only for a given output format. For instance, I have an image that requires special LaTeX treatment and i want to use \includegraphics for it. But for the epub version, I want the standard behavior.
Is there a way in Pandoc markdown to specify a section that should be processed only in a given context (LaTex vs epub). Templates have conditionals. I did not see the feature for Pandoc markdown.
Or is there another way of dealing with this use case?
Here is a solution with the file preprocessor filepp. We define a function img(caption,path,options) that is replaced by ![caption](path) or by \includegraphics depending on a flag. Notice two things: you need to escape commas in the function arguments (see the third argument of the first plot); you need to have two unescaped commas, even if one argument is not specified (see the second example plot below).
test.md
#bigfunc img(caption,path,options)
#if "out_fmt" eq "tex"
\begin{figure}
\caption{\label{caption} caption}
\includegraphics[options]{path}
\end{figure}
#else
![caption](path)
#endif
#endbigfunc
Here is an image
img(Plot,Rplot.png,height=2\,width=2)
img(Plot,Rplot.png,)
We specify the ouput format in the filepp command and pipe it through pandoc:
filepp -m bigfunc.pm -D out_fmt=tex test.md | pandoc -o test.tex
filepp -m bigfunc.pm -D out_fmt=html test.md | pandoc -o test.html
tex output:
Here is an image
\begin{figure}
\Plot{\label{Plot} Plot}
\includegraphics[height=2,width=2]{Rplot.png}
\end{figure}
\begin{figure}
\Plot{\label{Plot} Plot}
\includegraphics[]{Rplot.png}
\end{figure}
html output:
<p>Here is an image</p>
<div class="figure">
<img src="Rplot.png" alt="Plot" />
<p class="caption">Plot</p>
</div>
<div class="figure">
<img src="Rplot.png" alt="Plot" />
<p class="caption">Plot</p>
</div>
There are a few possibilities:
Write a custom filter, that modifies the document's AST, see pandoc scripting.
Use a preprocessor, see this post about using gpp in front of pandoc.
In limited use cases you can use \renewcommand in your LaTeX template to change the behavior of a LaTeX command.

Delete HTML code from log file in SHELL

I have a log file containing html code i need to delete all the content between html tags for every possible match in this file. How is that possible using filters?
Example of my file:
some text here
<html>
code
</html>
some text there
<html>
code
</html>
some other text
The output should be:
some text here
some text there
some other text
This awk should do:
awk '/<html>/{f=1;next} !f; /<\/html>/{f=0}' file
some text here
some text there
some other text
why not just:
sed '/<html>/,/<\/html>/d'
it works for your example.

text to html script

Does anyone have or know of a Ruby script that converts text to html?
Example:
I have a file that contains the following text:
Host Name
Info1
Line1
Info2
Line2
I want to have ruby convert it to the following html output
Host Name
Info1
Line1
Info2
Line2
I tried running RedCloth but got the following error:
The program can't start because msvcrt-ruby18.dll is missing
Thanks
Thanks
That depends upon what you mean by "text to HTML." There are several "web text generators" that convert easy-to-read free text with minimal markup (asterisks to indicate bold, double-spaced paragraphs get surrounded in <p> tags, etc). The most common, for Ruby, are Redcloth, which implements Textile free text, and Bluecloth, which implements Markdown.

Resources