1 | package org.expeditee.io;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.expeditee.gui.Frame;
|
---|
7 | import org.expeditee.items.Item;
|
---|
8 | import org.expeditee.items.ItemUtils;
|
---|
9 | import org.expeditee.items.Text;
|
---|
10 |
|
---|
11 | public class TEXWriter extends DefaultTreeWriter {
|
---|
12 |
|
---|
13 | // may be needed for sectioning commands
|
---|
14 | private Text _title = null;
|
---|
15 |
|
---|
16 | @Override
|
---|
17 | protected void initialise(Frame start) throws IOException {
|
---|
18 | _format = ".tex";
|
---|
19 | super.initialise(start);
|
---|
20 | }
|
---|
21 |
|
---|
22 | protected void writeTitle(Text title, List<Item> items) throws IOException {
|
---|
23 | _title = title;
|
---|
24 |
|
---|
25 | Text text = ItemUtils.FindTag(items, "@TexSection");
|
---|
26 |
|
---|
27 | if (text != null) {
|
---|
28 | String first = text.getFirstLine();
|
---|
29 | int ind = first.indexOf(":");
|
---|
30 |
|
---|
31 | if (ind > 0) {
|
---|
32 | String command = first.substring(ind + 1).trim().toLowerCase();
|
---|
33 |
|
---|
34 | _writer.write("\\" + command + "{");
|
---|
35 |
|
---|
36 | List<String> titleLines = _title.getText();
|
---|
37 | for (int i = 0; i < titleLines.size() - 1; i++) {
|
---|
38 | _writer.write(titleLines.get(i));
|
---|
39 | _writer.write(ItemWriter.NEW_LINE);
|
---|
40 | }
|
---|
41 |
|
---|
42 | _writer.write(titleLines.get(titleLines.size() - 1));
|
---|
43 |
|
---|
44 | _writer.write("}" + ItemWriter.NEW_LINE);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | protected void writeStartLink(Item linker) throws IOException {
|
---|
51 | // only output text items
|
---|
52 | if (!(linker instanceof Text))
|
---|
53 | return;
|
---|
54 |
|
---|
55 | Text text = (Text) linker;
|
---|
56 | List<String> toWrite = text.getText();
|
---|
57 |
|
---|
58 | String first = toWrite.get(0);
|
---|
59 | int ind = first.indexOf(":");
|
---|
60 |
|
---|
61 | if (ind > 0) {
|
---|
62 | String tag = first.substring(0, ind);
|
---|
63 | _writer.write("\\" + tag + "{" + ItemWriter.NEW_LINE);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | protected void writeEndLink(Item linker) throws IOException {
|
---|
69 | // only output text items
|
---|
70 | if (!(linker instanceof Text))
|
---|
71 | return;
|
---|
72 |
|
---|
73 | Text text = (Text) linker;
|
---|
74 | List<String> toWrite = text.getText();
|
---|
75 |
|
---|
76 | String first = toWrite.get(0);
|
---|
77 | int ind = first.indexOf(":");
|
---|
78 |
|
---|
79 | if (ind > 0) {
|
---|
80 | _writer.write("}" + ItemWriter.NEW_LINE);
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | protected void writeText(Text text) throws IOException {
|
---|
87 | for (String s : text.getText()) {
|
---|
88 | _writer.write(s);
|
---|
89 | _writer.write(ItemWriter.NEW_LINE);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Override
|
---|
94 | protected void writeAnnotationText(Text text) throws IOException {
|
---|
95 |
|
---|
96 | }
|
---|
97 | }
|
---|