[pmwiki-users] Special monospace requirement

Petko Yotov 5ko at 5ko.fr
Thu Sep 20 21:05:47 CDT 2012


Allister Jenks writes:
> This presents me with a problem because input fields on these panels  
> are underlined. A typical entry prompt would look like this:
>
> Name. . .: ____________________  Code. . . : __
> Date . . : __________
>
...
> Mark a block (perhaps with [@ and @]) which spans multiple lines. Within  
> this block all whitespace and carriage returns are preserved. Some lines may  
> start with one or more blanks or may be completely blank. All of the lines  
> in a block need to display as a single block level element. BUT, I need to  
> be able to mark up the underlined areas. Clearly this will get slightly ugly  
> in the edit window as the nicely aligned text block will be put out of shape  
> by whatever markup produces the underlines, but I can cope with that.
>
> I'm comfortable with CSS to get things looking how I want but I have a lot  
> of trouble sorting out the markup to make it generate what I want. The  
> markup needs to be simple enough that the rest of my team can use it, too.

Let's say you use the normal [@...@] markup for the terminal block, but  
precede it with (:terminal:) so you'll have in a wiki page:

(:terminal:) [@
here the 80x25 code
@]

Then, to highlight/underline editable fields, you just insert some character  
or combination which you know you wouldn't have in your terminal:

(:terminal:)[@
Name . . : @@                @@ Code. . . : @@               @@
Date . . : @@                @@
@]

In this example, I have used @@...@@ to delimit the editable zones. You can  
change it to a different combination, even to a single character if you'll  
never have it inside the terminal window.

To achieve this, I have in config.php the following:

  Markup('terminal', '>markupend', "/\\(:terminal:\\) *\\[@(.*)@\\]/sei",
    "MarkupTerminal(\$pagename, PSS('$1'))");

  function MarkupTerminal($pagename, $text) {
    $delimiter = '@@';
    $dx = preg_quote($delimiter, "/");
    $text = preg_replace("/$dx(.*?)$dx/", '<tt>$1</tt>', $text);
    return PreserveText('@', $text, '');
  }


This will cause the @@...@@ text to be wrapped in <tt> tags, and save  
everything in a <pre> block. So, in pub/css/local.css, I can add for  
example:

  pre tt {background: #eee; text-decoration: underline;}

See the result here:
  http://galleries.accent.bg/Cookbook/Terminal

As you noticed in your message, inserting the delimiters of the editable  
areas will shift the wikicode of that line, so editing may not be very nice.
 
But if you can find a single character that will NEVER appear on your  
terminal, use it as a delimiter, and you can even add 2 spaces in the  
replacement, so everything will be aligned. Use something like this in  
MarkupTerminal() :

    $delimiter = '@'; # single @...@   -or-
    $delimiter = '_'; # single _..._   -or-
    $delimiter = '$'; # single $...$
    ...
    $text = preg_replace("/$dx(.*?)$dx/", '<tt>$1  </tt>', $text);
    #                                            ^^2 spaces at the end

This can be fun. :-)

Petko




More information about the pmwiki-users mailing list