"Fossies" - the Fresh Open Source Software Archive 
Member "cb2bib-2.0.1/src/c2b/texToHtml.h" (12 Feb 2021, 2940 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "texToHtml.h" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.0.0_vs_2.0.1.
1 /***************************************************************************
2 * Copyright (C) 2004-2021 by Pere Constans
3 * constans@molspaces.com
4 * cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
5 * See the LICENSE file that comes with this distribution.
6 ***************************************************************************/
7 #ifndef TEXTOHTML_H
8 #define TEXTOHTML_H
9
10 #include "texParser.h"
11
12 #include "coreBibParser.h"
13
14
15 /**
16 Minimalist TeX to HTML converter
17 */
18 class texToHtml : public texParser
19 {
20
21 public:
22 texToHtml();
23 inline ~texToHtml() {}
24
25 QString toHtml(const QString& tex);
26 void toHtml(const QString& tex, const QString& fn);
27
28
29 private:
30 QDir _current_dir;
31 QHash<QString, bibReference> _references;
32 QHash<QString, int> _cites;
33 QList<QRegExp> _tex_macro_names_rx;
34 QRegExp _extern_url_rx;
35 QRegExp _macro_arguments_rx;
36 QRegExp _named_extern_url_rx;
37 QRegExp _named_url_rx;
38 QRegExp _url_rx;
39 QString _bibtex_directory;
40 QString _html;
41 QString _html_filename;
42 QString _index;
43 QString _tex_macros;
44 QString _title;
45 bool _close_subsection;
46 bool _close_subsubsection;
47 bool _make_index;
48 bool _use_mathjax_rendering;
49 bool _use_relative_links;
50 coreBibParser _cbp;
51 int _index_anchors;
52 settings* _settingsP;
53 void citesToHtml(QString* html);
54 void extractCites(const QString& p);
55 void extractMacro(const QString& v);
56 void parseComment(const QString& p) override;
57 void parseElement(const QString& p, const QString& e, const QString& v) override;
58 void parseTextParagraph(const QString& p) override;
59 void referencesToHtml(QString* reference_list_html);
60 void retrieveReferences();
61
62 inline void urlToHtml(QString* str) const
63 {
64 str->replace(_named_url_rx, "<a href=\"\\1\">\\2</a>");
65 str->replace(_url_rx, "<a href=\"\\1\">\\1</a>\\2");
66 str->replace(_named_extern_url_rx, "<a href=\"\\1\" target=\"_blank\">\\2</a>");
67 str->replace(_extern_url_rx, "<a href=\"\\1\" target=\"_blank\">\\1</a>\\2");
68 }
69
70 inline QString toHtmlString(QString str, const bool do_macros = true) const
71 {
72 // Move LaTeX to Unicode
73 c2bUtils::bibToC2b(str);
74 // Encode some symbols to HTML for proper browser display
75 str.replace('<', "<");
76 str.replace('>', ">");
77 str.replace('%', "%");
78 if (!_use_mathjax_rendering)
79 {
80 str.replace(QRegExp("_\\{([^\\}]*)\\}"), "<sub>\\1</sub>");
81 str.replace(QRegExp("\\^\\{([^\\}]*)\\}"), "<sup>\\1</sup>");
82 }
83 // Insert $$ into LaTeX macros provided it can be reasonably assumed they are
84 // outside a match environment
85 if (do_macros)
86 for (int i = 0; i < _tex_macro_names_rx.count(); ++i)
87 str.replace(_tex_macro_names_rx.at(i), "$\\1$");
88 return str;
89 }
90 };
91
92 #endif