aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2007-08-13 13:05:41 +0000
committerdakkar <dakkar@luxion>2007-08-13 13:05:41 +0000
commit37c3265998389b9c28b50e208e7607cc16ef9e08 (patch)
tree6ab70415ef917eff92c1439d3284624e681363ca
parent r2490@narval: dakkar | 2007-07-07 11:44:04 +0200 (diff)
downloadWebCoso-37c3265998389b9c28b50e208e7607cc16ef9e08.tar.gz
WebCoso-37c3265998389b9c28b50e208e7607cc16ef9e08.tar.bz2
WebCoso-37c3265998389b9c28b50e208e7607cc16ef9e08.zip
ora sta in Text::Restructured::Writer::LibXML
git-svn-id: svn://luxion/repos/WebCoso/trunk@268 fcb26f47-9200-0410-b104-b98ab5b095f3
-rw-r--r--rtest.pl124
1 files changed, 0 insertions, 124 deletions
diff --git a/rtest.pl b/rtest.pl
deleted file mode 100644
index df031fd..0000000
--- a/rtest.pl
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use XML::LibXML;
-use Text::Restructured;
-use YAML;
-
-my $input=<<'EOF';
-======
- Test
-======
-:Author: dakkar
-
-paragrafo
-
-link
-
-mathml: :mathml:`x^2`
-
-.. mathml::
-
- (x^2)/(y^2)
-
-pre::
-
- gino pino
- rino
-
-normale
-
-:titlink:`/path/al/doc/`
-
-EOF
-my $name='--inline--';
-
-my $opts={
- D => {
- generator => 0,
- 'source-link' => 0,
- 'time' => 0,
- },
-};
-my $parser=Text::Restructured->new($opts,'gino');
-if (@ARGV) {
- $name=$ARGV[0];
- $input=do{open my $fh,'<',$name;local $/;<$fh>};
-}
-
-# bad MNODINE, no cookie
-# MY_ROLES gets re-inited before every Parse, so I have to change a
-# global variable
-$Text::Restructured::ROLES{titlink}={
- tag => 'reference',
- attr => {
- refuri => '%s',
- role => sub {
- my ($parser,$attr,$text,$role)=@_;
- $role;
- }
- },
- text => 'dummy',
-};
-
-my $dudom=$parser->Parse($input,$name);
-
-my $xdoc=XML::LibXML->createDocument();
-
-my $MATHML='http://www.w3.org/1998/Math/MathML';
-sub mathml2xml {
- my ($mnode)=@_;
-
- if ($mnode->isText) {
- return $xdoc->createTextNode($mnode->nodeValue);
- }
-
-
- my @children=map {mathml2xml($_)}
- $mnode->childNodes();
-
- my $elem=$xdoc->createElementNS($MATHML,$mnode->nodeName);
- for my $attname ($mnode->attributeList) {
- next if $attname eq 'xmlns';
- $elem->setAttribute($attname,
- $mnode->attribute($attname))
- }
-
- $elem->appendChild($_) for @children;
-
- return $elem;
-}
-
-sub docutils2xml {
- my ($dunode)=@_;
-
- if ($dunode->{tag} eq '#PCDATA') {
- return $xdoc->createTextNode($dunode->{text} || '');
- }
-
- if ($dunode->{tag} eq 'mathml') {
- return mathml2xml($dunode->{attr}{mathml});
- }
-
- my @children=map {docutils2xml($_)}
- @{ $dunode->{content} || [] };
-
- my $elem=$xdoc->createElement($dunode->{tag});
-
- if (defined $dunode->{attr}) {
- while (my ($attname,$attval)=each %{$dunode->{attr}}) {
- if (! defined $attval) {
- $attval='';
- }
- elsif (ref($attval) eq 'ARRAY') {
- $attval=join ' ',@$attval;
- }
- $elem->setAttribute($attname,$attval);
- }
- }
- $elem->appendChild($_) for @children;
-
- return $elem;
-}
-$xdoc->setDocumentElement(docutils2xml($dudom));
-print $xdoc->toString();