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: https://git.sr.ht/~achmizs/pmwiki-pastebin-embed.git.
- Download and unzip pastebin-embed.zipΔ
- Place the file
simplehtmldom/folder into your
- Add such a line to
The basic usage is simple:
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:
- Single line (e.g.,
(This will include the specified line.)
- Line range with a start and end line (e.g.,
(This will include all lines from the start to the end of the range, inclusive.)
- Line range with a start line only (e.g.,
(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).
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.
nolinenums options may be used together, in any combination (for example,
(:pastebin-embed T3rxzk4N nofooter nolinenums:)).
raw option makes the above three options moot. The
no-pre option applies only if
raw is also specified.
no-js, the paste must be retrieved before the wikipage may be fully rendered). (The same is true of the
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
no-pre), HTML entities are now properly encoded.
- 2017-12-24-3: Minor bug fix.
- 2017-12-24-2: Added
no-preflag; changed markup priority.
- 2017-12-24: Initial release.
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).
- Said Achmiz (author)
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.