Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Add title tags to HTML #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

daxelrod
Copy link

Pod::PseudoPod::HTML now outputs <title> tags with the contents of =head0 when add_body_tags is on. We'll also throw in <head> tags absolutely free! :)

Here's a more specific description of the new behavior:

  • When add_body_tags is on, <head> is output after <html> and </head> is output before <body>.
  • When add_body_tags is on, and a =head0 command paragraph appears as the first piece of content, its text is added in <title> tags in the head. It still appears normally as an <h1> in the body.
  • When add_body_tags is on, and add_css_tags is also on, the <link> to the stylesheet appears in the head.

Even though I think all of this is nifty, here are a few reasons I could think of that you not want to pull from me (it's your call whether they're big deals or not):

  • I haven't tested what happens if add_css_tags is on, but add_body_tags is off. (If that is an invalid combination, the docs need an update).
  • I haven't tested what happens if the =head0 command paragraph is encountered, but isn't the first piece of content in the document. Pod::PseudoPod::Tutorial does say "The file should always start with a =head0" but I'm not sure whether this fails gracefully if the order is different.
  • The placement of blank lines in <head> and right after <body> is somewhat odd.

No matter what, thank you for publishing Modern Perl, which is what inspired me to do all of this in the first place! (Specifically, I wanted to make the generation of its HTML version even better.) Also, thank you for all of the other work you do, which has significantly improved my life as a programmer.

It reflects the current behavior where the head0 command paragraph
is not added as a title tag when add_body_tags is used.
Move output of html and body tags from start_Document() into emit()

We don't actually know at start_Document() time whether there will
be a =head0 command paragraph tag to make into a title tag.
Luckily, we *do* know this by the first time emit() is called,
because, as the tutorial says, "The file should always start with
a =head0".

This commit ammounts to a no-op change.
We now output the html tag in start_Document, but the body tag
in emit. This will make adding a title tag in the correct place
easier.

This also has the side effect of moving the link element for css
above the body tag.
After <html>, output <head>.
Before <body>, output </head>.
The text in a =head0 command paragraph is now saved into a
'title_text' hash element in our parser object.

This change does not affect our output at all.
A slight change in approach, in order to get ordering of output
correct.

The logic for outputting the title, closing head, and beginning
body have now moved into a new method begin_body_if_necessary().

Both emit() and end_head0() now call this method.

We now use a flag 'in_html_head' rather than 'body_tags_emitted'
for consistency with other in_* flags.

Note that we do everything but actually output the title tag at
this point.

Also that because of how emit already works, there is now always
a blank line before </head> in the output. This is the only
externally-visible change.
We now actually output a title tag with the contents of
the =head0 command paragraph, if one exists.
Add a new test for a document with body tags and css turned on,
where the document additionally has a =head0 command paragraph,
which creates a <title> tag.
This does not otherwise change code or output.
@daxelrod
Copy link
Author

  • If add_css_tags is on, but add_body_tags is off, no stylesheet <link> tag is generated. This behavior is not a regression, the same is true in your version.
  • If =head0 is encountered, but is not the first piece of content in the document, everything works normally, except that no title tags are generated. Multiple =head0 in the document don't break anything either (and the first one at the beginning of the document, if any, becomes the title).

@daxelrod
Copy link
Author

I noticed it's been a little while since I sent this pull request.

Is there anything you'd like me to do to improve it, or are you not interested in this feature?

If you've been too busy to have a look at it, that's fine too. :)

@chromatic
Copy link
Collaborator

That all sounds reasonable. Would you mind rebasing against the current trunk?

@chromatic chromatic closed this Aug 9, 2011
@chromatic chromatic reopened this Aug 9, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants