I have a problem that I can not
answer. I write an BBCODE editor with switch between a WYSIWYG editor and code
editor.
The visual editor is built from a drag
and drop blocs system (picture, text,
...)
In the visual editor, when an
user drag a new text bloc, the content is automatically written between
[text][/text]
tags.
In
the code editor, user can write free text without [text][/text]
tags.
To be able to switch between the two
editors, free text need to be added between [text][/text]
tags
in code
editor.
Example :
I write text and bbcode in code editor :
Cum haec taliaque
sollicitas eius aures everberarent expositas semper eius modi
rumoribus et
patentes.
[img]https://foo.com/fighters.png[/img]
Denique
Antiochensis ordinis vertices sub uno elogio iussit occidi ideo
efferatus,
quod ei celebrari vilitatem intempestivam urgenti, cum inpenderet
inopia
[img]https://foo.com/fighters1.png[/img]
[img]https://foo.com/fighters2.png[/img]
Utque
proeliorum periti rectores [i]primo catervas[/i] densas opponunt et
fortes,
deinde leves armaturas, post iaculatores ultimasque subsidiales acies,
si
fors
adegerit
If
i switch to visual editor, the free text need to be added between
[text][/text]
like
this:
[text]Cum haec taliaque
sollicitas eius aures everberarent expositas semper eius modi
rumoribus et
patentes.[/text]
[img]https://foo.com/fighters.png[/img]
[text]Denique
Antiochensis ordinis vertices sub uno elogio iussit occidi ideo
efferatus,
quod ei celebrari vilitatem intempestivam urgenti, cum inpenderet
inopia[/text]
[img]https://foo.com/fighters1.png[/img]
[img]https://foo.com/fighters2.png[/img]
[text]Utque
proeliorum periti rectores [i]primo catervas[/i] densas opponunt et
fortes,
deinde leves armaturas, post iaculatores ultimasque subsidiales acies,
si
fors
adegerit[/text]
I
think there are two
ways:
- Split text and
bbcode with loops, and rebuild code with another
loops. - Use a regex to get free text and
replace it.
What the best
way ? Do you think that possible to add the tags from a regex ?
Thank
you,
Thomas
No comments:
Post a Comment