create new tag
, view all tags

BeautifierPluginDev Discussion: Page for developer collaboration, enhancement requests, patches and improved versions on BeautifierPlugin contributed by the TWikiCommunity.
• Please let us know what you think of this extension.
• For support, check the existing questions, or ask a new support question in the Support web!
• Please file bug reports in the BeautifierPlugin bug database.

BeautifierPlugin Discussion

Not entirely sure about installation for this plugin, hope it works for other sites. This plugin was written by two people who don't know Perl or PHP. smile

For examples of this thing in action, see http://nebuladevice.sourceforge.net/cgi-bin/twiki/view/Test/TestTopic2

-- LingLo - 18 Dec 2002

Additional Language Files

When converting language files it's necessary to make adjustments to the plugin code, see the BeautifierPlugin.pm, should hopefully be fairly simple...

Also, it would be incredibly cool if other people convert language files as required and contribute them back to both http://www.beautifier.org and here.

-- LingLo - 18 Dec 2002


I'm wondering whether the %CODE_XXX{ ... }% syntax, this should really be changed to %CODE("Syntax"}{ ... }% or something along those lines. Any thoughts? It certainly seems to me this is the correct way to go about things.

-- LingLo - 18 Dec 2002

Would %CODE{"Syntax"}% blah... %ENDCODE% be possible? This seems to be the most in-line with other TWiki tags that wrap around data.

BTW, this plugin seems to work very nicely so far.

-- MikeMaurer - 19 Dec 2002

It worked for me. I even added perl without a hitch. However, I saw these messages in my logfile:

[Thu Dec 19 12:47:10 2002] view: Unquoted string "donothing" may clash with future reserved word at ../lib/Beautifier/Core.pm line 536.
[Thu Dec 19 12:47:11 2002] view: Use of uninitialized value in numeric eq (==) at ../lib/TWiki/Plugins/BeautifierPlugin.pm line 156.
  • To fix the first one I quoted the word "donothing"
  • To fix the second, I added the line $cpp=$tcl=$python=$java=$perl=0; to initPlugin in BeautifierPlugin.pm .

I'd like to see SQL supported, but I see it isn't in the Beautifier module. Guess I'll have to do it myself, eh? I got stuck just trying to uppercase "select" though. frown So I don't know how far I would get with it.

-- GeraldSkerbitz - 19 Dec 2002

Gerald, thanks, I've fixed them for future updates. Concerning SQL, did you look at the PHP distribution? There's a HFile_sqlnew.php file in the full distribution.

Attached is a new version of the BeautifierPlugin.pm, it supports the syntax suggested by MikeMaurer:

  • To recap, that's %CODE{"syntax"}% blah...blah %ENDCODE%.
  • This version also supports a "drop-in" of new syntaxes without having to modify the BeautiferPlugin.pm code. It does this by doing a lookup for "syntax" to match a module in HFile/HFile_syntax.pm. This means perl, php3 and scheme are now supported by default simply because they're part of the distribution.
  • Legacy tags are still supported for the meanwhile.

Can someone with knowledge of Perl check if this introduces a dodgy security issue please? I'll feed this back into a new release when people seem happy with it. Cheers to Agora:Main/KevinReid for helping out with the Perl language in this update.

-- LingLo - 20 Dec 2002

This looks like a great plugin! Would be useful on TWiki.org as well as elsewhere. Re the security issue, read some of the links from Codev.TaintChecking - the main thing is to 'filter in', i.e. to match only reasonable characters in the filename - I recommend something like /([a-z0-9_]+)/i in the regex, extracting the language name into $1. Due to various InternationalisationEnhancements, it's best to use this form to avoid security problems if an unusual I18N locale is used.

-- RichardDonkin - 20 Dec 2002

Ah, thanks for the advice! I've updated the official plugin page over at BeautifierPlugin with the suggestions, it now uses the funky new syntax and has a 'filter-in'. Please report any bugs, enjoy!

-- LingLo - 26 Dec 2002

Thanks for adding the new tag format!

One thing I notice that will likely throw off some of my users is that the text between the quotes is case-sensitive. Converting the user-entered text to a specific case before checking it would be a good enhancement.

-- MikeMaurer - 28 Dec '02

Updated to be more liberal with input, cheers for the suggestion!

-- LingLo - 28 Dec 2002

BUG Notice: I found a lot of " view: Reference found where even-sized list expected at ../lib/TWiki/Plugins/BeautifierPlugin.pm line 59." in my logs. Looking at the source, it is caused by the line: "%langs = { };" In perl, this is more properly done by: "%langs = ();" as a hash is a list, not a subroutine or scope block.

-- JoshMore - 10 Feb 2003

Small hint: In the Plugin topic use Interwiki syntax for contributors because Plugins are installed at different sites (by definition smile ). I added a TWiki: prefix to user names.

-- PeterThoeny - 01 May 2003

The XML option for the plug-in does not seem to block-indent the XML, contrary to most presentations of XML. This makes it nearly imposible to visually parse. Anyone have any suggestions on how to alter the definition of the HFile_xml.pm to make such a change, I am not much of a perl expert.

-- EdwardPlumer - 30 Jan 2004

Any chance this might be used for Macromedia ActionScript?

-- ArthurClemens - 09 Feb 2004

Forgive me if I'm wrong, but AFAICT this plugin has not been checked into CVS for a very long time. Shouldn't we be removing the "Developer Version in CVS" flag for plugins in this state? Where the revision controlled version is a long way behind the release?

-- CrawfordCurrie - 18 Mar 2004

done, although it will be checked into CVS again in the (somewhat) near future. -- WillNorris - 19 Nov 2004

As the modification flag was set to PleaseFeelFreeToModify, I checked in the zip version.

-- MattWilkie - 21 Mar 2004

I just tried the %CODE{"xml"}% form and it doesn't do any XML indent or other prettifying.

-- AndyBayerl - 25 Mar 2004

I sent the following mail to the beautifier.org list yesterday, will update if/when there's a response.

Hello, I was looking at the BeautifierPlugin for TWiki and found a little problem with the XML formatter, namely that it doesn't indent tags properly.

I tracked this down through HFile_xml.pm, trying different things for $self->{indent} and $self->{unindent}, and it seems the problem is that you can't have multi-character indent strings -- I'd figure for XML you would want the equivalent of:

$self->{indent} = ["<\w"];
$self->{unindent} = ["</\w", " />"];

but the routine responsible for matching these (Core.pm:starts_with(), I think) uses substr() not regexps. It seems like you could do this with an inline grep() call instead of substr(), but I got lost teasing the logic around line 476 apart -- hence this post. Am I on the right track here?

As the comments on http://twiki.org/cgi-bin/view/Plugins/BeautifierPluginDev indicate, there is some user demand for the XML parser to work, and there may be other languages that would benefit from allowing regexp, or minimally even multi-character, indent/unindent delimiters.

Can you help?

-- EricSorenson - 19 Nov 2004

Glad others have a need for the XML schema as well ... wish I new Perl to help wink Here are a few more issues that I wonder if anyone has run into or knows how to patch? Also the work-around I am using.

  • Using "java" schema (others might do this too), camel-case variable names (e.g. myLoopCounter) on the last line of the code snippet are rendered as wiki names. work-around: add a blank-line as the last line of the code snippet to ensure all real lines are formatted correctly.

  • XML problem I described some time back. work-around: explicitly use the "fragment" class in a div tag to get the right fonts, highlight box, indenting, etc. and do without the color-coding for now.

  • If I have a SEARCH{ ... } operation anywhere on a topic, the Beautifier plugin prints the error message "BeautifierPlugin Error: Unable to handle "java" syntax." My particular search looked like

%SEARCH{ search="MyCleverTopicPrefix" scope="topic" nosearch="on" nototal="on" }%

and was used to link in related pages dynamically. work-around: I have no idea what to do here. I have not found a trick to put both elements (search and code) in the same topic.

-- EdwardPlumer - 25 Jan 2005

added .zip (and extra HFile_*.pm files) to CVS

-- WillNorris - 27 Jun 2005

Please consider adding use strict; to this plugin. Its use is important to ensuring the quality of TWiki plugins and avoiding unpleasant surprises. See UseStrict for more.

-- MeredithLesly - 02 Jul 2006

Does anyone else receive lots of occurences of the following error when using this plugin?:

[Wed Aug 02 10:34:06 2006] [error] [client] [Wed Aug 2 10:34:06 2006] view: Use of uninitialized value in concatenation (.) or string at /home/www/twiki/lib/Beautifier/Core.pm line 537.

It mainly seems to occur when users hit topics using the python code highlighting module but I'm not absolutely sure it doesn't happen when others are used instead.

-- StephenGordon - 02 Aug 2006

  • In case anyone is wondering about how to enable selection blocks (bolding or highlighting certain lines of code), you have to modify the HFile_*'s to tell them what symbols start and end the blocks. For example, I have modified my lib/HFile/HFile_java by adding the following lines of code:
            $self->{selecton}               = "<!";
            $self->{selectoff}              = "!>";
            $self->{lineselect}             = "!!";

  • Once you do this, though, and try to use block selections, you'll discover a bug in lib/Beautifier/Core.pm. Line 148 has some debug code that was never disabled. Change:
        if (!$DEBUG) { print "Selection close\n"; }


        if ($DEBUG) { print "Selection close\n"; }

-- NeilMcCurdy - 17 Nov 2006

I've run into a problem trying to write an HFile for another programming language (Unicon, not that it matters here) and discovered that trying to use a word ('end', say) as a flag for unindent results in any word that is prefixed with 'end' (e.g. 'endTag') to also be used as an unindent flag. I'm not a perl programmer, can someone who is one take a look at Core.pm and see why this might be happening?

On a separate note, Unicon includes syntax entities (called keywords in Unicon-speak) that start with an & (e.g. &input, &output, &clock, etc.). I'd like to highlight these separately from other lexical elements, but it looks as though Beautifier is splitting &input into two tokens: '&' and 'input'. Is there a way around this? I suspect it's non-trivial and can live without this special highlighting, but maybe someone knows of a way?


-- SteveWampler - 21 Jun 2007

This plugin advertises verilog support, however, I see no included "Hfile" that supports verilog.

-- SteveRJones - 02 Jul 2007

Can anyone tell me how to suppress variable substitution in CODE blocks?

date +%Y%m

looks kind of funny (at least with TWiki-4.1.2, Sat, 03 Mar 2007, build 13046, Plugin API version 1.11 and BeautifierPlugin version 14024 (03 Jun 2007)):

%CODE{"bash"}% date +DONEm %ENDCODE%

The %Y% gets expanded, but I see a verbatim html snippet there.

Using does not work, the nop ist displayed in the CODE-block.

Another interesting question would be, how icons can be used inside CODE-blocks (though I'll never need that feature, I suppose).

I worked around the issue by using just verbatim in favor of CODE, so I do not need a fix.

-- HeinerWestphal - 20 Sep 2007

Would be nice if we could add line numbers as an option to beautifier: like:

 %CODE{ "bash" nu="on"}%

-- MarcoSilva - 23 Sep 2007

Where is the plugin appraisal for Beautifier?

-- MarcoSilva - 26 Oct 2007

http://www.beautifier.org is no more hosting, using koders we can find more HFiles, http://www.koders.com/perl/fid8C3C3EE0A10C107C8DB3FEBB3517EC99DCE0A7A7.aspx?s=spider

-- MarcoSilva - 30 Oct 2007

With TWiki v4.1.0 and Beautfier, I get two sets of errors in the access.log for twiki when trying to save an edited page using the

. The page appears to save okay.

First error:

view: Use of uninitialized value in numeric eq (==) at /path/twiki/lib/Beautifier/Core.pm line 113

I worked around this by checking if


if ($self->{highlightfile}->{notrim} == 0)
if (not defined ($self->{highlightfile}->{notrim}) || (defined ($self->{highlightfile}->{notrim}) && $self->{highlightfile}->{notrim} == 0))

I'm not too clear on how to fix the second pair of errors:

view: Use of uninitialized value in array dereference at /path/twiki/lib/Beautifier/Context.pm line 59
view: Use of uninitialized value in array dereference at /path/twiki/lib/Beautifier/Context.pm line 60

@{$self->{alldelims}} = @{$lang->{delimiters}};
push(@{$self->{alldelims}}, @{$lang->{stringchars}});

-- AaronHooley - 08 Jan 2008

Hi, I've installed the plugin on 4.2.0 from the configure page using "Find More Extension" link and received error:

Subroutine install redefined at /srv/www/twiki420/BeautifierPlugin_installer line 890.
When checking the installed plugin page the test code was rendered correctly so basically the plugin appears to work.

-- IngoKappler - 10 Apr 2008

Has anyone worked out the necessary highlighting rules for PHP4 / PHP5?

-- VickiBrown - 13 May 2008

DpSyntaxHighlighterPlugin does have rules for php.

-- ArthurClemens - 13 May 2008

Reiterating HeinerWestphal's desire of a year ago, I would also like to be able to beautify HTML code that contains embedded TWIki variables.

Specifically, I'd like to be able to beautify something like this:

 <form action="%SCRIPTURLPATH%/save%SCRIPTSUFFIX%/%WEB%/"> 
   <input type="hidden" name="onlywikiname"  value="on" />
   <input type="hidden" name="onlynewtopic"  value="on" />
   <input type="hidden" name="templatetopic" value="SomethingTemplate" />
   <input type="hidden" name="topicparent"   value="%TOPIC%"  />

   <input type="text" name="topic"  size="30" value="" />
   <input type="submit" />

  • If I wrap this code in <verbatim> and put %CODE{"html"}% outside of the verbatim tags, I get one green verbatim
  • If I put the %CODE{"html"}% inside a verbatim, it's rendered verbatim (duh) and the plugin doesn't run (no coloring)
  • If I leave out <verbatim>, the plugin handles protecting the html tags (good) but TWIki gobbles up and evaluates the variables (bad)
  • If I put in <nop> for the TWiki variables, the plugin thinks that's HTML and colors it. :-(

Is there any way I can "beautify" this mixed code? (BeautifierPlugin needs a way to be told to ignore TWiki variables. Maybe something like $percnt?)

-- VickiBrown - 01 Oct 2008

The plugin breaks my Twiki page with the following snippet:

%CODE{"html"}% <!--[if lt IE 7]> <img src="/images/logo_prolia-home.gif" alt="prolia™ denosumab - a force against fracture" /> <![endif]--> <!--[if gte IE 7]> <img src="/images/logo_prolia-home24.png" alt="prolia™ denosumab - a force against fracture" /> <![endif]--> <!--[if IE]><!--> <img src="/images/logo_prolia-home24.png" alt="prolia™ denosumab - a force against fracture" /> <!--<![endif]--> %ENDCODE%

-- DmitriMoore - 2012-08-21

Edit | Attach | Watch | Print version | History: r47 < r46 < r45 < r44 < r43 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r47 - 2012-08-21 - DmitriMoore
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.