Commit 794dc845 authored by Ivan D'halluin's avatar Ivan D'halluin
Browse files

Merge branch 'master' of gitlab.utc.fr:crozatst/hdoc

parents 9c772450 f00cf78f
emplacement_hdoc=./to_zip
rootfile=./content.xml
emplacement_hdoc=./to_zip
rootfile=./content.xml
output_xml=./to_zip/content.xml
\ No newline at end of file
<project name="EtherpadToHdoc" default="convert" basedir=".">
<property file="build.properties"/>
<!-- Builds Hdoc structure -->
<target name="construct_hdoc">
<mkdir dir="${emplacement_hdoc}" />
<mkdir dir="${emplacement_hdoc}/META-INF" />
<mkdir dir="${emplacement_hdoc}/OPS" />
<touch file="${emplacement_hdoc}/META-INF/container.xml" />
<touch file="${emplacement_hdoc}/mimetype" />
<echo message="application/x-hdoc+zip" file="${emplacement_hdoc}/mimetype" />
</target>
<!-- Fills Hdoc container -->
<target name="fill_container" depends="construct_hdoc">
<echoxml file="${emplacement_hdoc}/META-INF/container.xml">
<container version="1.0">
<rootfiles>
<rootfile full-path="${rootfile1}" media-type="text/xml" />
</rootfiles>
</container>
</echoxml>
</target>
<!-- Applies Perl Script to exported HTML file from Etherpad -->
<target name="perl_exec" depends="fill_container">
<exec executable="perl">
<arg value="src/normalization.pl"/>
<arg value="${InputPath}"/>
<!-- output dans intermediaire.xml -->
</exec>
</target>
<!-- Launches XSLT transform to Perl script output -->
<target name="xslt_exec">
<xslt style="src/etherpadTohdoc.xsl" in="tmp/intermediaire.xml" out="${output_xml}" />
</target>
<!-- Zipping Hdoc container -->
<target name="zip">
<zip basedir="${emplacement_hdoc}" destfile="${OutputPath}" />
</target>
<target name="convert" depends="fill_container, perl_exec, xslt_exec, zip"/>
</project>
<project name="EtherpadToHdoc" default="convert" basedir=".">
<property file="build.properties"/>
<!-- Builds Hdoc structure -->
<target name="construct_hdoc">
<mkdir dir="${emplacement_hdoc}" />
<mkdir dir="${emplacement_hdoc}/META-INF" />
<mkdir dir="${emplacement_hdoc}/OPS" />
<touch file="${emplacement_hdoc}/META-INF/container.xml" />
<touch file="${emplacement_hdoc}/mimetype" />
<echo message="application/x-hdoc+zip" file="${emplacement_hdoc}/mimetype" />
</target>
<!-- Fills Hdoc container -->
<target name="fill_container" depends="construct_hdoc">
<echoxml file="${emplacement_hdoc}/META-INF/container.xml">
<container version="1.0">
<rootfiles>
<rootfile full-path="${rootfile1}" media-type="text/xml" />
</rootfiles>
</container>
</echoxml>
</target>
<!-- Applies Perl Script to exported HTML file from Etherpad -->
<target name="perl_exec" depends="fill_container">
<exec executable="perl">
<arg value="src/normalization.pl"/>
<arg value="${InputPath}"/>
<!-- output dans intermediaire.xml -->
</exec>
</target>
<!-- Launches XSLT transform to Perl script output -->
<target name="xslt_exec">
<xslt style="src/etherpadTohdoc.xsl" in="tmp/intermediaire.xml" out="${output_xml}" />
</target>
<!-- Zipping Hdoc container -->
<target name="zip">
<zip basedir="${emplacement_hdoc}" destfile="${OutputPath}" />
</target>
<target name="convert" depends="fill_container, perl_exec, xslt_exec, zip"/>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<xsl:apply-templates select="//meta" mode="inHead"/>
<title><xsl:value-of select="//title"/></title>
</head>
<body>
<section>
<xsl:apply-templates select="@*|node()[not(self::meta)]" />
</section>
</body>
</html>
</xsl:template>
<xsl:template match="title">
</xsl:template>
<xsl:template match="meta" mode="inHead">
<xsl:for-each select="./*">
<meta name="{local-name(.)}" content="{./text()}"/>
</xsl:for-each>
<meta charset="utf-8"/>
<meta generator="HdocConverter/Etherpad"/>
</xsl:template>
<xsl:template match="meta">
</xsl:template>
<xsl:template match="h1 | h2 | h3 | h4 | h5 | h6">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="important">
<div class="emphasis"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="exemple">
<div class="example"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="definition">
<div class="definition"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="br">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="br|b|i|ul|ol|li|u|del">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<xsl:apply-templates select="//meta" mode="inHead"/>
<title><xsl:value-of select="//title"/></title>
</head>
<body>
<section>
<xsl:apply-templates select="@*|node()[not(self::meta)]" />
</section>
</body>
</html>
</xsl:template>
<xsl:template match="title">
</xsl:template>
<xsl:template match="meta" mode="inHead">
<xsl:for-each select="./*">
<meta name="{local-name(.)}" content="{./text()}"/>
</xsl:for-each>
<meta charset="utf-8"/>
<meta generator="HdocConverter/Etherpad"/>
</xsl:template>
<xsl:template match="meta">
</xsl:template>
<xsl:template match="h1 | h2 | h3 | h4 | h5 | h6">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="important">
<div class="emphasis"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="exemple">
<div class="example"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="definition">
<div class="definition"><xsl:value-of select="."/></div>
</xsl:template>
<xsl:template match="br">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
<xsl:template match="br|b|i|ul|ol|li|u|del">
<xsl:copy>
<xsl:value-of select="."/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
#!/usr/bin/perl
($InputPath) = @ARGV;
use FindBin;
# OPENING INPUT AN OUTPUT FILES
open(FICH_IN, '<', $InputPath) or die $!;
open(FICH_OUT, '+>', $FindBin::Bin . "/../tmp/intermediaire.xml") or die $! . $FindBin::Bin . "/../tmp/intermediaire.xml";
$insideMeta = 0;
$insideImportant = 0;
$insideExemple = 0;
$insideDefinition = 0;
$insideAttention = 0;
print FICH_OUT '<!-- <?oxygen RNGSchema="http://scenari.utc.fr/hdoc/schemas/xhtml/hdoc1-xhtml.rng" type="xml"?> -->';
while($_ = <FICH_IN>)
{
#print "\n current line : " . $_;
$isDone = 0;
# REMOVE NON-BREAKABLE SPACES AT END OF LINES (USELESS)
while ($_ =~s/&nbsp;//s) {
$_ =~s/&nbsp;//s;
}
# REPLACE BROKEN <br tags by <br/>
while ($_ =~ s/<br$//) {
$_ = $_ . "<br/>";
}
# REMOVE ends of broken br tags
if ($_ =~ /^\/>/) {
$_ =~ s/\/>//;
}
# REMOVE EXISTING DOCTYPE AND META
if ($_ =~ /<!DOCTYPE|<meta|<META/) {
$isDone = 1;
}
# REPLACE HTML TAG BY A SIMPLE ONE (WITHOUT NAMESPACE)
if ($_ =~ /<html/) {
print FICH_OUT "<html>";
$isDone = 1;
}
# TITLE LEVELS
if ($_ =~ /(={1,6})\s(.*)?\s\1/) {
$title_lvl = length $1;
print FICH_OUT '<h' . $title_lvl . '>' . $2 . '</h' . $title_lvl . '>';
$isDone = 1;
}
# META DATA BLOCK
if ($_ =~ /\{#/) {
$insideMeta = 1;
print FICH_OUT '<meta>';
$isDone = 1;
}
if ($_ =~ /#}/) {
$insideMeta = 0;
print FICH_OUT '</meta>';
$isDone = 1;
}
if ($insideMeta == 1)
{
if ($_ =~ /\#([a-z]{1,15})\s([^\#]+)/g)
{
print FICH_OUT "<" . $1 . ">" . $2 . "</" . $1 . ">";
}
$isDone = 1;
}
# IMPORTANT BLOCK
if ($_ =~ /.*\$}/ && !($_ =~ /{\$.*/)) {
$insideImportant = 0;
print FICH_OUT '</important>';
$isDone = 1;
}
if ($insideImportant == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{\$.*/) {
$insideImportant = 1;
print FICH_OUT '<important>';
$isDone = 1;
}
# EXAMPLE BLOCK
if ($_ =~ /.*-}/ && !($_ =~ /{-.*/)) {
$insideExemple = 0;
print FICH_OUT '</exemple>';
$isDone = 1;
}
if ($insideExemple == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{-.*/) {
$insideExemple = 1;
print FICH_OUT '<exemple>';
$isDone = 1;
}
# DEFINITION BLOCK
if ($_ =~ /.*:}/ && !($_ =~ /{:.*/)) {
$insideDefinition = 0;
print FICH_OUT '</definition>';
$isDone = 1;
}
if ($insideDefinition == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{:.*/) {
$insideDefinition = 1;
print FICH_OUT '<definition>';
$isDone = 1;
}
# attention BLOCK
if ($_ =~ /.*!}/ && !($_ =~ /{!.*/)) {
$insideAttention = 0;
print FICH_OUT '</attention>';
$isDone = 1;
}
if ($insideAttention == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{!.*/) {
$insideAttention = 1;
print FICH_OUT '<attention>';
$isDone = 1;
}
if ($isDone == 0) { # if line has been handled without detecting anything, we print it
print FICH_OUT $_;
}
} # END OF FILE LOOP
close(FICH_IN);
#!/usr/bin/perl
($InputPath) = @ARGV;
use FindBin;
# OPENING INPUT AN OUTPUT FILES
open(FICH_IN, '<', $InputPath) or die $!;
open(FICH_OUT, '+>', $FindBin::Bin . "/../tmp/intermediaire.xml") or die $! . $FindBin::Bin . "/../tmp/intermediaire.xml";
$insideMeta = 0;
$insideImportant = 0;
$insideExemple = 0;
$insideDefinition = 0;
$insideAttention = 0;
print FICH_OUT '<!-- <?oxygen RNGSchema="http://scenari.utc.fr/hdoc/schemas/xhtml/hdoc1-xhtml.rng" type="xml"?> -->';
while($_ = <FICH_IN>)
{
#print "\n current line : " . $_;
$isDone = 0;
# REMOVE NON-BREAKABLE SPACES AT END OF LINES (USELESS)
while ($_ =~s/&nbsp;//s) {
$_ =~s/&nbsp;//s;
}
# REPLACE BROKEN <br tags by <br/>
while ($_ =~ s/<br$//) {
$_ = $_ . "<br/>";
}
# REMOVE ends of broken br tags
if ($_ =~ /^\/>/) {
$_ =~ s/\/>//;
}
# REMOVE EXISTING DOCTYPE AND META
if ($_ =~ /<!DOCTYPE|<meta|<META/) {
$isDone = 1;
}
# REPLACE HTML TAG BY A SIMPLE ONE (WITHOUT NAMESPACE)
if ($_ =~ /<html/) {
print FICH_OUT "<html>";
$isDone = 1;
}
# TITLE LEVELS
if ($_ =~ /(={1,6})\s(.*)?\s\1/) {
$title_lvl = length $1;
print FICH_OUT '<h' . $title_lvl . '>' . $2 . '</h' . $title_lvl . '>';
$isDone = 1;
}
# META DATA BLOCK
if ($_ =~ /\{#/) {
$insideMeta = 1;
print FICH_OUT '<meta>';
$isDone = 1;
}
if ($_ =~ /#}/) {
$insideMeta = 0;
print FICH_OUT '</meta>';
$isDone = 1;
}
if ($insideMeta == 1)
{
if ($_ =~ /\#([a-z]{1,15})\s([^\#]+)/g)
{
print FICH_OUT "<" . $1 . ">" . $2 . "</" . $1 . ">";
}
$isDone = 1;
}
# IMPORTANT BLOCK
if ($_ =~ /.*\$}/ && !($_ =~ /{\$.*/)) {
$insideImportant = 0;
print FICH_OUT '</important>';
$isDone = 1;
}
if ($insideImportant == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{\$.*/) {
$insideImportant = 1;
print FICH_OUT '<important>';
$isDone = 1;
}
# EXAMPLE BLOCK
if ($_ =~ /.*-}/ && !($_ =~ /{-.*/)) {
$insideExemple = 0;
print FICH_OUT '</exemple>';
$isDone = 1;
}
if ($insideExemple == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{-.*/) {
$insideExemple = 1;
print FICH_OUT '<exemple>';
$isDone = 1;
}
# DEFINITION BLOCK
if ($_ =~ /.*:}/ && !($_ =~ /{:.*/)) {
$insideDefinition = 0;
print FICH_OUT '</definition>';
$isDone = 1;
}
if ($insideDefinition == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{:.*/) {
$insideDefinition = 1;
print FICH_OUT '<definition>';
$isDone = 1;
}
# attention BLOCK
if ($_ =~ /.*!}/ && !($_ =~ /{!.*/)) {
$insideAttention = 0;
print FICH_OUT '</attention>';
$isDone = 1;
}
if ($insideAttention == 1) {
print FICH_OUT $_;
$isDone = 1;
}
if ($_ =~ /{!.*/) {
$insideAttention = 1;
print FICH_OUT '<attention>';
$isDone = 1;
}
if ($isDone == 0) { # if line has been handled without detecting anything, we print it
print FICH_OUT $_;
}
} # END OF FILE LOOP
close(FICH_IN);
close(FICH_OUT);
\ No newline at end of file
<?oxygen RNGSchema="http://scenari.utc.fr/hdoc/schemas/xhtml/hdoc1-xhtml.rng" type="xml"?><html><head>
<title>/WgiCsM6pyN</title>
</head>
<body>
<br/><meta><auteur>Cécile
<br/></auteur><date>26/12/13
<br/></date></meta>
<br/><h2>Titre de niveau 2 : démo NF29 Etherpad vers Hdoc</h2>
<br/><definition> Une définition ici
<br/></definition>
<br/>Du texte simple en plein milieu
<br/>
<br/><exemple>Et un paragraphe exemple avec un bout en<i> italique</i>
<br/></exemple>
<br/>
<br/>
<br/>
<br/></body>
</html>
<?oxygen RNGSchema="http://scenari.utc.fr/hdoc/schemas/xhtml/hdoc1-xhtml.rng" type="xml"?><html><head>
<title>/WgiCsM6pyN</title>
</head>
<body>
<br/><meta><auteur>Cécile
<br/></auteur><date>26/12/13
<br/></date></meta>
<br/><h2>Titre de niveau 2 : démo NF29 Etherpad vers Hdoc</h2>
<br/><definition> Une définition ici
<br/></definition>
<br/>Du texte simple en plein milieu
<br/>
<br/><exemple>Et un paragraphe exemple avec un bout en<i> italique</i>
<br/></exemple>
<br/>
<br/>
<br/>
<br/></body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<container version="1.0">
<rootfiles>
<rootfile full-path="../OPS/file1.xml" media-type="text/xml" />