NAME

Text::Hatena - Perl extension for formatting text with Hatena Style.

SYNOPSIS

use Text::Hatena;

my $parser = Text::Hatena->new(
  permalink => 'http://www.example.com/entry/123',
);
$parser->parse($text);
my $html = $parser->html;

DESCRIPTION

Text::Hatena parses text with Hatena Style and generates html string. Hatena Style is a set of text syntax which is originally used in Hatena Diary (http://d.hatena.ne.jp/).

You can get html string from simple text with syntax like Wiki.

METHODS

Here are common methods of Text::Hatena.

new
$parser = Text::Hatena->new;
$parser = Text::Hatena->new(
  permalink => 'http://www.example.com/entry/123',
  ilevel => 1,
  invalidnode => [qw(h4 h5)],
  sectionanchor => '@',
);

creates an instance of Text::Hatena.

permalink is the uri of your document. It is used in H3 section anchor.

ilevel is the base indent level.

invalidnode is an array reference of invalid nodes. The node in the array will be skipped.

sectionanchor is the string of H3 section anchor.

parse
$parser->parse($text);

parses text and generates html.

html
$html = $parser->html;

returns html string generated.

Text::Hatena Syntax

Text::Hatena supports some simple markup language, which is similar to the Wiki format.

Paragraphs

Basically each line becomes a paragraph. If you want to force a newline in a paragraph, you can use a line break markup of HTML.

You can add footnotes by using double parentheses.

Hatena is in Tokyo((The biggest city in Japan)).

Text::Hatena treats a blank line as the end of a block. A blank line after a paragraph does not affect the output. Two blank lines are translated into a line break, three blank lines are translated into two line breaks and so on.

To stop generating paragraphs automatically, start a line with >< (greater-than sign and less-than sign). The first > (greater-than sign) will be omitted. If you end a line with ><, it will stop. The last < (less-than sign) will be omitted.

><div class="foo">A div block without paragraph.</div><

><form action="foo.cgi" method="put">
To insert a from, write as you see here.
<input type="text" name="a" />
<input type="submit" />
</form><
Headlines

To create a section headline, start a line with a star followed by an anchor, a star, some tags of categories and a section title. An anchor and tags are optional. If you omit an anchor, Text::Hatena generates it automatically.

*A line with a star becomes section headline
*sa*You can specify a string for anchor name
*[foo][bar]You can specify some tags of categories
*sa*[foo][bar]You can mix them

More stars mean deeper levels of headlines. You can use up to three stars for headlines.

**Start a line with two stars to create a 4th level headline
***Start a line with three stars to create a 5th level headline.
Lists and Tables

Text::Hatena supports ordered and unordered lists. Start every line with a minus (-) for unordered lists or a plus (+) for ordered ones. More marks mean deeper levels. You can show the end of the lists by a blank line.

-Start a line with minuses to create an unordered list item.

+Start a line with pluses to create an ordered list item.
++They can be nested.

Text::Hatena supports definition lists. Start every line with a colon followed by a term, a colon, and a description.

:term:description

You can create tables by using a simple syntax. Table rows have to start and end with a vertical bar (|). Separete every cell with a vertical bar (|). To turn cells into headers, begin them with a star.

|*header1|*header2|
|colum1|colum2|
Blockquotes

To make a blockquote, enclose line(s) with >> (double greater-than sign) and << (double less-than sign). Marks should be placed in separate lines; don't start quoting line(s) with >> or end them with <<. Blockquotes may be nested.

>>
To make a blockquote, enclose line(s) with >> (double greater-than sign)
and << (double less-than sign).
<<
Preformatted texts

To make a preformatted text, enclose line(s) with >| (a greater-than sign followed by a vertical bar) and |< (a vertical var followed by a less-than sign).

Every >| should be placed in separate lines; don't start preformatted line(s) with >|. But some preformatted texts may be closed by |< after the last lines without separating lines.

>|
To make a preformatted text, enclose line(s) with >|
(a greater-than sign followed by a vertical bar) and |<
(a vertical var followed by a less-than sign).
|<

This also works well.

>|
To make a preformatted text, enclose line(s) with >|
(a greater-than sign followed by a vertical bar) and |<
(a vertical var followed by a less-than sign).|<

To encode special characters into HTML entities, use >|| and ||< for >| and |<. The characters to be replaced are less-than signs (<), greater-than signs (>), double quotes ("), and ampersands (&).

>||
To encode special characters into HTML entities,
use >|| and ||< for >| and |<.
||<

SEE ALSO

http://d.hatena.ne.jp/ (Japanese)

AUTHOR

Junya Kondo, <jkondo@hatena.ne.jp> id:tociyuki, <http://d.hatena.ne.jp/tociyuki/>

COPYRIGHT AND LICENSE

Copyright (C) 2005 by Junya Kondo

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.