Home
Categories
Dictionary
Download
Project Details
Changes Log
What Links Here
How To
Syntax
FAQ
License

DocGenerator API: sentences



To add a sentence, you can either use[1]
There are equivalent methods using a ParagraphElement parent, for example: DocGeneratorAPI.addSentence(ParagraphElementParent, String)
: For example:
  DocGeneratorAPI api = new DocGeneratorAPI();
  api.createModel();
  api.setOutputDirectory(<the wiki directory>);

  // create an article
  XMLArticle article = api.createArticle("the first article");
      
  // add a sentence
  api.addSentence(article, "the regular sentence");      

  • A sentence has only one style (for example the whole sentence use a bold or regular font). If you want to mix several styles, you must add several sentences (see combining sentences for more information)
  • If you want to add new lines or tabulations in the middle of a sentence, you must add a break or a tab because new lines an tabulations in the html source are not directly. supported in html. However, some methods in the API allows to automatically convert them (see converting new lines and tabulations for more information)

Combining sentences


Of course, you can combine sentences, new lines, and break. For example, the following code will create this content:

This is a bold text in red
and some text on a new line.

      DocGeneratorAPI api = new DocGeneratorAPI();
      api.createModel();
      api.setOutputDirectory(<the wiki directory>);

      // create an article
      XMLArticle article = api.createArticle("the first article");
      
      // add the text on the first line
      api.addSentence(article, "This is a ");
      
      SentenceStyle style = SentenceStyle.createTypeStyle(FontType.BOLD);
      api.addSentence(article, "bold", style);
      
      api.addSentence(article, " text in ");
      
      style = SentenceStyle.createColorStyle("red");
      XMLTextStyle textStyle = api.addTextStyle(article, style);  
      api.addSentence(textStyle, "red");
      
      api.addBreak(article);
      // add the text on the second line
      api.addSentence(article, "and some text on a new line.");      

Converting new lines and tabulations

If you want to add new lines or tabulations in the middle of a sentence, you must add a break because new lines in the html source does not produce line break or tabulations. However several methods automatically convert new lines in the text to line breaks or tabulations.

For example: All these methods will correctly handle new lines and tabulations ( \n and \t).

For example:
   DocGeneratorAPI api = new DocGeneratorAPI();
   api.createModel();
   api.setOutputDirectory(<the wiki directory>);

   // create an article
   XMLArticle article = api.createArticle("the first article");
      
   // add some text on two lines
   api.addMultilineSentence(article, "This is a text on the first line\nand on the second line");
   // add some tabulated text
   api.addMultilineSentence(article, "\tThis is a text after a tab");      

Notes

  1. ^ There are equivalent methods using a ParagraphElement parent, for example: DocGeneratorAPI.addSentence(ParagraphElementParent, String)

See also


Categories: api

docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.