You are here

function hook_xbbcode_info in Extensible BBCode 8.2

Same name and namespace in other branches
  1. 8 xbbcode.api.php \hook_xbbcode_info()
  2. 7 xbbcode.api.php \hook_xbbcode_info()

Define tags that can be used by XBBCode.

A tag is uniquely identified by a (lowercase alphabetic) name. It must include a description and a sample, both of which should already be localized. It must include either a markup template or a callback function.

If a markup template is used, then the template should contain placeholders that will be replaced with the tag's content and attributes:

  • {content}: The text between opening and closing tags (non-inclusive), assuming the tag is not self-closing.
  • {option}: The single attribute of the tag, if one is entered.
  • {...}: If a named attribute is entered, it will replace the placeholder of the same name. Otherwise, the placeholder is removed.

For example, if [url=http://www.drupal.org]Drupal[/url] is entered, then {content} will be replaced with "Drupal" and {option} with "http://www.drupal.org". In [img width=60 height=60], {width} and {height} will be replaced with "60".

Return value

An array keyed by tag name, each element of which must contain these keys:

  • EITHER markup: A string of HTML code.
  • OR callback: A rendering function to call. See hook_xbbcode_TAG_render() for details.
  • options: An array that can contain any of the following keys.
    • selfclosing: This tag closes itself, as in [img=http://url].
  • sample: For the help text, provide an example of the tag in use. This sample will be displayed along with its rendered output.
  • description: A description of the tag.

The "sample" and "description" values should be localized with t().

2 functions implement hook_xbbcode_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

xbbcode_basic_xbbcode_info in xbbcode_basic/xbbcode_basic.module
xbbcode_xbbcode_info in ./xbbcode.module
Implements hook_xbbcode_info().
3 invocations of hook_xbbcode_info()
_xbbcode_build_handlers in ./xbbcode.inc
Discover the handlers by module hook invokation.
_xbbcode_build_tags in ./xbbcode.inc
Invoke all handlers to get the tags for a certain format.
_xbbcode_module_names in ./xbbcode.inc
End-user names of all modules that implement hook_xbbcode_info().

File

./xbbcode.api.php, line 46
Hooks provided by the XBBCode module.

Code

function hook_xbbcode_info() {
  $tags['url'] = array(
    'markup' => '<a href="{option}">{content}</a>',
    'description' => 'A hyperlink.',
    'sample' => '[url=http://drupal.org/]Drupal[/url]',
  );
  $tags['img'] = array(
    'markup' => '<img src="{option}" />',
    'options' => array(
      'selfclosing' => TRUE,
    ),
    'description' => 'An image',
    'sample' => '[img=http://drupal.org/favicon.ico]',
  );
  $tags['code'] = array(
    'markup' => '<code>{source}</code>',
    'description' => 'Code',
    'sample' => '[code]if (x <> 3) then y = (x <= 3)[/code]',
  );
  $tags['php'] = array(
    'callback' => 'hook_xbbcode_TAG_render',
    'description' => 'Highlighed PHP code',
    'sample' => '[php]print "Hello world";[/php]',
  );
  return $tags;
}