Not logged in. · Lost password · Register
Forum: General Help and Support Syntax and Usage RSS
How to use <code> highlighting with external files?
Avatar
cooperbaker #1
Member for 2 months · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to use <code> highlighting with external files?
Hello good people of DokuWiki.

I'm using dokuwiki to document a code-intensive project, and want to include external files from urls on the net (mainly raw github files).

I have unsuccessfully tried to use php like this:

<php>
echo "<code cpp file.cpp>";
echo file_get_contents( "http://some.github.com/rawfile.c" );
echo "</code>";
</php>

Clearly I don't know how/where to insert the raw file contents.

Can anyone suggest a better way to do this?
Avatar
turnermm (Moderator) #2
Member since Oct 2009 · 4544 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
You have to set allow_url_fopen to true in php.ini.  But I don't know if you can create a snippet this way.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
Michaelsy #3
Member since Jun 2015 · 745 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
In reply to post #1
Maybe the PHP Wikify Plugin will help you: https://www.dokuwiki.org/plugin:phpwikify
Another approach would be the Function Plugin: https://www.dokuwiki.org/plugin:function

The best thing would be if you put the best of both plugins together into a single plugin. The best of the PHPWikify Plugin: The PHP output is rendered by DokuWiki, as if it were original wiki code. The best of the Function Plugin: The PHP code can be called as a funcion (resp. macro) with parameters.

Feedback welcome - Michael Sy.
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
This post was edited on 2019-01-11, 07:21 by Michaelsy.
Avatar
cooperbaker #4
Member for 2 months · 2 posts
Group memberships: Members
Show profile · Link to this post
Thanks!  phpwikify is the answer.

Snippet downloading does not work but that's fine for my needs; I'll just put a little link above if I want it.

This is working great now:

<phpwikify>
$url  = 'http://some.github.com/rawfile.c';
$str  = '[['.$url.'|'.pathinfo( $url, PATHINFO_FILENAME ).'.'.pathinfo( $url, PATHINFO_EXTENSION ).']]';
$str .= '<code cpp [enable_line_numbers="true"]>';
$str .= file_get_contents( $url );
$str .= '</code>';
echo( $str );
</phpwikify>
Avatar
Michaelsy #5
Member since Jun 2015 · 745 posts · Location: Düsseldorf, Germany
Group memberships: Members
Show profile · Link to this post
Thank you for sharing your result!
Can you please insert [Solved] at the beginning of the title? (By editing your first post.)
By Patreon.com a few eurons can be fed into the code phasers of
the DokuWiki engine. Besides, Andi's posts are worth reading.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-03-20, 02:39:06 (UTC +01:00)