Skip to content
Permalink
Browse files

Making entities working

  • Loading branch information...
eroux committed Oct 24, 2013
1 parent 5861482 commit f7dff15d50a40fc05fa87ce84aaa4febdf775589
Showing with 51 additions and 29 deletions.
  1. +3 −1 conf/entities.cfg
  2. +42 −10 config.php
  3. +6 −18 texitrender.php
@@ -6,6 +6,7 @@ _ \_
$ \$
< $<$
> $>$
~ \textasciitilde
(c) {\copyright}
(tm) {\texttrademark}
(r) {\textregistered}
@@ -20,4 +21,5 @@ $ \$
^ \^{ }
... \ldots{}
LaTeX \LaTeX{}

• ~
· \,
@@ -53,7 +53,44 @@ function __construct($id, $namespace_mode, $conf, $nsbpc_obj) {
$this->_set_media_dir();
$this->bibfn = $this->generate_bib();
$this->get_all_files();
$this->conf['latexentities'] = false; // we generate it at compile time
$this->texit_render_obj = false;
}
/*
* This function sets $this->latexentities to an array where keys are
* the initial characters and values are the characters escaped in
* LaTeX (ex: _ => \_). It gets in by calling conftohash on conf/entities.cfg
* in the plugin's directory.
*/
function get_entities() {
$basefn = PLUGIN_TEXIT_CONF.'entities.cfg';
return $this->confToHash($basefn);
}
/**
* Builds a hash from a configfile
*
* If $lower is set to true all hash keys are converted to
* lower case.
*
* This is a modified version of Dokuwiki's function
* that doesn't consider # as a comment character (we
* need it for LaTeX entities).
*/
function confToHash($file) {
$conf = array();
$lines = @file( $file );
if ( !$lines ) return false;
foreach ( $lines as $line ) {
$line = trim($line);
if(empty($line)) continue;
$line = preg_split('/[\s\t]+/',$line,2);
// Build the associative array
$conf[$line[0]] = $line[1];
}
return $conf;
}
/*
* This function (eventually) generates the file texit.bib, in the directory
* of the namespace pointed by the "reference-db-enable" configuration option
@@ -235,13 +272,6 @@ function get_common_basename() {
}
}
/* This returns the full path of the entities.cfg config file. Not searched
* through nsbpc.
*/
function get_entities_fn() {
return PLUGIN_TEXIT_CONF.'entities.cfg';
}
/* This returns the full path of the base header file we take as reference
* for this compilation. In case nothing is found, false is returned.
*/
@@ -367,9 +397,6 @@ function get_all_files() {
$fn = wikiFN($value['id']);
$dest = $this->texitdir.'/'.noNS($value['id'])."-content.tex";
$dest = $this->_escape_fn($dest);
// if (!is_writable($dest)) {
// nice_die("TeXit: cannot write in file $dest, please fix your permissions");
// }
$result[$fn] = array('type' => 'tex', 'fn' => $dest);
}
// and we add the header and command
@@ -393,6 +420,7 @@ function get_all_files() {
}
$this->all_files = $result;
}
/* This function takes three arguments:
* * base is the full path of the base header file
* (for instance /path/to/dkwiki/lib/plugin/texit/conf/header-page.tex)
@@ -443,6 +471,10 @@ function compile_header($base, $dest, $all_files) {
* It reads $base, renders it into TeX and writes $dest.
*/
function compile_tex($base, $dest) {
if (!$this->conf['latexentities'])
{
$this->conf['latexentities'] = $this->get_entities();
}
if (!$this->texit_render_obj)
{
$this->texit_render_obj = new texitrender_plugin_texit($this);
@@ -166,11 +166,11 @@ function p_get_instructions_texit(&$text){
if (is_null($this->_Parser)) {
$this->_Parser = & new Doku_Parser();
}
// TODO: this leaves room for optimization, as the same
// handler could be used several times instead of being
// reinstanciated (as is the case now). The problem is
// that there is no reset() function on handlers and all
// attempts to do it by hand failes... patch welcome!
// TODO: this leaves room for optimization, as the same
// handler could be used several times instead of being
// reinstanciated (as is the case now). The problem is
// that there is no reset() function on handlers and all
// attempts to do it by hand failes... patch welcome!
$this->_Parser->Handler = new Doku_Handler();
if (count($this->_Parser->modes) == 0) {
foreach($this->_p_get_parsermodes as $mode){
@@ -266,7 +266,7 @@ function p_render($mode,$instructions, &$info){
$Renderer = & new $rclass(); #FIXME any way to check for class existance?
$Renderer->smileys = getSmileys();
$Renderer->entities = getEntities();
$Renderer->latexentities = $this->getLatexEntities();
$Renderer->latexentities = $this->_texit_conf['latexentities'];
$Renderer->acronyms = getAcronyms();
$Renderer->interwiki = getInterwiki();
$Renderer->info = $info;
@@ -282,18 +282,6 @@ function p_render($mode,$instructions, &$info){
// Return the output
return $Renderer->doc;
}
function getLatexEntities() {
static $latex_ent = NULL;
if ( !$latex_ent ) {
$fn = $this->texit->get_entities_fn();
if (@file_exists($fn)) {
$latex_ent = $this->confToHash($fn);
}
}
return $latex_ent;
}
/**
* Builds a hash from a configfile

0 comments on commit f7dff15

Please sign in to comment.
You can’t perform that action at this time.