Logo coherent WaveBurst  
Library Reference Guide
Logo
StripMathJax.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 // Strip MathJax Tag from file
20 // MathJax javascript is used to convert tex formulae inside an html block
21 // to a figure to be displayed from www browser
22 // Since the brakets { } are special characters for texinfo, all
23 // brackets used in the tex formulae must be defined with the escape
24 // character @. To avoid to use the escape we use a workaround :
25 // each formula must be commented with "@c MJX " or "@c mjx "
26 // The command "makeinfo --html convert the info comment into a html comment"
27 // This macro strip the comment "<!-- <MJ> " and "-->" or "<!-- <mj> " and "-->"
28 
30 
31 void StripMathJax(TString idir="cwb") {
32 
34 
35  if(!idir.EndsWith("/")) idir+="/";
36 
37  vector<TString> fileList = TB.getFileListFromDir(idir, ".html");
38 
39  char cmd[1024];
40  for(int i=0;i<fileList.size();i++) {
41  TString tmpFile = fileList[i];
42  tmpFile.ReplaceAll(".html",".html.tmp");
43  //cout << fileList[i].Data() << endl;
44  //cout << tmpFile.Data() << endl;
45  sprintf(cmd,"mv %s %s",fileList[i].Data(),tmpFile.Data());
46  //cout << cmd << endl;
47  gSystem->Exec(cmd);
48  StripMathJaxTag(tmpFile,fileList[i]);
49  sprintf(cmd,"rm %s",tmpFile.Data());
50  //cout << cmd << endl;
51  gSystem->Exec(cmd);
52  }
53 
54  exit(0);
55 }
56 
58 
59  ifstream in;
60  in.open(ifile.Data(),ios::in);
61  if (!in.good()) {cout << "Error Opening File : " << ifile.Data() << endl;exit(1);}
62 
63  ofstream out;
64  out.open(ofile.Data(),ios::out);
65 
66  char str[2048];
67  while(true) {
68  in.getline(str,2048);
69  if (!in.good()) break;
70  //cout << str << endl;
71  TString line = str;
72  // remove MathJax html comment
73  if(line.BeginsWith("<!-- <MJ> ")) {
74  line.ReplaceAll("<!-- <MJ> ","");
75  line.ReplaceAll("-->","");
76  }
77  if(line.BeginsWith("<!-- <mj> ")) {
78  line.ReplaceAll("<!-- <mj> ","");
79  line.ReplaceAll("-->","");
80  }
81  out << line.Data() << endl;
82  }
83 
84  out.close();
85 
86  return;
87 }
88 
char ofile[1024]
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:5108
TString("c")
ofstream out
Definition: cwb_merge.C:214
CWB::Toolbox TB
i drho i
char str[1024]
void StripMathJaxTag(TString ifile, TString ofile)
Definition: StripMathJax.C:57
TFile * ifile
ifstream in
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
char cmd[1024]
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
char line[1024]
exit(0)
void StripMathJax(TString idir="cwb")
Definition: StripMathJax.C:31