Writing a custom bbcode

Started by kebax, May 03, 2016, 10:48:42 AM

Previous topic - Next topic

kebax

Hello there!

I want to write a custom bbcode that renders into something. Are there any guidelines, documentation or other starting points available?

Regards,
Antti Barck

Kindred

look at the existing BBCode arrays?
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kebax


Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

kebax

Okay, I got it working, thanks. I few few additional questions:


  • How do I pass tag argument for rendering function?
  • How do I get id_msg of the message tha bbcode was inserted?
  • How do I disable rendering in preview?

Here is what I have done so far:


array(
'tag' => 'customtag'',
'type' => 'unparsed_content',
'content' => render_customtag( tag param here, id_msg here),
'block_level' => true,
),

Kindred

I don't know that 2 or 3 are possible without serious recoding.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

1. Depends on exactly what you're trying to do.
2. Not supported without changes as other places that aren't posts also use bbcode.
3. Very very nasty to pull off.

What exactly are you trying to do I get the impression you're aiming for a dice roll mod where the user won't be able to keep previewing until they get the numbers they want.

kebax

Okay, forget the 2 and 3. It was a bad design anyhow and I throwed the idea into trash.

But:

Quote from: Arantor on May 04, 2016, 09:50:50 AM
1. Depends on exactly what you're trying to do.

I am trying to pass the tag param to a function that renders a html snippet. I thought that was pretty obvious?


Quote from: kebax on May 04, 2016, 08:18:08 AM
...

array(
'tag' => 'customtag'',
'type' => 'unparsed_content',
'content' => render_customtag( tag param here, id_msg here),
'block_level' => true,
),


So what I exactly want here is that:

[customtag]some_param[/customtag] => render_customtag(some_param)

will pass some_param to the function render_custom tag.

(you can forget that id_msg there)

Arantor

No, I need to know exactly what you're trying to accomplish as there are multiple ways of getting values from the tag into the function, including some that are very non trivial to pull off, such as the utter monstrosity required in http://www.simplemachines.org/community/index.php?topic=528220.0

Knowing exactly what you're trying to accomplish is important so I can tell you the best way to do it.

kebax

Okay, maybe its better that I try to figure this out myself.

Arantor

As opposed to getting help from people because you don't want to explain what you're trying to do beyond a vague example that doesn't provide enough information to be useful to one of the few people who could actually help you?

You have [customtag]some parameter[/customtag]... Should that parameter be BBC parsed? Other parameters?

I can tell you now that SMF's engine doesn't really like that, it assumes the content is to be presented in some way and that you're putting tags around it like the URL tag does (and is why there are multiple definitions for the URL and quote tags) To actually push its content to a custom function you almost always have to use the other types, e.g, parsed_equals or unparsed_equals to push it to a validate function which the parser can then inject back.

I'm not trying to be a dick about this, writing any non trivial BBC like you're trying to do is fraught with trouble and very few people understand how the parser works. I just can't do it on hypothetical information where the details you're not willing to provide will almost certainly change the nature of how this would be implemented.

kebax

Well actually the solution was pretty straightforward and almost trivial. I just studied the existing bbcode arrays (as suggested in the first reply) and found a perfect solution there. My original design was way too complex.

So this is now solved, thanks for everybody. And sorry for being crumpy, but hey, I am old man. :)

Arantor

This is sort of why I asked, because I figured that depending on what you were trying to do there might have been a simpler solution... Glad you got it worked out though.

Advertisement: