Pular para o conteúdo principal

Advanced Options

Enviado por Yukare em

Geshifilter accepts some extra options, we can set more than the language, we can show line numbers, or make the start at some point, so lets see those advances options.

linenumbers

Line numbering can be enabled/disabled with the attribute "linenumbers". Possible values are: "off" for no line numbers, "normal" for normal line numbers and "fancy" for fancy line numbers (every nth line number highlighted).

With linenumbers="off":

<code language="php" linenumbers="off">
<?php
echo('Hello');
?>
</code>

Become:

<?php
echo('Hello');
?>

With linenumbers="normal": 

<code language="php" linenumbers="normal">
<?php
echo('Hello');
?>
</code>

Become:

  1. <?php
  2. echo('Hello');
  3. ?>

With linenumbers="fancy": 

<code language="php" linenumbers="fancy">
<?php
/**
 * Implements hook_library_info_alter().
 */
function geshifilter_library_info_alter(&$libraries, $extension) {
  if ($extension == 'geshifilter') {
    $config = \Drupal::config('geshifilter.settings');
    // Add the language CSS file if CSS classes are used for code styling.
    if ($config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) {
      $css = drupal_realpath(GeshiFilterCss::languageCssPath());
      $name = substr($css, strlen(DRUPAL_ROOT));
      $libraries['geshifilter']['css']['component'][$name] = [];
    }
  }
}
?>
</code>

You can see that the line numbers for lines 5,10,15 are bold:

  1. <?php
  2. /**
  3.  * Implements hook_library_info_alter().
  4.  */
  5. function geshifilter_library_info_alter(&$libraries, $extension) {
  6. if ($extension == 'geshifilter') {
  7. $config = \Drupal::config('geshifilter.settings');
  8. // Add the language CSS file if CSS classes are used for code styling.
  9. if ($config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) {
  10. $css = drupal_realpath(GeshiFilterCss::languageCssPath());
  11. $name = substr($css, strlen(DRUPAL_ROOT));
  12. $libraries['geshifilter']['css']['component'][$name] = [];
  13. }
  14. }
  15. }
  16. ?>

start

With the atribute start, we can make the line numbers start from another number, this implicit sets linenumbers="normal":

<code language="php" start="8">
<?php
echo('Hello');
?>
</code>

Become:

  1. <?php
  2. echo('Hello');
  3. ?>

fancy

For fancy line numbering the interval for the highlighted line numbers can be specified with the attribute "fancy", which implicitly enables fancy line numbering.

<code language="php" fancy="3">
<?php
/**
 * Implements hook_library_info_alter().
 */
function geshifilter_library_info_alter(&$libraries, $extension) {
  if ($extension == 'geshifilter') {
    $config = \Drupal::config('geshifilter.settings');
    // Add the language CSS file if CSS classes are used for code styling.
    if ($config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) {
      $css = drupal_realpath(GeshiFilterCss::languageCssPath());
      $name = substr($css, strlen(DRUPAL_ROOT));
      $libraries['geshifilter']['css']['component'][$name] = [];
    }
  }
}
?>
</code>

Becomes:

  1. <?php
  2. /**
  3.  * Implements hook_library_info_alter().
  4.  */
  5. function geshifilter_library_info_alter(&$libraries, $extension) {
  6. if ($extension == 'geshifilter') {
  7. $config = \Drupal::config('geshifilter.settings');
  8. // Add the language CSS file if CSS classes are used for code styling.
  9. if ($config->get('css_mode') == GeshiFilter::CSS_CLASSES_AUTOMATIC) {
  10. $css = drupal_realpath(GeshiFilterCss::languageCssPath());
  11. $name = substr($css, strlen(DRUPAL_ROOT));
  12. $libraries['geshifilter']['css']['component'][$name] = [];
  13. }
  14. }
  15. }
  16. ?>

 

Termos