====== xhtmlruby plugin ====== ---- plugin ---- description: Converts Japanese furigana written as 漢字(ふり) into XHTML 1.1 漢字(ふり) markup author : Mike "Pomax" Kamermans email : pomax@nihongoresources.com type : Action lastupdate : 2010-10-14 compatible : 2009-02-14 tags : ruby, furigana downloadurl: http://projects.nihongoresources.com/downloadables/plugin-xhtmlruby.tar.gz ---- ===== Download and Installation ===== Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually. * [[http://projects.nihongoresources.com/downloadables/plugin-xhtmlruby.tar.gz|tar.gz format (3k)]] FIXME Link not available (as at 12-Sep-2013) * [[http://sites.google.com/site/seifer03/index/dokuwiki_xhtmlruby.zip|zip format (3k)]], Temp Mirror :!: ===== Important installation note ===== DokuWiki is itself XHTML 1.0 compliant, but the ruby element was not admitted to XHTML until 1.1 - this means that if you want your DokuWiki to pass w3c validation, you will need to change the header signature that DokuWiki generates in the inc/actions.php file. Change lines 485 and 486 from: $pre .= '' . DOKU_LF; to: $pre .= '' . DOKU_LF; and [[http://validator.w3.org|w3c validation]] should now pass all ruby elements without complaint, rather than generating a massive error and warning for each and every one of them. ===== Getting your guide text marked up as ruby ===== This plugin will convert Japanese kanji with furigana in parentheses into XHTML 1.1 ruby element markup, meaning that 漢字(ふり) in your wiki text (including headings) will be automatically converted to: 漢字(ふり) when the page is rendered. While it should be obvious, this plugin does not modify your wiki text in any way, it merely does the substitution when the page gets rendered. The plugin also allows for 'empty' guide text, to force guide text to be over a specific subset of characters: 駅()前(まえ) will generate: (まえ) rather than: 駅前(まえ) ===== Details ===== Because ruby markup must be set up not just for the page text, but also the text in headings and the TOC, this is an XHTML post-processing action plugin, rather than a syntax plugin. The replacement is based on a regular expression search and replace: kanji = "[\x{4E00}-\x{9FFF}\x{3005}\x{30F6}]+"; kana = "[\x{3040}-\x{30FF}]+"; search = "/(".kanji.")\((".kana.")\)/u"; replace = "$1($2)"; "kanji" cover the "CJK Unified Ideograph" Unicode block, plus the Unicode glyphs 々 (kanji repetition) and ヶ (simplified form of 箇), "kana" covers the "Hiragana" and "Katakana" Unicode blocks. ===== Todo ===== * Extend the plugin so that Chinese "bopomofo" phonetic guide text, as well as Korean Hangul are parsed as readings, and the CJK Unified Ideograph extensions blocks A and B are considered legal kanji forms, too. ===== Bugs ===== None known at the time of writing. Unfortunately, on my 2017 Frusterick Manners, this plugin causes ReferenceError: addInitEvent is not defined addInitEvent(function(){ fixRubyAlignment(); }); js.php?...3892c5d (line 65824) I have changed ''addInitEvent'' on the last line of script.js to ''jQuery'' (per suggestion on [[plugin:cellbg#compatibility_issues]] although I don't know the reason), but then it's found that on Line 29 ''cssRule.selectorText'' is also not defined... So finally I decided to: - remove script.js in the plugin folder - disable the plugin - re-enable it again -> seems no problem so far, the action.php and the CSS file still do their jobs. I know that script.js can deal some compatibility problems across browsers, but I don't have the ability to debug it. --- [[user>MilchFlasche|MilchFlasche]] //2017-11-03 17:11// ===== Source ===== This plugin consists of four files: - style.css - CSS styling for the ruby markup - conf.ini - an ini file for setting whether to parse wiki text or not, and TOC text or not. - script.js - a script that ensures the CSS styling is correct for the browser that's loading the page - action.php - the plugin /* ---------------- Ruby markup ----------------- */ ruby { display: inline-table; text-align: center; vertical-align: bottom; } rb { display: table-row-group; } rt { display: table-header-group; font-size: 60%; } rp { display: none; } ; ; This is the configuration file for the xhtmlruby action plugin ; [config] ; if 'true', wiki text will be rubified. if 'false', it won't be (includes headers) parse_wiki_text = true ; if 'true', text in the TOC will be rubified. if 'false', it won't be. parse_toc_text = false /** * * XHTML 1.1 Ruby markup suffers from the "browsers don't always bother to obey CSS" problem. * The standard way to visualise ruby is by making the ruby code an inline table, and bottom * aligning it. However, not all browsers understand "bottom". or "baseline". This javascript * will try to make sure the ruby placement is correct for all major browsers by detecting the * browser, and modifying the ruby CSS rules accordingly. * * - Mike "Pomax" Kamermans */ // ---------------------------------------------------------------------------------------------------------------------- // CSS MANIPULATION // // based on http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript // ---------------------------------------------------------------------------------------------------------------------- function getCSSRule(ruleName, deleteFlag) { ruleName=ruleName.toLowerCase(); if (document.styleSheets) { for (var i=0; i */ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'action.php'); class action_plugin_xhtmlruby extends DokuWiki_Action_Plugin { var $version = '2009-10-26'; // configurable options var $parse_wiki_text = false; var $parse_toc_text = false; // for now, we operate on Japanese only - TODO: bopomofo and hangul rubification var $re_kanji = "[\x{4E00}-\x{9FFF}\x{3005}\x{30F6}]+"; var $re_kana = "[\x{3040}-\x{30FF}]*"; // s/// patterns var $re_search = ""; var $re_replace = ""; function getInfo() { return array( 'author' => 'Mike "Pomax" Kamermans', 'email' => 'pomax@nihongoresources.com', 'date' => $this->version, 'name' => 'xhtmlruby', 'desc' => 'Converts Japanese 漢字(ふり) into xhtml 1.1 漢字(ふり) markup', 'url' => 'n/a'); } /** * Postprocesses the HTML that was built from that, to rubify kanji that have associated furigana. */ function register(Doku_Event_Handler $controller) { // initialise variables $this->re_search = "/(".$this->re_kanji.")\((".$this->re_kana.")\)/u"; $this->re_replace = "$1($2)"; // initialise ini variables $inivars = parse_ini_file(DOKU_INC.'lib/plugins/xhtmlruby/conf.ini'); if($inivars['parse_toc_text']==true) { $this->parse_toc_text = true; } if($inivars['parse_wiki_text']==true) { $this->parse_wiki_text = true; } // uses a custom hook that needs to be added in html.php, see documentation if($this->parse_toc_text===true) { $controller->register_hook('HTML_TOC_ITEM', 'AFTER', $this, '_rubify_tocitem'); } if($this->parse_wiki_text===true) { $controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'AFTER', $this, '_rubify'); } } /** * rubify for ToC items */ function _rubify_tocitem(&$event, $param) { $item = &$event->data; $item = preg_replace($this->re_search,$this->re_replace,$item); } /** * rubify for wiki text */ function _rubify(&$event, $param) { // reference to data and associated data type $data = &$event->data[1]; $datatype = &$event->data[0]; // do nothing if the data is not not XHTML (this only generates XHTML ruby markup) if ($datatype != 'xhtml') { return; } // and finally, perform the postprocessing 'en place' $data = preg_replace($this->re_search,$this->re_replace,$data); } } ?>