Esempio n. 1
0
void
sectioning_html (int level, char *cmd)
{
  static int toc_ref_count = 0;
  int index;
  int old_no_indent;
  unsigned char *starting_pos, *ending_pos;
  char *temp, *toc_anchor = NULL;

  close_paragraph ();
  filling_enabled =  indented_fill = 0;
  old_no_indent = no_indent;
  no_indent = 1;

  /* level 0 (chapter) is <h2>, and we go down from there.  */
  add_html_block_elt_args ("<h%d class=\"%s\">", level + 2, cmd);

  /* If we are outside of any node, produce an anchor that
     the TOC could refer to.  */
  if (!current_node || !*current_node)
    {
      static const char a_name[] = "<a name=\"";

      starting_pos = output_paragraph + output_paragraph_offset;
      add_word_args ("%sTOC%d\">", a_name, toc_ref_count++);
      toc_anchor = substring (starting_pos + sizeof (a_name) - 1,
                              output_paragraph + output_paragraph_offset);
      /* This must be added after toc_anchor is extracted, since
         toc_anchor cannot include the closing </a>.  For details,
         see toc.c:toc_add_entry and toc.c:contents_update_html.

         Also, the anchor close must be output before the section name
         in case the name itself contains an anchor. */
      add_word ("</a>");
    }
  starting_pos = output_paragraph + output_paragraph_offset;

  if (macro_expansion_output_stream && !executing_string)
    append_to_expansion_output (input_text_offset + 1);

  get_rest_of_line (0, &temp);

  /* Use @settitle value if @top parameter is empty.  */
  if (STREQ (command, "top") && strlen(temp) == 0)
    temp = xstrdup (title ? title : "");

  index = search_sectioning (cmd);
  if (index < 0)
    {
      /* should never happen, but a poor guy, named Murphy ... */
      warning (_("Internal error (search_sectioning) \"%s\"!"), cmd);
      return;
    }

  /* Produce "X.Y" and add it to HTML output.  */
  {
    char *title_number = handle_enum_increment (level, index);
    if (strlen (title_number) > 0)
      add_word_args ("%s ", title_number);
  }

  /* add the section name to both HTML and macro-expanded output.  */
  if (macro_expansion_output_stream && !executing_string)
    {
      remember_itext (input_text, input_text_offset);
      me_execute_string (temp);
      write_region_to_macro_output ("\n", 0, 1);
    }
  else
    execute_string ("%s", temp);

  ending_pos = output_paragraph + output_paragraph_offset;

  /* Pluck ``X.Y SECTION-NAME'' from the output buffer and insert it
     into the TOC.  */
  if (section_alist[index].toc == TOC_YES)
    toc_add_entry (substring (starting_pos, ending_pos),
                   level, current_node, toc_anchor);

  free (temp);

  if (outstanding_node)
    outstanding_node = 0;

  add_word_args ("</h%d>", level + 2);
  close_paragraph();
  filling_enabled = 1;
  no_indent = old_no_indent;
}
Esempio n. 2
0
/* Output the footnotes.  We are at the end of the current node. */
void
output_pending_notes (void)
{
  FN *footnote = pending_notes;

  if (!pending_notes)
    return;

  if (html)
    {
      add_html_block_elt ("<div class=\"footnote\">\n<hr>\n");
      /* We add an anchor here so @printindex can refer to this point
         (as the node name) for entries defined in footnotes.  */
      if (!splitting)
        add_word ("<a name=\"texinfo-footnotes-in-document\"></a>");
      add_word_args ("<h4>%s</h4>", (char *) _("Footnotes"));
    }
  else
    switch (footnote_style)
      {
      case separate_node:
        {
          char *old_current_node = current_node;
          char *old_command = xstrdup (command);

          already_outputting_pending_notes++;
          execute_string ("%cnode %s-Footnotes,,,%s\n",
                          COMMAND_PREFIX, current_node, current_node);
          already_outputting_pending_notes--;
          current_node = old_current_node;
          free (command);
          command = old_command;
        }
      break;

      case end_node:
        close_paragraph ();
        in_fixed_width_font++;
        /* This string should be translated according to the
           @documentlanguage, not the current LANG.  We can't do that
           yet, so leave it in English.  */
        execute_string ("---------- Footnotes ----------\n\n");
        in_fixed_width_font--;
        break;
      }

  /* Handle the footnotes in reverse order. */
  {
    int save_in_fixed_width_font = in_fixed_width_font;
    FN **array = xmalloc ((footnote_count + 1) * sizeof (FN *));
    array[footnote_count] = NULL;

    while (--footnote_count > -1)
      {
        array[footnote_count] = footnote;
        footnote = footnote->next;
      }

    filling_enabled = 1;
    indented_fill = 1;
    in_fixed_width_font = 0;

    while ((footnote = array[++footnote_count]))
      {
        if (html)
          {
	    /* Make the text of every footnote begin a separate paragraph.  */
            add_html_block_elt ("<p class=\"footnote\"><small>");
            /* Make footnote number a link to its definition.  */
            add_word_args ("[<a name=\"fn-%d\" href=\"#fnd-%d\">%d</a>]",
			   footnote->number, footnote->number, footnote->number);
            add_word ("</small> ");
            already_outputting_pending_notes++;
            execute_string ("%s", footnote->note);
            already_outputting_pending_notes--;
            add_word ("</p>\n");
          }
        else
          {
            char *old_current_node = current_node;
            char *old_command = xstrdup (command);

            already_outputting_pending_notes++;
            execute_string ("%canchor{%s-Footnote-%d}(%s) %s",
                            COMMAND_PREFIX, current_node, footnote->number,
                            footnote->marker, footnote->note);
            already_outputting_pending_notes--;
            current_node = old_current_node;
            free (command);
            command = old_command;
          }

        close_paragraph ();
      }

    if (html)
      add_html_block_elt ("<hr></div>");
    close_paragraph ();
    free (array);

    in_fixed_width_font = save_in_fixed_width_font;
  }

  free_pending_notes ();
}
Esempio n. 3
0
/* Insert the text following input_text_offset up to the end of the line
   in a new, separate paragraph.  Directly underneath it, insert a
   line of WITH_CHAR, the same length of the inserted text. */
void
insert_and_underscore (int level, char *cmd)
{
  int i, len;
  int index;
  int old_no_indent;
  unsigned char *starting_pos, *ending_pos;
  char *temp;
  char with_char = scoring_characters[level];

  close_paragraph ();
  filling_enabled =  indented_fill = 0;
  old_no_indent = no_indent;
  no_indent = 1;

  if (macro_expansion_output_stream && !executing_string)
    append_to_expansion_output (input_text_offset + 1);

  get_rest_of_line (0, &temp);

  /* Use @settitle value if @top parameter is empty.  */
  if (STREQ (command, "top") && strlen(temp) == 0)
    temp = xstrdup (title ? title : "");

  starting_pos = output_paragraph + output_paragraph_offset;

  /* Poor man's cache for section title.  */
  if (strlen (last_sectioning_title))
    free (last_sectioning_title);
  last_sectioning_title = xstrdup (temp);

  index = search_sectioning (cmd);
  if (index < 0)
    {
      /* should never happen, but a poor guy, named Murphy ... */
      warning (_("Internal error (search_sectioning) `%s'!"), cmd);
      return;
    }

  /* This is a bit tricky: we must produce "X.Y SECTION-NAME" in the
     Info output and in TOC, but only SECTION-NAME in the macro-expanded
     output.  */

  /* Step 1: produce "X.Y" and add it to Info output.  */
  add_word_args ("%s ", handle_enum_increment (level, index));

  /* Step 2: add "SECTION-NAME" to both Info and macro-expanded output.  */
  if (macro_expansion_output_stream && !executing_string)
    {
      char *temp1 = xmalloc (2 + strlen (temp));
      sprintf (temp1, "%s\n", temp);
      remember_itext (input_text, input_text_offset);
      me_execute_string (temp1);
      free (temp1);
    }
  else
    execute_string ("%s\n", temp);

  /* Step 3: pluck "X.Y SECTION-NAME" from the output buffer and
     insert it into the TOC.  */
  ending_pos = output_paragraph + output_paragraph_offset;
  if (section_alist[index].toc == TOC_YES)
    toc_add_entry (substring (starting_pos, ending_pos - 1),
                   level, current_node, NULL);

  free (temp);

  len = (ending_pos - starting_pos) - 1;
  for (i = 0; i < len; i++)
    add_char (with_char);
  insert ('\n');
  close_paragraph ();
  filling_enabled = 1;
  no_indent = old_no_indent;
}