When I ask for a "printer-friendly version" of a book, all the titles come out looking the same, they are marked:
h1 id="3" name="3" class="book-h1"

When I look at the code for function "book_print" in the book.module, it looks as if there is a variable which is supposed to change depending on the depth in the book - the variable is called $depth. But as far as I can see it is defined as "1" and never changes.

I can't find this marked as a bug, but it seems to me to be one. Excuse me if I have missed something.

CommentFileSizeAuthor
#4 book_16.patch1.67 KBkilles@www.drop.org

Comments

joel_guesclin’s picture

Here is a solution for this which seems to work:

In functions book_print and book_print_recurse change the line:

      $output .= "<h1 id=\"$node->nid\" name=\"$node->nid\" class=\"book-h$depth\">$node->title</h1>";

so that it looks like this:

      $output .= "<h$depth id=\"$node->nid\" name=\"$node->nid\" >$node->title</h$depth>";

This gets rid of the class book-h1 which is not referenced in the print.css

Then, in book_print make sure that the call to book_print_recurse shows:

      $output .= book_print_recurse($id, $depth + 1);

Correct the definition of book_print_recurse to read:

      function book_print_recurse($parent = "", $depth) {

Then you might want to play with the misc/print.css but I'm still having trouble understanding that.

moshe weitzman’s picture

I can confirm that book.module is still outputting this non-ideal markup in HEAD. See book_print()

killes@www.drop.org’s picture

Assigned: Unassigned » killes@www.drop.org

Here is a patch that also takes care to no increase the depth over 6. The patch is untested but run through php -l.

killes@www.drop.org’s picture

StatusFileSize
new1.67 KB

And here'S the patch...

dries’s picture

Not sure. A lot of book pages use h2 and h3 headers.

killes@www.drop.org’s picture

IMNSHO they shouldn't. If you need substructures that qualify for h2 or h3 you should create subpages. Long pages aren't good to read on a screen.

Steven’s picture

The book has to do a trade-off between the amount of clicks required to reach a topic and the amount of information on a page. There are many cases where h2 and h3 usage is valid.

Steven’s picture

The book has to do a trade-off between the amount of clicks required to reach a topic and the amount of information on a page. There are many cases where h2 and h3 usage is valid.

Steven’s picture

It should be possible to check which h's are used in a book page, and renumber them.

Eg. if we are at level 3 in the book (<h3>), and the body uses <h2> and <h4>, we renumber those to <h4> and <h5>.

dries’s picture

Not going to commit this patch as is. It needs more thought.

clairem’s picture

I'm glad to see that this patch is still marked as active, beacuse I want to suggest an alternative way of developing the same idea -- which at its core is about differentiating the difft levels of a book.

First I should say that I agree with Steven's point that use of h2 and h3 can sometimes be valid in book pages, and I would add that possibly h4 h5 and h6 may be valid as well. We may all have our preferences, but site maintainers juggling their options may make their choices in circumstances which developers have not envisaged. Renumbering hn tags could break pages: a h3 tag in a book page at depth4 would be renumbered as h7. Not good.

So, instead of renumbering the headings, why not use the depth to wrap each book page in a div with an appropriate class, like this:

<div class="depth0">
  <h1>Animals</h1>
  wibble
  </div>
<div class="depth1">
 <h1>Mammals</h1>
  flurble
</div>
<div class="depth2">
  <h1>Primates</h1>
  blurble
</div>
etc ...

Then print.css could set the indentation for depth, as follows:

.depth0 {padding-left: 0);
.depth 1 {padding-left: 1em;}
etc...

Site managers could modify print.css to suit their needs, without ever having to tweak the Drupal code ... and without their hn tags being modified

puregin’s picture

Please see also the related discussion on

http://drupal.org/node/1898

I'm completely in support of clairem's idea to wrap sections in <div> tags.

However, at the risk of repeating myself to excess - any use of H1, H2, ... H6 inside of a book page is a sign of something not right. These should never appear. Having them present implies:

  • It will be impossible for others to add or re-arrange sections unless they have edit permissions for a page.
  • Individual authors can hijack the apparent (presentational) structure of a book by arbitrarily beginning new chapters, for example
  • There is no guarantee of coherence (hierarchy) in the presentation of the book
  • The structure of the document is not accessible to the navigational elements presented by Drupal - sections will disappear from the book navigation view, forward/up/next links, etc.

If you feel the urge to include them in your book page, one or more of the following is probably true:

  • Your page is too long. If readers need to scroll through a long page, they will probably need the navigational clues that headings provide - but they will in all cases be better served by having the page divided into true subsections via child nodes.
  • You are trying to present some kind of list. Try using <dl>, <dt>, <dd> instead
  • You are trying to achieve visual impact. Visual impact is OK, though it's often not done well. If you must, do it with style (pun intended)
  • Your page is essentially just a container for subsections - try pushing content up into the parent or down into children and eliminate the page entirely.
puregin’s picture

Please see also the related discussion on

http://drupal.org/node/1898

I'm completely in support of clairem's idea to wrap sections in <div> tags.

However, at the risk of repeating myself to excess - any use of H1, H2, ... H6 inside of a book page is a sign of something not right. These should never appear. Having them present implies:

  • It will be impossible for others to add or re-arrange sections unless they have edit permissions for a page.
  • Individual authors can hijack the apparent (presentational) structure of a book by arbitrarily beginning new chapters, for example
  • There is no guarantee of coherence (hierarchy) in the presentation of the book
  • The structure of the document is not accessible to the navigational elements presented by Drupal - sections will disappear from the book navigation view, forward/up/next links, etc.

If you feel the urge to include them in your book page, one or more of the following is probably true:

  • Your page is too long. If readers need to scroll through a long page, they will probably need the navigational clues that headings provide - but they will in all cases be better served by having the page divided into true subsections via child nodes.
  • You are trying to present some kind of list. Try using <dl>, <dt>, <dd> instead
  • You are trying to achieve visual impact. Visual impact is OK, though it's often not done well. If you must, do it with style (pun intended)
  • Your page is essentially just a container for subsections - try pushing content up into the parent or down into children and eliminate the page entirely.
puregin’s picture

This issue is fixed with the patch for http://drupal.org/node/1482, together with the print.css stylesheet patch provided in http://drupal.org/node/1898.

puregin’s picture

Marking this as fixed now that the patch for http://drupal.org/node/1482 has been committed.

Anonymous’s picture

RockyRoad’s picture

Title: Book title formatting the same for all levels of the book » Book title formatting the same for all levels of the book (printer-friendly version, drupal 6.x)
Version: » 6.12

Hi,

The book module has probably changed significantly since last comment here.

But the problem is still there IMHO.
I use a simple way to write css (for drupal 6x book), which conciliates both approaches (use book outline vs. use node contents headings).
For me, book writers would rather concentrate on their subject than on the undocumented prefered practices of modules maintainers.

Here's a simplified part of it:

...
div.section-1 h3,
div.section-2 h2,
div.section-3 h1.book-heading {
font-size: 1.6em;
}

div.section-1 h4,
div.section-2 h3,
div.section-3 h2,
div.section-4 h1.book-heading {
font-size: 1.2em;
}
...

I hope these "two cents" can help.

But one thing I don't understand is why the html exported book takes his stylesheet in the misc/ directory.
I would like to see a default stylesheet provided by the book module, and a user setting to override it.
But I didn't had a look in book.module sources yet.

Best regards,