Closed morph192 closed 8 years ago
Any help here?
What do you mean "insert some text in table"? Can you post a full sample?
Sure , i use simple form like here for comments with this bbcode plugin... When someone try to add
[code]
<div class="navigation">
<li><a href="#">Test</a></li>
</div>
[/code]
There is result only test , but cant see the full html for this bbcode :)
Sorry for my bad english
Ah, I see. Your problem in this case is the <pre>
tag. All that does is specify a fixed-width font; if you want any html inside it to render as text, then you need to escape it. In PHP, you can do this with htmlentities
. I don't see a default tag handler for [code]
, so you'll have to make one yourself:
class Code extends \JBBCode\CodeDefinition {
public function __construct($useOption){
parent::__construct($useOption);
$this->setTagName("code");
$this->setParseContent(false);
}
public function asHtml(\JBBCode\ElementNode $el){
$content = $this->getContent($el);
return "<pre>".htmlentities($content)."</pre>";
}
}
$str = '[code]<div class="navigation"><li><a href="#">Test</a></li></div>[/code]';
$parser = new \JBBCode\Parser();
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());
$parser->addCodeDefinition(new Code(false));
$parser->parse($str);
$mbb = $parser->getAsHtml();
echo $mbb;
Hello mate, thanks for answer but still dont work :)
I use now:
//bbcode
$parser = new JBBCode\Parser();
$parser->addCodeDefinitionSet(new JBBCode\DefaultCodeDefinitionSet());
$builder = new JBBCode\CodeDefinitionBuilder('img', '<img style="max-width:700px;" src="{param}">');
$parser->addCodeDefinition($builder->build());
$parser = new \JBBCode\Parser();
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());
$parser->addCodeDefinition(new Code(false));
$parser->parse($message);
$mbb = $parser->getAsHtml();
And still dont work and i added this function up.. It remove me like:
[code]
<div class="nav">
<li><a href="#">Lorem</a></li>
</div>
[/code]
It show only lorem now dont have and [code][/code] tags...
Sorry for my bad english
I just want to replace html tags in [code][/code] bbcode :)
Sorry, my mistake--forgot to include the <pre>
tag. I've fixed the sample in my original comment.
Hello , sorry for to many replies but this still dont work:
Now my code is like:
$message = $_POST['message'];
//bbcode
class Code extends \JBBCode\CodeDefinition {
public function __construct($useOption){
parent::__construct($useOption);
$this->setTagName("code");
$this->setParseContent(false);
}
public function asHtml(\JBBCode\ElementNode $el){
$content = $this->getContent($el);
return "<pre>".htmlentities($content)."</pre>";
}
}
$parser = new \JBBCode\Parser();
$parser->addCodeDefinitionSet(new \JBBCode\DefaultCodeDefinitionSet());
$parser->addCodeDefinition(new Code(false));
$parser->parse($message);
$mbb = $parser->getAsHtml();
and still dont work what i need the mysql results is like:
<pre>
Test
</pre>
From:
`[code]
<div class="nav">
<li><a href="#">Test</a></li>
</div>
[/code]`
Any solution to solve this problem?
I just tried it on my machine and it works fine:
Maybe I don't understand what you're expecting. You say you are expecting
<pre>
Test
</pre>
From
`[code]
<div class="nav">
<li><a href="#">Test</a></li>
</div>
[/code]`
but that doesn't quite make sense. If the expected response you posted is meant to be what is visible at render time, then it's wrong because you wouldn't actually see <pre>
rendered. If the expected response you posted is meant to represent the literal string output of the parser, then it is wrong as well, because it's missing all the markup.
Here is the literal string output from the parser when I run it:
<pre> <div class="nav"> <li><a href="#">Test</a></li> </div> </pre>
I've already posted the rendered output. Do either of these match what you expect?
I just need the full code from [code][/code] not just a part.. So if user want:
[code]
<div class="nav">
<li> <a href="#"> Test </a> </li>
</div>
[/code]
The result in my database need to be :
<pre>
<div class="nav">
<li> <a href="#"> Test </a> </li>
</div>
</pre>
I tryed all what u write but it dont want to work :/
oh, well first of all, you probably shouldn't store the parsed version in your database. Just store it with the bbcode tags intact, and parse them at render time. This way, if the functionality for those tags is ever modified or improved, you will always see the intended result when you render them.
Even if you DID want to store the parsed output in your database, again, you would still need to escape the html characters.
So store this in your database:
[code]
<div class="nav">
<li> <a href="#"> Test </a> </li>
</div>
[/code]
and at render time, run it through your parser, which will send this to the browser:
<pre> <div class="nav"> <li><a href="#">Test</a></li> </div> </pre>
and that will render like this:
@jbowens I think you can close this issue. We haven't heard from @morph192 again, and I don't think there's anything else to say on the subject.
Hello guys,
I used same code like from site :
And when i insert some text in table i cant see HTML code.. Something like :
Result is only:Lorem..
Any help?