File: cadabra2html.cc

package info (click to toggle)
cadabra2 2.4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 78,732 kB
  • sloc: ansic: 133,450; cpp: 92,064; python: 1,530; javascript: 203; sh: 184; xml: 182; objc: 53; makefile: 51
file content (56 lines) | stat: -rw-r--r-- 1,347 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <fstream>
#include <iostream>
#include "DataCell.hh"

int main(int argc, char **argv)
	{
	if(argc<3) {
		std::cerr << "Usage: cadabra2html [--segment] [cadabra notebook] [html file]\n\n";
		std::cerr << "Convert a Cadabra v2 notebook to an HTML segment or standalone HTML file.\n"
		          << "If the HTML file name is not given, output goes to standard out.\n";
		return -1;
		}

	std::string cdb_file, html_file;
	bool segment_only=false;
	bool strip_code=false;
	int n=1;
	while(n<argc) {
		if(std::string(argv[n])=="--segment")
			segment_only=true;
		else if(std::string(argv[n])=="--strip-code")
			strip_code=true;
		else if(cdb_file=="")
			cdb_file=argv[n];
		else
			html_file=argv[n];
		++n;
		}
	std::cerr << "stripping code: " << strip_code << std::endl;

	auto from=cdb_file.find_last_of("/");
	++from;
	auto to  =cdb_file.find_last_of(".");
	std::string t=cdb_file.substr(from, to-from);
	t[0]=toupper(t[0]);
	std::string title="Cadabra manual: "+t;

	std::ifstream file(cdb_file);
	std::string content, line;
	while(std::getline(file, line))
		content+=line;

	cadabra::DTree doc;
	JSON_deserialise(content, doc);
	std::string html = export_as_HTML(doc, segment_only, strip_code, title);

	if(html_file!="") {
		std::ofstream htmlfile(html_file);
		htmlfile << html;
		}
	else {
		std::cout << html;
		}

	return 0;
	}