Skip to content

Commit

Permalink
Add configuration for theme selection
Browse files Browse the repository at this point in the history
  • Loading branch information
christianezeani committed Apr 23, 2023
1 parent 29c2a1c commit 36d8e1f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# codify Plugin for DokuWiki
# Codify Plugin for DokuWiki

All documentation for this plugin can be found [here][plugin-url]

Expand Down
25 changes: 24 additions & 1 deletion dist/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,40 @@

class action_plugin_codify extends DokuWiki_Action_Plugin {

const THEME = [
'default' => 'prism',
'dark' => 'prism-dark',
'funky' => 'prism-funky',
'okaidia' => 'prism-okaidia',
'twilight' => 'prism-twilight',
'coy' => 'prism-coy',
'solarizedlight' => 'prism-solarizedlight',
'tomorrow' => 'prism-tomorrow',
];

private function getTheme() {
$value = $this->getConf('theme');

if (isset(self::THEME[$value])) {
return self::THEME[$value];
}

return self::THEME['default'];
}

public function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_hookjs');
}

public function _hookjs(Doku_Event $event, $param) {
$pluginBase = DOKU_BASE.'lib/plugins';

$theme = $this->getTheme();

// BEGIN: Stylesheets
$event->data['link'][] = array(
'rel' => 'stylesheet',
'href' => 'https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.min.css'
'href' => "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/{$theme}.min.css"
);

$event->data['link'][] = array(
Expand Down
3 changes: 3 additions & 0 deletions dist/conf/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$conf['theme'] = 'default';
15 changes: 15 additions & 0 deletions dist/conf/metadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$meta['theme'] = [
'multichoice',
'_choices' => [
'default',
'dark',
'funky',
'okaidia',
'twilight',
'coy',
'solarizedlight',
'tomorrow',
]
];
3 changes: 3 additions & 0 deletions dist/lang/en/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$lang['theme'] = 'Theme';
2 changes: 1 addition & 1 deletion dist/plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base codify
author Christian Ezeani
email christian.ezeani@gmail.com
date 2023-03-31
date 2023-04-23
name Codify Plugin
desc Provides awesome code highlighting using PrismJS in dokuwiki pages.
url http://www.dokuwiki.org/plugin:codify

0 comments on commit 36d8e1f

Please sign in to comment.