User:Alien333/poemise
(Documentation for poemise.js.)
This is a tentative to automate most of the repetitive tasks of poetry proofreading that do not necessitate human intervention.
Poemize proper
[edit]Unwrapping
[edit]Puts lines < 3 characters at the end of the preceding line for punctuation, and lines starting by a lowercase for hard wrap (removes single eol hyphens).
Patterns
[edit]In EBNF, and by growing priority:
pattern = ""
| ( digit | "." | "[" any "]" ) pattern (* a digit means that many :'s, a "." a blank line and "[" any "]" is for something else at the beginning *)
| "!" number (* multiple-digit indent *)
| ( ";" | "'") number (* number*01-. or number*0-. *)
| pattern "," pattern (* separating two sub-patterns *)
| number "*" pattern (* pattern repeated number times *)
| pattern "-" pattern; (* "," with higher priority *)
where
digit = 0-9
number = digit+
Use
[edit]Applies an indent pattern given with *[pattern].
If no pattern is given, it will resort to the last pattern given (stored in a cookie). When there is no cookie, it resorts to the pattern "0". If you do not want to reuse, use just *, without anything after, to erase the cookie and reset the pattern to "0".
You can start at a specific index in your indent pattern with /[number].
If not given, it looks at where the pattern was cut on the preceding page (stored in a cookie), though it doesn't take it if it's from the same page. If it doesn't have that, it takes 0. To forcefully reset it, put just /, alone.
The zone to be poemised is assumed to start at the beginning and to end at EOF.
The start can be put somewhere else with + and the end with -.
When an edge (start/end) is not limited, it will try to fill in with the *, the /, and some additional wizardry (see #Edge divination for details).
For a last page of a poem, $ keeps it from adding an |end=.
+, -, $, *, /, parsed in that order, should be beginning of line (* and / absorb until EOL).
A - often means that a poem is interrupted mid-page, and so some code must be inserted (notably <section>s) to separate it from the next poem. Instead of having to copypaste it, you can define it with triple parentheses, (((...))), possibly across multiple lines, although the first of the first three parentheses must be on beginning of line. It will be saved in a cookie and reused whenever there is a -. To reset it, just set it empty, like so: ((())).
I am aware that my effort to compress this can lead to hard to read things, such as +$*2*56!10;'4, but eh, not going to be saved in page history.
Empty lines are by default ignored, add " " (one space) to them (which will be removed) to keep them from being collapsing (useful for irregular stanza breaks, that don't follow a pattern).
Edge divination
[edit]For start, will look at the (/ index - 1)th item of the pattern (wrapping around), put stanza if it's . and follow else.
For end, will look at the (final index+1)th item of the pattern (wrapping around), if it's . then put stanza else follow.
if it detects a larger blank at the bottom of this page or at the top of the next one than is usual for this index, then puts no end, else stanza, and if it isn't a . put follow. "larger" is but a word, and the ratio past which we consider it "larger" is open to discussion. Current code uses 1.8. (This detection involves requesting and analysing a few images, so it can take up to one or two seconds, but I think it is still worth it, as else you'd have to open the next page). (disabled as too slow, need to think more about this)
There is an ongoing issue with how {{ppoem}} interacts with {{di}}, which often results in situations like this:
This script also includes, though it's a bit unorthodox, a way to clear this. Namely, when a) previewing b) in Page: namespace, if c) there is a line which is broken up, add an {{em}} to the end of the line with a di (or increment it if there's already one), and then, auto-preview.
And then, if the conditions are still met, well, rinse and repeat. Highly recommended along with User:Alien333/cmbb's fast preview, which makes smooth what else can result in slightly trippy situations, where the script repeatedly previews seconds apart.
Endshift & startshift
[edit]Just a quicker way to shift the ends and starts of ppoem, in this order: none → follow → stanza → none.