Francesco
Francesco

Reputation: 325

tinymce default applied (written) style

I'm using tinymce to edit some field in a web application. I need to have an html result (after editing) with some specification.

For example: when I press enter tinymce create a new paragraph (that's ok, and I know this behaviour can be changed, but paragraph is ok).

What I need is a specific style to the paragraph be applied. I saw there is the possibility to specify content_css, but this is a visual deformation of what is written in the edited html.

my need is when I press enter a paragraph with specific style (margin, alignmnent, ..) must be written directly in the edited html text.

e.g. <P style="margin-top:2px; margin-bottom:10px"> ...</P>

Is it possibile to define specific style to be applied to each html tags ?

I need this because after editing, the html content is used in another part of application, where I can not add additional style configurations.

Upvotes: 0

Views: 322

Answers (2)

user1299518
user1299518

Reputation:

Did you try that?

...
'content_css' : './path/to/your/styles.css',
...

styles.css

p {
   margin-top:2px;
   margin-bottom:10px
}

..I saw there is the possibility to specify content_css, but this is a visual deformation..

True, but don't forget that this visual deformation is extracted when you call tinyMCE.activeEditor.getContent(). Though, i'm not sure it will extract your specific styles applied to <p> (untested)

Check also here

UPDATED

Ok, i have another suggestion using HTML parsing using this.

$html = str_get_html("<div>add here your HTML from tinymce editor <p></p></div> test <p></p>");
foreach($html->find("p") as $p) {
   $p->style = "margin:2px 0 10px 0";
}
$html_modified = $html;

The $html_modified should contain the <p> with margin applied.

Upvotes: 1

Prem Bikram Limbu
Prem Bikram Limbu

Reputation: 159

Yes it is possible in tinymce. Just go to Tools -> Source Code of the editor toolbar. Write your HTML code with style there. You can try yourself.

Upvotes: -1

Related Questions