DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:importanttext

Mark a Text

Compatible with DokuWiki

No compatibility info given!

plugin Enclose a text within hashes and it generates a <span class="important" /> around it.

Last updated on
2007-10-09
Provides
Syntax

The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to important_paragraf, wrap

Tagged with highlight

Syntax

  • Starts with ##.
  • Ends with ##
  • A class name can optionally be given:
    • Default class name is important.
    • Class name is between the starting ## and an optional |.
    • Class name must be all lower case ASCII characters.

Examples

The following:

This is a text with ##an important## part.

Is converted to HTML as:

<p>This is a text with <span class="important">an important</span> part.</p>

The following:

This is a ##marker|marked## word.

is converts to HTML as:

<p>This is a <span class="marker">marked</span> word.</p>

Installation

Create a folder lib/plugins/importanttext/and add:

  • lib/plugins/importanttext/plugin.info.txt
  • lib/plugins/importanttext/syntax.php
  • lib/plugins/importanttext/style.css
lib/plugins/importanttext/plugin.info.txt
base   example
author Marc Wäckerlin
email  marc [at] waeckerlin [dot-org]
date   2010-01-17
name   Important Text
desc   mark: !!!!This is important!!!!
url    https://www.dokuwiki.org/plugin:importanttext

Optional CSS Definition

For the look and feel, optionally add the following code to your template's design.css file (if the name of your template is default, then it is in lib/tpl/default/design.css, also copy it to lib/tpl/default/print.css for the printing):

Tip: you can also create a CSS file in lib/plugins/importanttext/style.css

lib/plugins/importanttext/style.css
.important {
  background-color: __light__;
  border: 1px solid __dark__;
}
 
div.important {
  margin: 0.75em 0 1em 0;
  padding: 0.2em;
}
 
div.important div {
  padding:0;
  margin: 0;
}
 
div.important > div + div {
  padding:0;
  margin: 0.5em 0 0 0;
}
 
.important > .important {
  background-color: __dark__;
  border: 1px solid __black__;
}
 
span.marker {
  border-left: 1em solid yellow;
}

The “marker” class in the last section marks a text like marked with a yellow text-marker, if you write:

##marker|This text is like marked with a yellow text-marker.##

To install the functionality, copy the following code into a new file named lib/plugins/importanttext/syntax.php:

lib/plugins/importanttext/syntax.php
<?php
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
/**
 * Important Text - Mark a text with a class.
 *
 * Marks important text:
 *
 * An important text is enclosed by with ##text##.
 * It is marked with <span class="important" >
 *
 * And mark your text as:##anything|This is the Text##
 * if you want to mark it as <span class="anything" >
 *
 *
 * @author Marc Wäckerlin http://marc.waeckerlin.org
 * License: GPL
 */
class syntax_plugin_importanttext extends DokuWiki_Syntax_Plugin {
 
    function getType() {
        return 'substition';
    }
 
    function getSort() {
        return 70;
    }
 
    function accepts($mode) {
        if(!count($this->allowedModes)) {
            global $PARSER_MODES;
            $this->allowedModes = array_merge(
                $PARSER_MODES['container'],
                $PARSER_MODES['baseonly'],
                $PARSER_MODES['formatting'],
                $PARSER_MODES['substition'],
                $PARSER_MODES['protected'],
                $PARSER_MODES['disabled'],
                $PARSER_MODES['paragraphs']
            );
        }
        return parent::accepts($mode);
    }
 
    function connectTo($mode) {
        $this->Lexer->addEntryPattern(
            '##[a-z]+\|(?=[^\n]*##)', $mode,
            'plugin_importanttext'
        );
        $this->Lexer->addEntryPattern(
            '##(?=[^\n]*##)', $mode,
            'plugin_importanttext'
        );
    }
 
    function postConnect() {
        $this->Lexer->addExitPattern(
            '##',
            'plugin_importanttext'
        );
    }
 
    function handle($match, $state, $pos, &$handler) {
        return array($match, $state);
    }
 
    function render($format, &$renderer, $data) {
        list($match, $state) = $data;
        switch($state) {
            case DOKU_LEXER_ENTER:
                {
                if(strlen($match) > 3)
                    $class = htmlspecialchars(substr($match, 2, strlen($match) - 3));
                else
                    $class = 'important';
                $renderer->doc .= '<span class="'.$class.'">';
                }
                return true;
            case DOKU_LEXER_EXIT:
                {
                for($i = 0; $i < strlen($match) - 4; ++$i) $renderer->doc .=
                    $match[$i];
                $renderer->doc .= '</span>';
                }
                return true;
            case DOKU_LEXER_MATCHED:
                return true;
            case DOKU_LEXER_UNMATCHED:
                {
                $renderer->doc .= htmlspecialchars($match);
                }
                return true;
        }
        return false;
    }
}
 
?>

Known Bugs

plugin incompatibility

The divalign's justify markup is broken by this plugin (due to formatting between ###...###). – Wonko

ChangeLog

  • 2013-01-25
    • Rename plugin and this wikipage from important_text to importanttext
  • 2006-01-20 mrw
    • initial release
plugin/importanttext.txt · Last modified: 2016-01-13 14:38 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki