options) throws Exception {
37 | File f = new File(fileOrDir);
38 | File rootDir = f.isFile() ? f.getParentFile() : f;
39 | try {
40 | rootPath = _.unifyPath(rootDir);
41 | } catch (Exception e) {
42 | _.die("File not found: " + f);
43 | }
44 |
45 | analyzer = new Analyzer(options);
46 | _.msg("Loading and analyzing files");
47 | analyzer.analyze(f.getPath());
48 | analyzer.finish();
49 |
50 | generateHtml();
51 | analyzer.close();
52 | }
53 |
54 |
55 | private void generateHtml() {
56 | _.msg("\nGenerating HTML");
57 | makeOutputDir();
58 |
59 | linker = new Linker(rootPath, OUTPUT_DIR);
60 | linker.findLinks(analyzer);
61 |
62 | int rootLength = rootPath.length();
63 |
64 | int total = 0;
65 | for (String path : analyzer.getLoadedFiles()) {
66 | if (path.startsWith(rootPath)) {
67 | total++;
68 | }
69 | }
70 |
71 | _.msg("\nWriting HTML");
72 | Progress progress = new Progress(total, 50);
73 |
74 | for (String path : analyzer.getLoadedFiles()) {
75 | if (path.startsWith(rootPath)) {
76 | progress.tick();
77 | File destFile = _.joinPath(OUTPUT_DIR, path.substring(rootLength));
78 | destFile.getParentFile().mkdirs();
79 | String destPath = destFile.getAbsolutePath() + ".html";
80 | String html = markup(path);
81 | try {
82 | _.writeFile(destPath, html);
83 | } catch (Exception e) {
84 | _.msg("Failed to write: " + destPath);
85 | }
86 | }
87 | }
88 |
89 | _.msg("\nWrote " + analyzer.getLoadedFiles().size() + " files to " + OUTPUT_DIR);
90 | }
91 |
92 |
93 | @NotNull
94 | private String markup(String path) {
95 | String source;
96 |
97 | try {
98 | source = _.readFile(path);
99 | } catch (Exception e) {
100 | _.die("Failed to read file: " + path);
101 | return "";
102 | }
103 |
104 | List\n")
118 |
119 | .append("\n")
122 |
123 | .append("\n\n")
124 |
125 | .append("")
126 | .append(addLineNumbers(styledSource))
127 | .append("
")
128 |
129 | .append("