Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offerte text with styling #31

Open
rvanheest opened this issue Jul 26, 2015 · 6 comments
Open

Offerte text with styling #31

rvanheest opened this issue Jul 26, 2015 · 6 comments

Comments

@rvanheest
Copy link
Owner

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 HTML String 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 LaTeX String instead.

Styling the might be supported:

  • Bold/italic/underline
  • Font size
  • Font type (header 1..n, paragraph, etc.)
  • Font color
  • Background color
  • Horizontal rule
  • Lists (bullets and numbers) + nesting

Styling that will no be supported:

  • Font family
@rvanheest rvanheest added this to the v0.5-alpha milestone Jul 26, 2015
@rvanheest rvanheest mentioned this issue Jul 26, 2015
2 tasks
@rvanheest
Copy link
Owner Author

Color is not a must.
Lists seems very usefull

@rvanheest
Copy link
Owner Author

Use the potential parser from #50 to do the parsing between HTML and LaTeX

@rvanheest
Copy link
Owner Author

Also don't forget to put the HTML string in the XML file. Layout needs to be preserved after saving and reloading!

@rvanheest
Copy link
Owner Author

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

@rvanheest
Copy link
Owner Author

rvanheest commented Oct 24, 2018

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?

@rvanheest
Copy link
Owner Author

rvanheest commented Oct 27, 2018

The code of the (failed) experiments so far can be found on the formatted-offer-text branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant