App::D...::Text(3pm)

πŸ“¦
version 8.0.1 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

🌈 App::DocKnot::Spin::Text 🌈

ok so bestie, this is the App::D...::Text(3pm) page, and the vibe is: it's App::DocKnot::Spin::Text, and its whole job is turning certain text formats into HTML. Yes, that specific. She's picky. πŸ’…


✨ NAME ✨

App::DocKnot::Spin::Text β€” Convert some particular text formats into HTML


πŸ¦‹ SYNOPSIS πŸ¦‹

use App::DocKnot::Spin::Text;

my $text = App::DocKnot::Spin::Text->new({style => '/styles/faq.css'});
$text->spin_text_file('/path/to/input', '/path/to/output.html');

πŸ“ REQUIREMENTS πŸ“

You need Perl 5.24 or later, plus these modules, all available from CPAN:

  • List::SomeUtils
  • Path::Tiny
  • Sort::Versions

πŸ’œ DESCRIPTION πŸ’œ

Okay so. This is another one of those odd breed of partially functional beasts β€” a text to HTML converter. πŸ¦„

Here's the honest tea: this is not truly possible in general. People do way too many varied things with their text for anyone to intuit document structure from it. So instead, this is a converter that will translate documents written the way I write. It may or may not work for you. The chances that it will work for you are directly proportional to how much your writing looks like mine. no cap.

App::DocKnot::Spin::Text understands digest separators β€” that's lines of exactly thirty hyphens, from the minimal digest standard β€” and it will treat a "Subject" header immediately after them as a section header. Beyond that, headings have to earn their spot as section headers by being one of:

  • outdented,
  • underlined on the following line, or
  • in all caps.

(Outdenting means the regular text is indented by a few spaces, but headers start in column 0 β€” or at least in a column farther to the left than the regular text. slay.)

Section headers that begin with numbers (with any number of periods) will be given <a id> tags containing that number prepended with "S". And here's the special-parsing moment ✨: any section with a header containing "contents" will have lines beginning with numbers turned into links to the appropriate <a id> tags in the same document. Use this to turn the table of contents of your minimal digest format FAQ into a real table of contents with links in the HTML version. obsessed.

Text with embedded whitespace more than a single space β€” or a couple of spaces at a sentence boundary or after a colon (and any text with literal tabs) β€” will be wrapped in <pre> tags. Same goes for any indented text that doesn't look like English paragraphs. URLs surrounded by <...> or <URL:...> will be turned into links. Other URLs will not be turned into links, and no effort whatsoever is made to turn random body text into links just because it happens to look like a link. πŸ™ˆ

Bullet lists and numbered lists get turned into the appropriate HTML structures. Some attempt is also made to recognize description lists, but App::DocKnot::Spin::Text was written by someone who writes a lot of technical documentation and therefore tends to prefer <pre> if unsure whether something is a description list or preformatted text. So description lists are only going to work if the description titles aren't indented relative to the surrounding text. iykyk.

Regular indented paragraphs, or paragraphs quoted with a consistent non-alphanumeric quote character, are recognized and turned into HTML block quotes. 🫢

It's worthwhile paying attention to the headers at the top of your document so that App::DocKnot::Spin::Text can get a few things right:

  • If you use RCS or CVS, put the RCS "Id" keyword as the first line of your document. It will be stripped out of the resulting output and App::DocKnot::Spin::Text will use it to determine the document revision.
  • This should be followed by regular message headers and news.answers subheaders if the document is an actual FAQ, and App::DocKnot::Spin::Text will use the "From" and "Subject" headers to figure out a title and headings to use.
  • As a special case, an HTML-title header in the subheaders will override any other title that App::DocKnot::Spin::Text thinks it should use for the document.

App::DocKnot::Spin::Text expects your document to have an <h1> title, and will add one from the Subject header if it doesn't find one. It will also add subheaders (class="subheading") giving the author (from the "From" header) and the last modified time and revision (from the RCS "Id" string) if there are no subheadings already. And if there's a subheading that contains RCS identifiers, it will be replaced by a nicely formatted heading generated from the RCS "Id" information in the HTML output. iconic.

Text marked as *bold* using the standard asterisk notation will be surrounded by <strong> tags β€” but only if the asterisks appear to be marking bold text rather than serving as wildcards or some other function. She's judging your asterisks, respectfully. πŸ’€

App::DocKnot::Spin::Text produces output (at least in the absence of any lurking bugs) which complies with the XHTML 1.0 Transitional standard. The input and output character set is assumed to be UTF-8.


πŸ‘‘ CLASS METHODS πŸ‘‘

new(ARGS)

Create a new App::DocKnot::Spin::Text object. Pro tip bestie: a single converter object can be reused to convert multiple files β€” provided that they have the same options. πŸŽ€

ARGS should be a hash reference with one or more of the following keys, and all of them are optional:

output

The path to the root of the output tree when converting a tree of files. This will be used to calculate relative path names for generating inter-page links using the provided "sitemap" argument. If "sitemap" is given, this option should also always be given.

modified

Add a last modified subheader to the document. This will always be done if an RCS "Id" string is present in the input. Otherwise, a last modified subheader based on the last modification date of the input file will be added if the input is a file and this option is set to a true value. The default is false.

sitemap

An App::DocKnot::Spin::Sitemap object. This will be used to create inter-page links. For inter-page links, the "output" argument must also be provided.

style

The URL to the style sheet to use. The appropriate HTML will be added to the <head> section of the resulting document. ✨

title

The HTML page title to use. This will also be used as the <h1> heading if the document doesn't contain one, but will not override a heading found in the document β€” only the HTML <title> attribute.


🌸 INSTANCE METHODS 🌸

spin_text_file([INPUT[, OUTPUT]])

Convert a single text file to HTML.

  • INPUT is the path of the input file
  • OUTPUT is the path of the output file

OUTPUT, or both INPUT and OUTPUT, may be omitted β€” in which case standard input or standard output, respectively, will be used.

Heads up bestie: if OUTPUT is omitted, App::DocKnot::Spin::Text will not be able to obtain sitemap information even if a sitemap was provided, and therefore will not add inter-page links. 😭

⭐ NOTES ⭐

I wrote this program because every other text to HTML converter that I've seen made specific assumptions about the document format and wanted you to write like it wanted you to write rather than like the way you wanted to write. This program instead wants you to write like I write, which from my perspective is an improvement. 😌

I don't claim that this is the be-all and end-all of text to HTML converters, as I don't believe such a beast exists. I do believe it's pretty close to being the be-all and end-all of text to HTML converters for text that I personally have written, since I've written into it a lot of knowledge of the sorts of text formatting conventions that I use. If you happen to use the same ones, you may be delighted with this module. If you don't, you'll probably be very frustrated with it. πŸ’€

In any case, I took to this project the perspective that whenever there was something this program couldn't handle, I wanted to make it smarter rather than change the input. I've mostly been successful at that, so far. πŸ¦‹


🧚 CAVEATS 🧚

This program attempts to intuit structure from an unstructured markup format. It therefore relies on a whole bunch of fussy heuristics, poorly-understood assumptions, and sheer blind luck. To fully document the boundary cases of this program would take more time and patience than I care to invest; see the source code if you're curious. This is not a predictable or easily documentable program. Instead, it attempts to do what I mean without bugging me about it.

There is therefore, at least currently, no way to control or adjust parameters in this program without editing it. I may someday add that, but I'm leery of it, since the code complexity would start increasing exponentially if I tried to let people tweak everything. I've given up on more than one text to HTML converter because it had more options than ls and expected you to try to figure out which ones should be used for a document yourself. πŸ™ˆ

English month names are used for the last modification dates, and the resulting HTML always declares that the document is in English. This could be made configurable if anyone wishes.


πŸ’– AUTHOR πŸ’–

Russ Allbery <rra@cpan.org>


Copyright 1999-2002, 2004-2005, 2008, 2010, 2013, 2021-2024 Russ Allbery <rra@cpan.org>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


πŸ”₯ SEE ALSO πŸ”₯

  • docknot(1)
  • App::DocKnot::Spin
  • App::DocKnot::Spin::Sitemap

This module is part of the App-DocKnot distribution. The current version of DocKnot is available from CPAN, or directly from its web site at <https://www.eyrie.org/~eagle/software/docknot/>. 🌐


ok periodt, that's the whole page bestie πŸ’… this rendering came from perl v5.40.1 and was dated 2026-01-16, and honestly? slay. go turn some text into HTML. 🫢✨

πŸ“¦ where this page comes from