Summary: Embed Pastebin pastes in a wikipage.
Version: 2021-12-11
Prerequisites: Recent PmWiki version (tested with 2.2.144); PHP 5
Status: Maintained
Maintainer: Said Achmiz
License: MIT License
Users: (view? / edit)
Discussion: PastebinEmbed-Talk


This recipe lets you embed Pastebin pastes in a wikipage. You can show only some lines of a paste, and highlight certain lines.

Git repository for this recipe:


  1. Download and unzip pastebin-embed.zipΔ
  2. Place the file pastebin-embed.php and the simplehtmldom/ folder into your cookbook/ directory
  3. Add such a line to config.php:


The basic usage is simple:

(:pastebin-embed paste-id:)

(For example, (:pastebin-embed T3rxzk4N:).)

There are several optional arguments (which must go after the paste id):


Do not embed a script which makes the browser retrieve the paste; instead, retrieve the paste server-side, and insert it into the page that’s served to the browser.


Don’t show the “footer” (actually a header).


Hide the line numbers.


Don’t display syntax coloring, line numbers, footer, etc.; just show the raw text of the paste.


Don’t wrap the raw text in a <pre> tag and don’t encode HTML entities (useful if, for example, the text is going to be processed by some other markup, such as PmPygment or MarkdownMarkupExtension). (Does nothing if raw mode is not used.)

lines=comma-separated list of lines or line ranges

Show only specified lines/ranges. The lines= parameter takes three kinds of arguments:

  1. Single line (e.g., lines=2)
    (This will include the specified line.)
  2. Line range with a start and end line (e.g., lines=5-7)
    (This will include all lines from the start to the end of the range, inclusive.)
  3. Line range with a start line only (e.g., lines=10-)
    (This will include all lines from the start of the range to the end of the file.)

The three kinds of arguments may be combined freely. For example:

(:pastebin-embed T3rxzk4N lines=2,5-7,11,15- :)

This will show lines 2, 5, 6, 7, 11, and line 15 onward.

hl=comma-separated list of lines or line ranges

Highlight the specified lines/ranges. The hl= parameter takes exactly the same sort of arguments as the lines= parameter (see above).

NOTE: The styling for highlighted lines (by default, a yellow background) may be customized, by setting the $PastebinEmbedHighlightStyle variable in config.php (before including pastebin-embed.php). For example, suppose you want to change the yellow background to fuchsia, and also make the text of highlighted lines bold:
$PastebinEmbedHighlightStyle = "background-color: fuchsia; font-weight: bold;";


Enable dark theme for the embedded paste. (Does nothing in raw mode.)

Note that mixing and matching light-theme and dark-theme pastes on the same page does not really work right; this is a limitation of the Pastebin-provided CSS.


The no-js, nofooter, and nolinenums options may be used together, in any combination (for example, (:pastebin-embed T3rxzk4N nofooter nolinenums:)).

The raw option makes the above three options moot. The no-pre option applies only if raw is also specified.

The no-js option may be used for browsers which do not support Javascript (or for users who have Javascript disabled). However, it will result in slightly slower initial page loads (because the default Javascript method loads the paste asynchronously, after the page has already loaded, whereas with no-js, the paste must be retrieved before the wikipage may be fully rendered). (The same is true of the raw option.)

The lines=, hl=, and theme=dark options may be used in combination with any other option.


This recipe uses the PHP Simple HTML DOM Parser by S. C. Chen.

Change log / Release notes

  • 2021-12-11: Fixed bugs due to Pastebin updates; updated simplehtmldom version; added dark theme support.
  • 2018-10-19: Bug fix.
  • 2017-12-27: Bug fix.
  • 2017-12-26-2: Line highlighting added.
  • 2017-12-26: Line ranges may now be specified (just as with GistEmbed).
  • 2017-12-25: In raw mode (without no-pre), HTML entities are now properly encoded.
  • 2017-12-24-3: Minor bug fix.
  • 2017-12-24-2: Added no-pre flag; changed markup priority.
  • 2017-12-24: Initial release.

See also

Ape also allows embedding of Pastebin pastes; however, Ape embeds the paste inside an <iframe>, which causes certain problems (e.g. there is no way to size the frame automatically to show all the content), and does not allow any way to hide the footer, line numbers, etc. In comparison, Pastebin Embed is a more lightweight and flexible solution (but only does Pastebin embedding, not any of the other things that Ape does).



See discussion at PastebinEmbed-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.