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

Use as a WYSIWYG Editor with html text in background and styled design in front #181

Closed
ASchmidt84 opened this issue Sep 20, 2015 · 15 comments

Comments

@ASchmidt84
Copy link

Hi,

this is a great project. And I try to familiar with your project. But at this moment I have a few problems with that.
I have to build an editor WYSIWYG like the HTMLEditor in JavaFX. My problem is at this moment, in background I generate a html text. Of course without head and body. Only the text for a paragraph and the inline code for maybe bold or italic. Like <b> oder <i>.

Now maybe the user wants to add a colored text at a special caret position. Do I have the caret position inside the html text? And how I can realize that I have the possibility to add <b> in htmltext and show only the bolder in WYSIWYG? I try to implemented InlineCssTextArea and I can transform a few things like <b> or <i>.

Do you have a special version of this editor?

Thank you

@ghost
Copy link

ghost commented Sep 20, 2015

Hi there,
if I understand your question correctly, here is the info you need(i think):

richtext data structure is made of paragraphs, that are made if styledtext,
which are text+styles.

There are methods to get paragraphs from a text area, its text and its
style segments, and each segment has a length. So you can compute segments
start positions starting from 0 then adding segments lengths.

So what the user hits save, you parse the text area info and write to/open
a text file where you open a

for each parapgraph, append style and text
for each segment, then close your parahraph. do this for each paragraph and
you get your html code as an ASCII text file. You close the text file and
set its extenion to html.

I hope this helps.

@ASchmidt84
Copy link
Author

Hi
this is not exactly what I mean.

I have a fully styled html paragraph. This can contains for example things like <ul>.

Now I hoped that this editor has the possibility to set a htmlText in background. The visual editor shows the styled html. And each caret, for example carte position 5 would be caret position 8 in html text.

Ok, so I have to build this by my self.
Thanks for your help

@ghost
Copy link

ghost commented Sep 20, 2015 via email

@TomasMikula
Copy link
Member

Hi André,

RichTextFX is not going to magically know the index within HTML.

I eventually want to support custom implementations of what is now called EditableStyledDocument. Your implementation of EditableStyledDocument could then hold HTML text (or some kind of syntax tree or DOM) and provide a view of it as a sequence of paragraphs for RichTextFX to render. Even then, however, resolving text indexes to html indexes would be the job of your custom EditableStyledDocument implementation.

Also note that you can reasonably map only a subset of HTML to styled text. Things like tables will not work.

@ASchmidt84
Copy link
Author

Hi Thomas,

thats sound great. Yes I know thinks like table are not relevant to me.
But you eventually plan to support. So this is not implemented, do it not?

At this moment implemented by my self the normal styling things like <b>, <font ...>, <i> and so on.

André

@TomasMikula
Copy link
Member

Yes, that is unfortunately not supported right now, but I plan to add it in the future.

@JordanMartinez
Copy link
Contributor

I'm closing this since Tomas' suggestion of a custom ESD can be done now, even if tables are not yet supported at this time.

@elkebasel
Copy link

I am working with JavaFX in connection with jpro webserver, which means that neither HTMLEditor nor SwingNodes are supported.
I would like to parse the document output as html as described in this thread.
My question:
I have a bullet list with two layers.
Bildschirmfoto vom 2020-12-01 20-03-11
the output of the paragraphs is:
Par[; StyledSegment(segment=left(text 1) style=12,Serif,0x000000ff)]
Par[; StyledSegment(segment=left(text 2) style=12,Serif,0x000000ff)]
Par[; StyledSegment(segment=left(text 3) style=12,Serif,0x000000ff)]
Par[; StyledSegment(segment=left(text 4) style=12,Serif,0x000000ff)]
where do I find the information about the bullets and the indents?
Thank you very much in advance for your answer!
Best, Elke

@Jugen
Copy link
Collaborator

Jugen commented Dec 1, 2020

I think that for each paragraph you would need to extract it's paragraph style using: getParagraphStyle()
So for example: area.getParagraph(0).getParagraphStyle()

@elkebasel
Copy link

elkebasel commented Dec 1, 2020 via email

@Jugen
Copy link
Collaborator

Jugen commented Dec 2, 2020

Ah sorry, my bad - my suggestion applies to the next release, which I think will be next week sometime.
In the mean time you can look at the latest ParStyle and update your code with it if you want.

ParStyle has the following new methods that apply to your use case:

    public boolean isIndented() {
        return indent.map( in -> in.level > 0 ).orElse( false );
    }

    public Indent getIndent() {
        return indent.get();
    }

@Jugen
Copy link
Collaborator

Jugen commented Dec 2, 2020

@elkebasel also see PR 987 to help you with this.
Feel free to comment there as well.

@elkebasel
Copy link

elkebasel commented Dec 2, 2020 via email

@elkebasel
Copy link

Dear Jugen
I tried your advice, and I can read the indents of the bullet list.
Am I right that "Indent" does always mean bulleted list (as when I put a normal tabulator it is treated as part of the text)?
I will try to implement myself a numbered list, this will help to learn how richtextfx works.
Thank you very much so far, you helped me a lot.
Best, Elke

@Jugen
Copy link
Collaborator

Jugen commented Dec 3, 2020

Dear Elke, well done.
Yes, an "Indent" always indicates a bulleted list and never a tab.
Have fun, best
Jürgen

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

No branches or pull requests

5 participants