Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've hacked together some quick enhancements for the Free Nodelet. Go to Nodelet Settings and enable the Free Nodelet if you haven't already.

The main features are:

  • No longer foul up square brackets in JavaScript inside HTML comments.
  • A way to get JavaScript square brackets even outside of HTML comments.
  • A way to "Add this node" similar to what the "Personal Nodelet" has, but more powerful.
  • Simple templates for making interesting links like "How AnonyMonk sees this node" or "This node's author's most-recent write-ups".

This enhancement should be considered experimental, as it was a quick hack and a much better design may be proposed after we get more experience with it. But I wanted to actually deploy it so anyone could play with it in order to encourage feedback on how to improve it. So, please try it out, but realize that we might announce major changes sooner or later that may break some of what you write.

All of the features (except the first) are provided by a simple templating system that uses ` (backtick) as the only metacharacter. This was chosen because it is a character that is not useful in JavaScript nor HTML.

Only in the Free Nodelet, `id` gets replaced with the current node's node_id. `title` gets replaced with the current node's title. If using the title in HTML (almost always), use `title&` instead to get the title with &, <, >, [, and ] characters escaped as HTML entities. To use a title in a URL, use `title%` to have it URL-escaped (using %xx).

The following items get expanded if put between a pair of backticks (`) in the Free Nodelet:

  • id - current node's ID
  • title - current node's title
  • author_id - current node's author's user ID number
  • author_name - current node's author's name
  • author_title - same as author_name ("title" of their home node)
  • user_id - your ID (useful for writing macros that another user can paste into their nodelet)
  • user_name - your monk name
  • user_title - same as user_name
  • _arg - the value of the CGI parameter '_arg' or 'arg' ("arg" can be anything, but the leading _ is required).
Each of the above can have a & or % on the end (just before the closing backtick). Other items like root_id, root_title, sect_id, and sect_title may be added in future. You don't need to use & nor % on *id items, since they expand to just digits and digits don't need to be escaped.

The above expansions happen before [...] links are processed, so you can make a link like [id://`id`|Bookmark node `id`].

The following substitutions are also made:

  • `[ becomes [
  • `] becomes ]
  • `` becomes `
  • ``` becomes ``
  • ```` becomes ```
  • etc.
Note that `[ gets expanded in such a way that the resulting [ will not be processed as a PerlMonk's link specification. So the resulting [ can be part of some JavaScript. Inside of HTML comments, either `[ or just [ can be used.

Note that "HTML comments" at PerlMonks simply start with "<!--" and simply end with "-->". In real HTML comments, whitespace is allowed inside these start/end sequences and occurrences of "--" inside the comments have special meaning. Since the Free Nodelet's HTML is not filtered by PerlMonks, if you put "--" inside your HTML comments there, you might "confuse" your browser, but PerlMonks doesn't care about any appearances of "--" in your HTML comments when it comes to deciding where to not process [...] as a link.

A `_foo` gets expanded to whatever the _foo parameter was set to in the URL (or POST) used to fetch the page, such as via ;_foo=bar. If the no "_foo" parameter exists, then the value of the "foo" parameter is used instead. If not even a "foo" parameter exists, then the item is left as `_foo`, just as is done with any unrecognized template-like item.

Below I'll include a couple of annoted examples of how to use these features and even the source code I used to implement the features. I look forward to your feedback.

- tye        


In reply to Free Nodelet gets templating features by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found