You are here

responsive_table_filter.module in Responsive Table Filter 7

Same filename and directory in other branches
  1. 8 responsive_table_filter.module

Text filter for wrapping <table> tags in a <figure> tag.

File

responsive_table_filter.module
View source
<?php

/**
 * @file
 * Text filter for wrapping <table> tags in a <figure> tag.
 */

/**
 * Implements hook_filter_info().
 */
function responsive_table_filter_filter_info() {
  $filters['responsive_table_filter'] = array(
    'title' => t('Responsive Table filter'),
    'description' => t('Wraps a %table tags with a %figure tag.', array(
      '%table' => '<table>',
      '%figure' => '<figure>',
    )),
    'process callback' => '_responsive_table_filter_process',
    'tips callback' => '_responsive_table_filter_tips',
  );
  return $filters;
}

/**
 * Implements hook_filter_FILTER_process().
 */
function _responsive_table_filter_process($text, $format) {
  $text = preg_replace_callback('@<table([^>]*)>(.+?)</table>@s', '_responsive_table_filter_process_table', $text);
  return $text;
}

/**
 * PREG replace callback.
 */
function _responsive_table_filter_process_table(array $matches) {
  $attributes = $matches[1];
  $text = $matches[2];
  $text = '<figure class="responsive-figure-table"><table' . $attributes . '>' . $text . '</table></figure>';
  return $text;
}

/**
 * Implements hook_filter_FILTER_tips().
 */
function _responsive_table_filter_tips($format, $long = FALSE) {
  return t('Wraps a %table tags with a %figure tag.', array(
    '%table' => '<table>',
    '%figure' => '<figure>',
  ));
}

Functions

Namesort descending Description
responsive_table_filter_filter_info Implements hook_filter_info().
_responsive_table_filter_process Implements hook_filter_FILTER_process().
_responsive_table_filter_process_table PREG replace callback.
_responsive_table_filter_tips Implements hook_filter_FILTER_tips().