Open rvanheest opened 9 years ago
Color is not a must. Lists seems very usefull
Use the potential parser from #50 to do the parsing between HTML and LaTeX
Also don't forget to put the HTML string in the XML file. Layout needs to be preserved after saving and reloading!
this is an invoice text with **bold text**, _italic text_
* element1
* element2
* element3
becomes
this is an invoice text with bold text, italic text
- element1
- element2
- element3
I tried a conversion from Markdown to LaTeX using
<dependency>
<groupId>es.nitaur.markdown</groupId>
<artifactId>txtmark</artifactId>
<version>0.16</version>
</dependency>
(which is a slightly improved version of com.github.rjeschke:txtmark:0.13
)
I was able to write a custom Decorator
for inserting LaTeX markup tags such as \textbf{
and \subsubsection*{
. Wrapped in a CleaningEmitter
, the custom Decorator
was able to generate correct and executable LaTeX.
However, a problem arises when we try to write markdown like:
## Subheader
* item #1
* item #2
* item #3
This gets converted into the following LaTeX:
\subsection*{Subheader}
\begin{itemize}
\item{item #1}
\item{item #2}
\item{item #3}
\end{itemize}
Notice that the #
are not escaped here, which is supposed to be the case in LaTeX. Also other characters (not in this example) are supposed to be escaped, such as \
and {
. However, these latter characters are not supposed to be escaped when used in a markup tag, such as in \item{...}
.
A solution for this would be to override the emit
method in the CleaningEmitter
mentioned above and do some pre-processing on the .value
in root.lines
. While this works correctly up to the point of calling super.emit(out, root)
, it doesn't work in the long run, since the latter call perceives this extra \
as an escape character and does not add it to out
. Hence the pre-processing step is undone in super.emit(out, root)
and the produced LaTeX is still invalid.
@Override
public void emit(StringBuilder out, Block root) {
Line line = root.lines;
while (line != null) {
if (!line.isEmpty)
line.value = line.value.replace("#", "\\#"); // just one replace example
line = line.next;
}
super.emit(out, root);
}
Something that might work is to replace #
with its LaTeX variant of an ASCII character: xxx.replace("#", "\\char\"0023 ")
. The question is how far we should go in this, though. Should we support every ASCII character and hence convert every character into its ASCII code?
The code of the (failed) experiments so far can be found on the formatted-offer-text branch.
Instead of plain text, the offerte text area needs to include styling. For this we can use the JavaFx
HTMLEditor
or maybe something similar to this with less styling options.The
HTMLEditor
has an HTMLString
as its output. Since the Offerte PDFs are generated using LaTeX either a parser needs to be written to generate LaTeX code from the HTML or the new implementation of the editor returns a LaTeXString
instead.Styling the might be supported:
Styling that will no be supported: