Skip to content

Commit

Permalink
Merge pull request #6 from ssahara/dev2
Browse files Browse the repository at this point in the history
Dev2
  • Loading branch information
ssahara committed Dec 6, 2017
2 parents 979eef5 + d2ded6b commit 06635f4
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 106 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DokuWiki plugin InlineJS
========================

Allow internal JavaScript and StyleSheet in wiki pages.
Allow adhoc internal JavaScript and StyleSheet in wiki pages.


Syntax
Expand All @@ -25,7 +25,11 @@ Let some library files preloaded in specific DokuWiki pages
<PRELOAD>
/path/to/some.js # depends on document root of web server
/path/to/some.css
<script src="http://example.com/javascript.js"></script> # external JavaScript
<link rel="stylesheet" href="http://example.com/css?key=value"> # external css
<style>
... css rule-set ...
</style>
</PRELOAD>


Expand Down
28 changes: 21 additions & 7 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,35 @@ function inlinejs_handleMeta(Doku_Event $event, $param) {
if (!isset($INFO['meta']['plugin_inlinejs'])) return;

foreach ($INFO['meta']['plugin_inlinejs'] as $entry) {
switch ($entry['type']) {
case 'css':
switch ($entry['_tag']) {
case 'style':
$event->data['style'][] = array(
'type' => 'text/css',
'_data' => $entry['_data'],
);
break;
case 'link':
$event->data['link'][] = array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => $entry['path'],
'href' => $entry['href'],
);
break;
case 'js':
$event->data['script'][] = array(
case 'script':
if (isset($entry['src'])) {
$event->data['script'][] = array(
'type' => 'text/javascript',
'charset' => 'utf-8',
'src' => $entry['path'],
'src' => $entry['src'],
'_data' => '',
);
);
} else {
$event->data['script'][] = array(
'type' => 'text/javascript',
// 'charset' => 'utf-8',
'_data' => $entry['_data'],
);
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$lang['preloader-intro'] = "REMARK: Additional css and/or js file(s) loaded in <head> section.";
$lang['preloader-intro'] = "REMARK: Additional CSS / JavaScript definitions in <head> section";
2 changes: 1 addition & 1 deletion lang/ja/lang.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

$lang['preloader-intro'] = "※ <head>セクションにおいて、次の css または js ファイルを読み込んでいます.";
$lang['preloader-intro'] = "※ <head>セクションに追加定義される CSS / JavaScript";
4 changes: 2 additions & 2 deletions plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base inlinejs
author Satoshi Sahara
email sahara.satoshi@gmail.com
date 2017-11-25
name Inline Javascript and CSS plugin
date 2017-12-06
name Inline JavaScript and CSS plugin
desc Allow spot-based embedding of JavaScript and StyleSheet in the page.
url https://www.dokuwiki.org/plugin:inlinejs
3 changes: 2 additions & 1 deletion syntax/embedblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

class syntax_plugin_inlinejs_embedblock extends syntax_plugin_inlinejs_embedder {

//protected $mode, $pattern;
//protected $mode, $pattern;
//protected $code = null;

function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
Expand Down
29 changes: 9 additions & 20 deletions syntax/embedcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

class syntax_plugin_inlinejs_embedcss extends syntax_plugin_inlinejs_embedder {

//protected $mode, $pattern;
//protected $mode, $pattern;
//protected $code = null;

function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
Expand All @@ -35,28 +36,16 @@ function getPType() { return 'block'; }
/**
* Create output
*/
function render($format, Doku_Renderer $renderer, $indata) {
function render($format, Doku_Renderer $renderer, $data) {

if (empty($indata)) return false;
list($state, $data) = $indata;
list($state, $code) = $data;
if ($format != 'xhtml') return false;

switch ($state) {
case DOKU_LEXER_ENTER:
$html = '<style type="text/css">'.DOKU_LF.'<!-- ';
$renderer->doc .= $html;
break;

case DOKU_LEXER_UNMATCHED:
//$renderer->doc .= $renderer->_xmlEntities($data);
$renderer->doc .= $data; // raw write
break;

case DOKU_LEXER_EXIT:
$html = ' -->'.DOKU_LF.'</style>'.DOKU_LF;
$renderer->doc .= $html;
break;
}
$html = '<style type="text/css">'.DOKU_LF.'<!-- ';
$html.= $code; // raw write
$html.= ' -->'.DOKU_LF.'</style>'.DOKU_LF;
$renderer->doc .= $html;

return true;
}

Expand Down
42 changes: 20 additions & 22 deletions syntax/embedder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class syntax_plugin_inlinejs_embedder extends DokuWiki_Syntax_Plugin {

protected $mode, $pattern;
protected $code = null;

function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
Expand Down Expand Up @@ -52,48 +53,45 @@ function handle($match, $state, $pos, Doku_Handler $handler) {

global $conf;
if ($this->getConf('follow_htmlok') && !$conf['htmlok']) {
msg($this->getPluginName().': JavaScript embedding is disabled.',-1);
msg($this->getPluginName().': '.$this->getPluginComponent().' is disabled.',-1);
return false;
}

switch ($state) {
case DOKU_LEXER_ENTER:
return array($state,'');
return false;

case DOKU_LEXER_UNMATCHED:
return array($state, $match);
$this->code = $match;
return false;

case DOKU_LEXER_EXIT:
return array($state, '');
$data = array($state, $this->code);
$this->code = null;

if ($this->getConf('follow_htmlok') && !$conf['htmlok']) {
$msg = $this->getPluginComponent().' is disabled.';
msg($this->getPluginName().': '.$msg, -1);
return false;
}
return $data;
}
return false;
}

/**
* Create output
*/
function render($format, Doku_Renderer $renderer, $indata) {
function render($format, Doku_Renderer $renderer, $data) {

if (empty($indata)) return false;
list($state, $data) = $indata;
list($state, $code) = $data;
if ($format != 'xhtml') return false;

switch ($state) {
case DOKU_LEXER_ENTER:
$html = '<script type="text/javascript">'.DOKU_LF.'/*<![CDATA[*/';
$renderer->doc .= $html;
break;

case DOKU_LEXER_UNMATCHED:
//$renderer->doc .= $renderer->_xmlEntities($data);
$renderer->doc .= $data; // raw write
break;
$html = '<script type="text/javascript">'.DOKU_LF.'/*<![CDATA[*/';
$html.= $code; // raw write
$html.= '/*!]]>*/'.DOKU_LF.'</script>'.DOKU_LF;
$renderer->doc .= $html;

case DOKU_LEXER_EXIT:
$html = '/*!]]>*/'.DOKU_LF.'</script>'.DOKU_LF;
$renderer->doc .= $html;
break;
}
return true;
}
}
3 changes: 2 additions & 1 deletion syntax/embedinline.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

class syntax_plugin_inlinejs_embedinline extends syntax_plugin_inlinejs_embedder {

//protected $mode, $pattern;
//protected $mode, $pattern;
//protected $code = null;

function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_'
Expand Down
Loading

0 comments on commit 06635f4

Please sign in to comment.