Ejemplo n.º 1
0
 private static void TranslateSup(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
 {
     state.Stack.Push("sup");
     //writer.Write("^{");
     writer.Write(@"\textsuperscript{");
     TranslateTexte(article, writer, xElement, state);
     writer.Write("}");
     state.Stack.Pop();
 }
Ejemplo n.º 2
0
        private static void TranslateParagraphe(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            state.Stack.Push("paragraph");
            TranslateTexte(article, writer, xElement, state);

            if (xElement.NextNode != null)
            {
                writer.WriteLine();
                writer.WriteLine();
            }
            state.Stack.Pop();
        }
Ejemplo n.º 3
0
        private static void TranslateImgText(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XAttribute xType   = xElement.Attribute("type");
            XAttribute xSrc    = xElement.Attribute("src");
            XAttribute xBorder = xElement.Attribute("border");
            XAttribute xFond   = xElement.Attribute("fond");

            string type = String.Empty;

            switch (xType.Value)
            {
            case "idea":
                type = "idee";
                break;

            case "warning":
                type = "attention";
                break;

            case "info":
                type = "info";
                break;

            case "error":
                type = "danger";
                break;

            default:
                throw new NotImplementedException();
            }

            state.Stack.Push("imgtexte");
            writer.WriteLine(@"\begin{{{0}}}{{}}", type);
            TranslateTexte(article, writer, xElement, state);
            writer.WriteLine(@"\end{{{0}}}", type);
            writer.WriteLine();

            state.Stack.Pop();
        }
Ejemplo n.º 4
0
        private static void TranslateListe(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            IEnumerable <XElement> xElements = xElement.Elements("element");
            bool isOrdered = xElement.Attribute("type")?.Value == "1";

            state.Stack.Push("liste");
            state.Stack.Push("element");

            writer.WriteLine(isOrdered ? @"\begin{enumerate}" : @"\begin{itemize}");
            foreach (XElement xItem in xElements)
            {
                writer.Write(@"\item ");
                TranslateZoneRedigee(article, writer, xItem, state);
                writer.WriteLine();
            }

            writer.WriteLine(isOrdered ? @"\end{enumerate}" :  @"\end{itemize}");
            writer.WriteLine();

            state.Stack.Pop();
            state.Stack.Pop();
        }
Ejemplo n.º 5
0
        private static void TranslateLink(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XAttribute xHref    = xElement.Attribute("href");
            XAttribute xTarget  = xElement.Attribute("target");
            XAttribute xOnClick = xElement.Attribute("onclick");
            XAttribute xTitle   = xElement.Attribute("title");
            XAttribute xLangue  = xElement.Attribute("langue");

            string rawUrl = EscapeChar(xHref.Value);

            if (xHref.Value.StartsWith("#"))
            {
                // C'est un lien interne. On le squizz.
                TranslateTexte(article, writer, xElement, state);
            }
            else
            {
                if (xHref.Value == xElement.Value)
                {
                    writer.Write(String.Format(@"\href{{{0}}}{{lien}}", rawUrl));
                }
                else
                {
                    writer.Write(String.Format(@"\href{{{0}}}{{", rawUrl));
                    TranslateTexte(article, writer, xElement, state);
                    writer.Write(@"}");
                }
                if (state.Stack.FirstOrDefault(x => x == "rich-imgtexte" || x == "imgtexte") != null || xElement.Ancestors("synopsis").Count() > 0)
                {
                    writer.Write(@"\footnotemark ");
                    state.PendingFootnotes.Add(WriteUrlInFootnote(rawUrl));
                }
                else
                {
                    writer.Write(String.Format(@"\footnote{{\texttt{{{0}}}}}", WriteUrlInFootnote(rawUrl)));
                }
            }
        }
Ejemplo n.º 6
0
 public DirectoryInfo GetArticleSourceDirectory(ArticleType article)
 {
     return(_sourceDirectory.CreateSubdirectory(article.ID));
 }
Ejemplo n.º 7
0
        private static void TranslateCode(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XAttribute xLanguage = xElement.Attribute("langage");

            state.Stack.Push("code");
            writer.Write(@"\begin{lstlisting}");

            if (xLanguage != null)
            {
                switch (xLanguage.Value.ToLower())
                {
                case "assembly-r2000":
                    writer.Write(@"[language={[Motorola68k]Assembler}]");
                    break;

                case "c":
                    writer.Write(@"[language=C]");
                    break;

                case "cpp":
                    writer.Write("[language=C++]");
                    break;

                case "csharp":
                    writer.Write(@"[language={[Sharp]C}]");
                    break;

                case "html":
                    writer.Write(@"[language=HTML]");
                    break;

                case "java":
                    writer.Write("[language=Java]");
                    break;

                case "javascript":
                    //writer.Write("[language=Java]");
                    break;

                case "makefile":
                    writer.Write("[language=make]");
                    break;

                case "apacheconf":
                case "other":
                    break;

                case "php":
                    writer.Write("[language=PHP]");
                    break;

                case "qml":
                    break;

                case "qt":
                    writer.Write("[language=C++]");
                    break;

                case "shell":
                case "shellscript":
                    writer.Write("[language=sh]");
                    break;

                case "text":
                    break;

                default:
                    //writer.Write(@"[language={0}]", xLanguage.Value);
                    break;
                }
            }

            writer.WriteLine();

            foreach (XNode xChildNode in xElement.Nodes())
            {
                switch (xChildNode.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    XText xChildText = xChildNode as XText;
                    writer.Write(EscapeCharInListing(xChildText.Value));
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            //TranslateTexte(article, writer, xElement, state);
            writer.WriteLine(@"\end{lstlisting}");
            state.Stack.Pop();
        }
Ejemplo n.º 8
0
        private static void TranslateZoneRedigee(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            if (xElement != null)
            {
                IEnumerable <XNode> xNodes = xElement.Nodes();
                foreach (XNode xChildNode in xNodes)
                {
                    switch (xChildNode.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        XElement xChildElement = xChildNode as XElement;
                        switch (xChildElement.Name.ToString())
                        {
                        case "annotation-kitoodvp":
                            break;

                        case "b":
                            TranslateB(article, writer, xChildElement, state);
                            break;

                        case "br":
                            TranslateBr(writer, xChildElement, state);
                            break;

                        case "code":
                            TranslateCode(article, writer, xChildElement, state);
                            break;

                        case "font":
                            TranslateFont(article, writer, xChildElement, state);
                            break;

                        case "i":
                            TranslateI(article, writer, xChildElement, state);
                            break;

                        case "image":
                            TranslateImage(article, writer, xChildElement, state);
                            break;

                        case "inline":
                            TranslateInline(writer, xChildElement, state);
                            break;

                        case "important":
                            TranslateImportant(article, writer, xChildElement, state);
                            break;

                        case "link":
                            TranslateLink(article, writer, xChildElement, state);
                            break;

                        case "liste":
                            TranslateListe(article, writer, xChildElement, state);
                            break;

                        case "noteBasPage":
                            TranslateNoteBasPage(article, writer, xChildElement, state);
                            break;

                        case "paragraph":
                            TranslateParagraphe(article, writer, xChildElement, state);
                            break;

                        case "renvoi":
                            TranslateRenvoi(writer, xChildElement, state);
                            break;

                        case "signet":
                            TranslateSignet(writer, xChildElement, state);
                            break;

                        case "sub":
                            TranslateSub(article, writer, xChildElement, state);
                            break;

                        case "sup":
                            TranslateSup(article, writer, xChildElement, state);
                            break;

                        case "tableau":
                            TranslateTableau(article, writer, xChildElement, state);
                            break;

                        default:
                            throw new NotImplementedException(xChildElement.Name.ToString());
                        }
                        break;
                    }

                    case XmlNodeType.Text:
                        XText xChildText = xChildNode as XText;
                        writer.Write(EscapeChar(xChildText.Value));
                        break;

                    default:
                        throw new NotImplementedException(xChildNode.NodeType.ToString());
                    }
                }
            }
        }
Ejemplo n.º 9
0
 private static void TranslateFont(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
 {
     TranslateTexte(article, writer, xElement, state);
 }
Ejemplo n.º 10
0
        private static void TranslateTableau(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XElement info = xElement.XPathSelectElement("tableau/ligne/colonne[1]/image[@src='./images/100002010000002000000020F2813DC4.png']");

            if (info != null)
            {
                XElement xText = xElement.XPathSelectElement("tableau/ligne/colonne[2]");
                state.Stack.Push("tableau");
                state.Stack.Push("ligne");
                state.Stack.Push("colonne");
                writer.WriteLine(@"\begin{info}{}");
                TranslateZoneRedigee(article, writer, xElement, state);
                writer.WriteLine(@"\end{info}");
                state.Stack.Pop();
                state.Stack.Pop();
                state.Stack.Pop();
            }
            else
            {
                XAttribute             xBorder       = xElement.Attribute("border");
                bool                   hasBorder     = xBorder != null && xBorder.Value != "0";
                IEnumerable <XElement> xFirstLine    = xElement.XPathSelectElements("ligne[1]/colonne");
                IEnumerable <XElement> xLignes       = xElement.XPathSelectElements("ligne");
                string[]               formatColonne = new string[xFirstLine.Count()];
                string                 formatColonnes;

                int count = 0;
                state.Stack.Push("tableau");

                foreach (XElement xCell in xFirstLine)
                {
                    //                    formatColonne[count] = "m{3.5cm}";
                    formatColonne[count] = String.Format("p{{{0}\\textwidth}}", (0.92 / xFirstLine.Count()).ToString(CultureInfo.InvariantCulture));
                    count++;
                }

                if (hasBorder)
                {
                    formatColonnes = String.Format("|{0}|", String.Join("|", formatColonne));
                }
                else
                {
                    formatColonnes = String.Join(String.Empty, formatColonne);
                }

                writer.WriteLine(@"\begin{center}");
                writer.WriteLine(@"\begin{{longtable}}{{{0}}}", formatColonnes);

                if (hasBorder)
                {
                    writer.WriteLine(@"\hline");
                }

                XElement[] xLignesArray = xLignes.ToArray();
                for (int i = 0; i < xLignesArray.Length; ++i)
                {
                    XElement xLigne = xLignesArray[i];
                    IEnumerable <XElement> xColonnes = xLigne.XPathSelectElements("colonne");
                    bool firstCell = true;

                    foreach (XElement xCell in xColonnes)
                    {
                        if (!firstCell)
                        {
                            writer.Write("&");
                        }

                        TranslateTexte(article, writer, xCell, state);
                        firstCell = false;
                    }

                    if (i < xLignesArray.Length - 1)
                    {
                        writer.WriteLine(@"\\");
                    }

                    if (hasBorder)
                    {
                        writer.WriteLine(@"\hline");
                    }
                }

                if (hasBorder)
                {
                    writer.WriteLine(@"\hline");
                }
                writer.WriteLine(@"\end{longtable}");
                writer.WriteLine(@"\end{center}");
                writer.WriteLine();

                state.Stack.Pop();
            }
        }
Ejemplo n.º 11
0
        private static void TranslateImage(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XAttribute xAlign        = xElement.Attribute("align");
            XAttribute xSrc          = xElement.Attribute("src");
            XAttribute xLegende      = xElement.Attribute("legende");
            XAttribute xZoom         = xElement.Attribute("zoom");
            XAttribute xAlt          = xElement.Attribute("alt");
            XAttribute xHref         = xElement.Attribute("href");
            XAttribute xTitre        = xElement.Attribute("titre");
            string     align         = xAlign != null ? xAlign.Value : String.Empty;
            string     src           = xSrc != null ? xSrc.Value : String.Empty;
            string     scale         = "0.4";
            bool       includeFigure = true;

            // Modification de l'extension si c'est un gif
            if (src.ToLower().EndsWith(".gif"))
            {
                src = src.Substring(0, src.Length - ".gif".Length) + ".png";
            }

            if (article.Images != null)
            {
                ImageType image = article.Images.FirstOrDefault(x => x.Src == src);

                if (image != null)
                {
                    scale = image.Taille;
                }
            }

            state.Stack.Push("image");

            if (state.Stack.FirstOrDefault(x => x == "tableau") != null)
            {
                includeFigure = false;
            }

            //if (state.Stack.FirstOrDefault(x => x == "tableau") != null ||
            if (
                state.Stack.FirstOrDefault(x => x == "rich-imgtexte") != null ||
                state.Stack.FirstOrDefault(x => x == "paragraph") != null)
            {
                includeFigure = false;
                writer.Write(@"\includegraphics[scale={1}]{{\DVPGetImagePath/{0}}}", src, scale);
            }
            else
            {
                if (includeFigure)
                {
                    if (xLegende == null || String.IsNullOrEmpty(xLegende.Value))
                    {
                        writer.WriteLine(@"\begin{figure}[H]");
                    }
                    else
                    {
                        writer.WriteLine(@"\begin{figure}[H]");
                    }
                }

                writer.WriteLine(@"\center");

                writer.WriteLine(@"\includegraphics[scale={1}]{{\DVPGetImagePath/{0}}}", src, scale);
                if (xLegende != null && !String.IsNullOrEmpty(xLegende.Value))
                {
                    if (state.Stack.FirstOrDefault(x => x == "tableau") != null)
                    {
                        writer.WriteLine(@"\center{{{0}}}", EscapeChar(xLegende.Value));
                    }
                    else
                    {
                        if (xLegende.Value.StartsWith("figure", StringComparison.CurrentCultureIgnoreCase))
                        {
                            writer.WriteLine(@"\caption*{{{0}}}", EscapeChar(xLegende.Value));
                        }
                        else
                        {
                            writer.WriteLine(@"\caption{{{0}}}", EscapeChar(xLegende.Value));
                        }
                    }
                }

                if (includeFigure)
                {
                    writer.WriteLine(@"\end{figure}");
                }
                writer.WriteLine();
            }

            state.Stack.Pop();
        }
Ejemplo n.º 12
0
 public static Contenu Create(ArticleType article, XElement xRoot, ContenuContexteEnum contexte)
 {
     return(new Contenu(article, xRoot, contexte));
 }
Ejemplo n.º 13
0
        private static void TranslateSection(ArticleType article, TextWriter writer, XElement xElement, ContenuState state)
        {
            XElement               xTitle         = xElement.XPathSelectElement("title");
            XAttribute             xID            = xElement.Attribute("id");
            XAttribute             xNoNumber      = xElement.Attribute("noNumber");
            XAttribute             xSautDePagepdf = xElement.Attribute("sautDePagePdf");
            IEnumerable <XElement> xSections      = xElement.Elements("section");
            int    sectionDeep;
            string title = xTitle != null ? xTitle.Value : String.Empty;

            state.Stack.Push("section");
            state.Sections.Push(state.Sections.Pop() + 1);
            sectionDeep = state.Stack.Where(x => x == "section").Count();

            if (MustIncludeSection(state, article))
            {
                switch (sectionDeep)
                {
                case 1:
                    //writer.WriteLine(@"\begin{{multicols}}{{2}}[{0}]", !String.IsNullOrEmpty(title) ? String.Format(@"\subsection{{{0}}}", EscapeChar(title)) : String.Empty);
                    writer.WriteLine(@"\subsection{{{0}}}", EscapeChar(title));
                    break;

                case 2:
                    if (!String.IsNullOrEmpty(title))
                    {
                        writer.WriteLine(@"\subsubsection{{{0}}}", EscapeChar(title));
                    }
                    break;

                case 3:
                    if (!String.IsNullOrEmpty(title))
                    {
                        writer.WriteLine(@"\subsubsubsection{{{0}}}", EscapeChar(title));
                    }
                    break;

                case 4:
                    if (!String.IsNullOrEmpty(title))
                    {
                        writer.WriteLine(@"\paragraph{{{0}}}", EscapeChar(title));
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }

                IEnumerable <XNode> xNodes = xElement.Nodes();

                bool hasSectionChildren = xElement.Element("section") != null;

                if (hasSectionChildren)
                {
                    state.Sections.Push(0);
                }

                foreach (XNode xChildNode in xNodes)
                {
                    switch (xChildNode.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        XElement xChildElement = xChildNode as XElement;
                        switch (xChildElement.Name.ToString())
                        {
                        case "animation":
                            TranslateAnimation(writer, xChildElement, state);
                            break;

                        case "citation":
                            TranslateCitation(article, writer, xChildElement, state);
                            break;

                        case "code":
                            TranslateCode(article, writer, xChildElement, state);
                            break;

                        case "image":
                            TranslateImage(article, writer, xChildElement, state);
                            break;

                        case "imgtext":
                            TranslateImgText(article, writer, xChildElement, state);
                            break;

                        case "liste":
                            TranslateListe(article, writer, xChildElement, state);
                            break;

                        case "paragraph":
                            TranslateParagraphe(article, writer, xChildElement, state);
                            break;

                        case "rich-imgtext":
                            TranslateRichImgText(article, writer, xChildElement, state);
                            break;

                        case "section":
                            TranslateSection(article, writer, xChildElement, state);
                            break;

                        case "signet":
                            TranslateSignet(writer, xChildElement, state);
                            break;

                        case "tableau":
                            TranslateTableau(article, writer, xChildElement, state);
                            break;

                        case "title":
                            break;

                        default:
                            throw new NotImplementedException(xChildElement.Name.ToString());
                        }
                        break;
                    }

                    default:
                        throw new NotImplementedException(xChildNode.NodeType.ToString());
                    }
                }

                if (hasSectionChildren)
                {
                    state.Sections.Pop();
                }

                switch (sectionDeep)
                {
                case 1:
                    //writer.WriteLine(@"\end{multicols}");
                    writer.WriteLine();
                    break;

                case 2:
                case 3:
                case 4:
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            state.Stack.Pop();
        }
Ejemplo n.º 14
0
 private Contenu(ArticleType article, XElement xRoot, ContenuContexteEnum contexte)
 {
     _xRoot    = xRoot;
     _contexte = contexte;
     _article  = article;
 }