Source-highlight Library
sourcehighlight.h
1//
2// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008
3//
4// Copyright: See COPYING file that comes with this distribution
5//
6
7#ifndef SOURCEHIGHLIGHT_H_
8#define SOURCEHIGHLIGHT_H_
9
10#include <string>
11#include <istream>
12#include <ostream>
13
14#include "textstyleformattercollection.h"
15
16namespace srchilite {
17
18class FormatterManager;
19class PreFormatter;
20class LangDefManager;
21class BufferedOutput;
22class LineNumGenerator;
23class DocGenerator;
24class CharTranslator;
25class HighlightEventListener;
26class CTagsManager;
27class CTagsFormatter;
28class LineRanges;
29class RegexRanges;
30
37 std::string outputLang;
38
44 std::string dataDir;
45
47 std::string backgroundColor;
48
50 std::string styleFile;
51
53 std::string styleCssFile;
54
56 std::string styleDefaultFile;
57
59 std::string linePrefix;
60
62 std::string rangeSeparator;
63
65 std::string title;
66
68 std::string inputLang;
69
71 std::string css;
72
74 std::string headerFileName;
75
77 std::string footerFileName;
78
81
83 std::string outputFileDir;
84
87
90
93
96
99
104
110
115
118
121
124
127
133
136
139
142
145
151 unsigned int lineNumberDigits;
152
155
158
161
164
169 unsigned int tabSpaces;
170
176
177public:
181 SourceHighlight(const std::string &outputLang = "html.outlang");
183
189 void initialize();
190
198 void highlight(const std::string &input, const std::string &output,
199 const std::string &inputLang);
200
209 void
210 highlight(std::istream &input, std::ostream &output,
211 const std::string &inputLang,
212 const std::string &inputFileName = "");
213
221 void checkLangDef(const std::string &langFile);
222
230 void checkOutLangDef(const std::string &langFile);
231
240 void printHighlightState(const std::string &langFile, std::ostream &os);
241
250 void printLangElems(const std::string &langFile, std::ostream &os);
251
257 const std::string createOutputFileName(const std::string &inputFile);
258
259 void setDataDir(const std::string &_datadir) {
260 dataDir = _datadir;
261 }
262
263 void setStyleFile(const std::string &_styleFile) {
264 styleFile = _styleFile;
265 }
266
267 void setStyleCssFile(const std::string &_styleFile) {
268 styleCssFile = _styleFile;
269 }
270
271 void setStyleDefaultFile(const std::string &_styleDefaultFile) {
272 styleDefaultFile = _styleDefaultFile;
273 }
274
275 void setTitle(const std::string &_title) {
276 title = _title;
277 }
278
279 void setInputLang(const std::string &_inputLang) {
280 inputLang = _inputLang;
281 }
282
283 void setCss(const std::string &_css) {
284 css = _css;
285 }
286
287 void setHeaderFileName(const std::string &h) {
288 headerFileName = h;
289 }
290
291 void setFooterFileName(const std::string &f) {
292 footerFileName = f;
293 }
294
295 void setOutputDir(const std::string &_outputDir) {
296 outputFileDir = _outputDir;
297 }
298
299 const TextStyleFormatterCollection &getFormatterCollection() const {
300 return formatterCollection;
301 }
302
303 void setOptimize(bool b = true) {
304 optimize = b;
305 }
306
307 void setGenerateLineNumbers(bool b = true) {
309 }
310
311 void setGenerateLineNumberRefs(bool b = true) {
313 }
314
315 void setLineNumberPad(char c) {
316 lineNumberPad = c;
317 }
318
319 void setLineNumberAnchorPrefix(const std::string &_prefix) {
320 lineNumberAnchorPrefix = _prefix;
321 }
322
323 void setLineNumberDigits(unsigned int d) {
325 }
326
327 void setGenerateEntireDoc(bool b = true) {
329 }
330
331 void setGenerateVersion(bool b = true) {
332 generateVersion = b;
333 }
334
335 void setCanUseStdOut(bool b = true) {
336 canUseStdOut = b;
337 }
338
339 void setBinaryOutput(bool b = true) {
340 binaryOutput = b;
341 }
342
343 void setHighlightEventListener(HighlightEventListener *l) {
345 }
346
347 void setRangeSeparator(const std::string &sep) {
348 rangeSeparator = sep;
349 }
350
351 DocGenerator *getDocGenerator() const {
352 return docGenerator;
353 }
354
355 DocGenerator *getNoDocGenerator() const {
356 return noDocGenerator;
357 }
358
359 LineRanges *getLineRanges() const {
360 return lineRanges;
361 }
362
363 void setLineRanges(LineRanges *lr) {
364 lineRanges = lr;
365 }
366
367 RegexRanges *getRegexRanges() const {
368 return regexRanges;
369 }
370
371 void setRegexRanges(RegexRanges *rr) {
372 regexRanges = rr;
373 }
374
375 void setCTagsManager(CTagsManager *m) {
376 ctagsManager = m;
377 }
378
379 void setTabSpaces(unsigned int i) {
380 tabSpaces = i;
381 }
382
388 const std::string &getOutputFileExtension() const {
389 return outputFileExtension;
390 }
391};
392
393}
394
395#endif /*SOURCEHIGHLIGHT_H_*/
The main class for writing into the output.
Definition: bufferedoutput.h:28
Formatter for information gathered from ctags.
Definition: ctagsformatter.h:50
Takes care of running ctags and to generate a CTagsFormmatter.
Definition: ctagsmanager.h:23
Given a DocTemplate it generates the start of the document and the end, using variables such as title...
Definition: docgenerator.h:40
Associates to an element name the corresponding formatter.
Definition: formattermanager.h:24
Base class for listeners of HighlightEvent.
Definition: highlighteventlistener.h:18
Handles langdef language definition files.
Definition: langdefmanager.h:25
Generates line numbers in the output.
Definition: linenumgenerator.h:19
Functionalities for detecting whether a line is in one of the stored line ranges (or in the context o...
Definition: lineranges.h:38
Preformats text to be generated.
Definition: preformatter.h:31
Stores possible separators implemented as regular expressions and provides functionalities to search ...
Definition: regexranges.h:22
The main class performing highlighting of an input file generating an output file.
Definition: sourcehighlight.h:35
std::string linePrefix
the prefix for all the output lines
Definition: sourcehighlight.h:59
bool binaryOutput
whether to open output files in binary mode (default false)
Definition: sourcehighlight.h:163
void checkLangDef(const std::string &langFile)
Only check the validity of the language definition file.
Definition: sourcehighlight.cpp:360
bool generateEntireDoc
whether to generate an entire document (default false)
Definition: sourcehighlight.h:154
char lineNumberPad
the line number padding char (default '0')
Definition: sourcehighlight.h:144
void initialize()
performs initialization of fields, if not already initialized.
Definition: sourcehighlight.cpp:82
bool generateVersion
whether to generate the program version in the output file (default=true)
Definition: sourcehighlight.h:157
bool optimize
Whether to optmize output (e.g., adiacent text parts belonging to the same element will be buffered a...
Definition: sourcehighlight.h:132
void printHighlightState(const std::string &langFile, std::ostream &os)
Prints the HighlightState corresponding to the language definition file.
Definition: sourcehighlight.cpp:376
CTagsManager * ctagsManager
the CTagsManager for creating CTagsFormatters
Definition: sourcehighlight.h:117
std::string backgroundColor
the background color
Definition: sourcehighlight.h:47
bool generateLineNumbers
whether to generate line numbers
Definition: sourcehighlight.h:135
std::string outputFileDir
the directory for output files
Definition: sourcehighlight.h:83
FormatterManager * formatterManager
the formatter manager
Definition: sourcehighlight.h:86
bool canUseStdOut
whether we can use stdout for generating the output (default true)
Definition: sourcehighlight.h:160
std::string rangeSeparator
the separator for ranges
Definition: sourcehighlight.h:62
std::string inputLang
the input lang for the output document
Definition: sourcehighlight.h:68
std::string lineNumberAnchorPrefix
the prefix for the line number anchors
Definition: sourcehighlight.h:141
void highlight(const std::string &input, const std::string &output, const std::string &inputLang)
Highlights the contents of the input file into the output file, using the specified inputLang definit...
Definition: sourcehighlight.cpp:182
LineNumGenerator * lineNumGenerator
the generator for line numbers
Definition: sourcehighlight.h:98
LangDefManager * langDefManager
for loading language definitions
Definition: sourcehighlight.h:95
void checkOutLangDef(const std::string &langFile)
Only check the validity of the out language definition file.
Definition: sourcehighlight.cpp:368
HighlightEventListener * highlightEventListener
The listener for highlight events.
Definition: sourcehighlight.h:114
DocGenerator * noDocGenerator
the generator of the start and end of the output document when NOT generating an entire document
Definition: sourcehighlight.h:109
std::string outputLang
the output language file name
Definition: sourcehighlight.h:37
unsigned int lineNumberDigits
the number of digits for line numbers (if not specified this is computed automatically according to t...
Definition: sourcehighlight.h:151
const std::string & getOutputFileExtension() const
Returns the file extension for the output file as specified in the output format definition file (ini...
Definition: sourcehighlight.h:388
bool generateLineNumberRefs
whether to generate line numbers with references
Definition: sourcehighlight.h:138
std::string styleFile
the style file
Definition: sourcehighlight.h:50
std::string footerFileName
the file name of the footer
Definition: sourcehighlight.h:77
void printLangElems(const std::string &langFile, std::ostream &os)
Prints the language elements corresponding to the language definition file.
Definition: sourcehighlight.cpp:384
std::string styleDefaultFile
the style defaults file
Definition: sourcehighlight.h:56
CTagsFormatter * ctagsFormatter
the CTagsFormatter for formatting references and anchors
Definition: sourcehighlight.h:120
std::string title
the title for the output document (defaults to the source file name)
Definition: sourcehighlight.h:65
LineRanges * lineRanges
the possible LineRanges (to check which lines should be printed)
Definition: sourcehighlight.h:123
std::string headerFileName
the file name of the header
Definition: sourcehighlight.h:74
std::string outputFileExtension
the file extension for output files
Definition: sourcehighlight.h:80
DocGenerator * docGenerator
the generator of the start and end of the output document
Definition: sourcehighlight.h:103
PreFormatter * preFormatter
the preformatter
Definition: sourcehighlight.h:89
void updateBufferedOutput(BufferedOutput *output)
Sets the specified buffered output to all the formatters.
Definition: sourcehighlight.cpp:394
TextStyleFormatterCollection formatterCollection
all the formatters that are created
Definition: sourcehighlight.h:92
std::string css
the value for the css
Definition: sourcehighlight.h:71
const std::string createOutputFileName(const std::string &inputFile)
Given the input file name creates an output file name.
Definition: sourcehighlight.cpp:281
unsigned int tabSpaces
If greater than 0 it means that tabs will be replaced by tabSpaces blank characters.
Definition: sourcehighlight.h:169
std::string dataDir
Path for several configuration files.
Definition: sourcehighlight.h:44
std::string styleCssFile
the css style file
Definition: sourcehighlight.h:53
RegexRanges * regexRanges
the possible RegexRanges (to check which lines should be printed)
Definition: sourcehighlight.h:126
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
std::list< TextStyleFormatter * > TextStyleFormatterCollection
Collection of TextStyleFormatter objects.
Definition: textstyleformattercollection.h:11