You are here

function _typogrify_process in Typogrify 6

Same name and namespace in other branches
  1. 5 typogrify.module \_typogrify_process()
  2. 7 typogrify.module \_typogrify_process()

Processing function to apply the Typogrify filters

Parameters

string $text: The text to apply the filter on.

integer $format: ID if the input format whose settings to use when applying the filters.

Return value

string The filtered text.

2 calls to _typogrify_process()
TypogrifySmartyPantsTestCase::testOriginalTypogrifyExample in tests/typogrify-smartypants.test
typogrify_filter in ./typogrify.module
Implementation of hook_filter().

File

./typogrify.module, line 93
typogrify.module Typogrify: Brings typographical refinemnts to drupal

Code

function _typogrify_process($text, $format) {
  $characters_to_convert = array();

  // Load Helpers.
  module_load_include('class.php', 'typogrify');
  module_load_include('php', 'typogrify', 'unicode-conversion');
  if (!function_exists('marksmarty_filter')) {
    module_load_include('php', 'typogrify', 'smartypants');
  }

  // Load the current format settings.
  $settings = _typogrify_get_settings($format);

  // Wrap ampersands.
  if ($settings['wrap_ampersand']) {
    $text = Typogrify::amp($text);
  }

  // Remove widows.
  if ($settings['widont_enabled']) {
    $text = Typogrify::widont($text);
  }

  // Smartypants formatting.
  if ($settings['smartypants_enabled']) {
    global $_typogrify_smartypants_attr;
    $_typogrify_smartypants_attr = $settings['smartypants_hyphens'];
    $text = SmartyPants($text);
  }

  // Wrap caps.
  if ($settings['wrap_caps']) {
    $text = Typogrify::caps($text);
  }

  // Wrap initial quotes.
  if ($settings['wrap_initial_quotes']) {
    $text = Typogrify::initial_quotes($text);
  }

  // Build a list of ligatures to convert.
  foreach (unicode_conversion_map('ligature') as $ascii => $unicode) {
    if ($settings['ligatures'][$ascii]) {
      $characters_to_convert[] = $ascii;
    }
  }

  // Build a list of arrows to convert.
  foreach (unicode_conversion_map('arrow') as $ascii => $unicode) {
    if ($settings['arrows'][$ascii]) {
      $characters_to_convert[] = $ascii;
    }
  }

  // Convert ligatures and arrows
  if (count($characters_to_convert) > 0) {
    $text = convert_characters($text, $characters_to_convert);
  }
  return $text;
}