Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

JavaScript-Editable

Summary: How to include JavaScript markup in wiki pages
Version:
Prerequisites:
Status:
Maintainer:
Categories: Markup
Users: +1 (View / Edit)

Question

Is it possible to include JavaScript markup in wiki pages?

Answer

Yes. Using this recipe you can embed JavaScript in your pages. However, keep in mind that allowing JavaScript (as well as html) on an editable wiki page is dangerous: code inserted by a malicious visitor could be quite harmful. In this case, password protecting the pages is a reasonable suggestion.

Markup

You can use the custom markup in your local/config.php:

   Markup(
       'html',
       'fulltext',
       '/\\(:html:\\)(.*?)\\(:htmlend:\\)/mesi',
       "Keep(str_replace(array('&lt;', '&gt;', '&amp;'), array('<', '>', '&'),
       PSS('$1')))"
   );

This markup won't parse the text within (:html:) and (:htmlend:).

Example in your wiki page:

   (:html:)
   <script language="JavaScript">
       alert("Thanks to PM for that markup.");
   </script>
   (:htmlend:)

Notes

It must be stressed again and again that including JavaScript on an editable page could be dangerous.

Comments

  • (13/Aug/2010) You can use the standard cookbook installation, by copying the following file in your cookbook directory: JavaScript-Editable.phpΔ , and add include('cookbook/JavaScript-Editable.php'); in your 'local/config.php' -Profiles.MassimilianoVessi
  • Inserted code into config and tried using the alert example given in PmWiki2.1beta20 with monobook skin in farm. All it produced was the text of the script. Same result when I inserted the JavaScript for a google map. Des Feb 16, 2006.
  • Same results here with Pmwiki 2.0.13. The problem is the '<' and '>' characters get changed to '&lt;' and '&gt;'.
  • In the process of posting the above note, I realized the problem with the code. The markup code as viewed in edit mode was correct, but was rendering differently. I fixed it to render correctly. -JC

This note already existed at the time this recipe page was created, but it was easy to overlook. The code there might work a little better because your block of code will not necessarily be <p>inside a paragraph</p>. Hagan

  • Thanks for the pointer. I trialled the markup in the note and it worked first time. Although the page is protected, I've now removed the markup as anyone familiar with the related (:html:) could use it on any open page to freely insert code. Maintaining the google map API code on an external page and using (:includeurl:) seems safer. Des Feb 26, 2006.

Using this script, I was able to add Google Translate to my sidebar. Not too shabby! - Aargau3

See Also

Contributors

  • Luigi -> mailto:kirpi [snail] kirpi [period] it humbly reported from the Mailing Lists.
  • Torsten is the main contributor.
Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:42 AM