Introduction.
A simple perl script to parse a text file to produce raw and tidy HTML tabled code that renders with little or no editing when inserted into Wordpress's editor.
The process page is HERE - but please read all of this page, as the syntax is very important (but fairly simple).
Requirements.
A text editor.
Operation.
Copy a simple text file into the form window which gets parsed and a tidy HTML rendering will be produced, ready for insertion into Wordpress's editor. A 'preamble' can be added by solvers if required. Basic text colouring choices are available (contact me if more are required - see end of this page) and bold on/off features.
Instructions Section
Please ensure you read all of this page first to ensure correct usage (GIGO).
A text readable version of the code is here, released under the GPLv3 license
Syntax of 'draft'.
Note: There is NO verification made by the code that the text copied into the form is in the correct syntax - if it is not, garbage will result, guaranteed.
The file 'draft' is of this basic format:
Preamble (if required)
[Across/Down]
Clue number
[Clue*]
Solution
Answer
...
(*clues are optional)
All on separate lines without leading/trailing spaces etc. or blank lines (but the code does take care of some of this).
The Preamble
The preamble can be anything you wish to write about the crossword, and can include HTML tags for emphasis, links, colours etc.
If no preamble is required, just ensure the top line of the draft is 'Across'.
Due to the nature of the parser, paragraph breaks need to be specified with a single period ".", thus:
========================
This weeks crossword was very good.
I hope we get more of these.
.
Favourite clue was 24ac...
========================
This produces when processed:
This weeks crossword was very good.
I hope we get more of these.
Favourite clue was 24ac...
========================
Clues
You can select with CLUES or with NO CLUES on the process page (radio buttons). Ensure you set this option correctly, as garbage will result.
So, with clues included, and with a preamble:
========================
Preamble here
Across
1
clue
solution
comments
2
clue
solution
comments
Down
1
clue
solution
comments
3
clue
solution
comments
and so on ...
========================
'Across' and 'Down' section markers must be included and capitalised.
If NO clues are included, the file is thus (without a preamble also, to illustrate):
========================
Across
1
solution
comments
2
solution
comments
Down
1
solution
comments
3
solution
comments
and so on...
========================
More on comments:
If you wish to have line breaks within comments in table cells, use the pipe symbol '|' to break the line thus (borders shown to emphasis):
1.
ANSWER
ANS+W+ER
comment split with line break
so, this becomes (with no clues):
========================
1
ANSWER
ANS+W+ER|comment split with line break
...
========================
Another advantage is HTML tags can also be used (in the preamble/solution and/or comments lines) e.g. if you wish to emphasis a hidden word clue:
so:
========================
Across
1
SESAME
hidden: clas<b>SES AME</b>rican
========================
produces:
hidden: clasSES AMErican
========================
And also an html link (or image) pointing to an area of interest e.g. can be added as such:
========================
1
Links
How to <a href="http://www.w3schools.com/HTML/html_links.asp">HERE</a>
========================
produces:
1. Links How to HERE
========================
Examples.
Using a joke crossword I saw somewhere years ago:
1O
2P
3E
4N
2O
P
E
N
3O
P
E
N
4O
P
E
N
Across
Down
1.
Not closed
1.
Garden equipment?
2.
Upfront
2.
Vegetables?
3.
Free
3.
Relax?
4.
Uncork
4.
Farmyard animals?
so WITH clues and a preamble will be:
========================
Silly crossword this week
.
The clues are strange, especially the down clues with
their weak puns.
.
Hurry up next week's version.
Across
1
Not closed
OPEN
opposite of closed
2
Upfront
OPEN
honest, candid
3
Free
OPEN
free, as in an open tournament e.g. the 'open' in golf
4
Uncork
OPEN
i.e. open a bottle of wine
Down
1
Garden equipment?
OOOO
HOSE|<b>Oh dear!</b> a homophonic pun
2
Vegetables?
PPPP
PEAS|even worse !!
3
Relax?
EEEE
EASE|Argh!
4
Farmyard animals?
NNNN
HENS|<b>Enough!!!</b> best clue though!
========================
This produces the output:
exampleclues.html
With NO clues (remember to select correct radio button!):
========================
Silly crossword this week
.
The clues are strange, especially the down clues with
their weak puns.
.
Hurry up next week's version.
Across
1
OPEN
opposite of closed
2
OPEN
honest, candid
3
OPEN
free, as in an open tournament e.g. the 'open' in golf
4
OPEN
i.e. open a bottle of wine
Down
1
OOOO
HOSE|Oh dear! a homophonic pun
2
PPPP
PEAS|even worse !!
3
EEEE
EASE|Argh!
4
NNNN
HENS|Enough!!! best clue though!
========================
This produces the output:
examplenoclues.html
========================
Gotcha's
If the words 'Across' and/or 'Down' appear exactly as quoted on a single line all lonesome, the parser will produce garbage - ensure these two words are only used for the relevant solution sections.
--
There is another 'gotcha' that needs addressing. Sometimes one clue covers other clues, and these are referred to i.e.:
10 see 9
so here there will be no solution nor comments; but [a] place holder[s] still need to be supplied to ensure correct parsing of the draft when creating the HTML table, so use a dash in lieu of the normal clue/solution/comment thus:
(with clues)
10
see 9
-
-
(without clues)
10
see 9
-
and so on...
Multiple concatenated clue numbers (21,23,33,42 etc.) can be all appended on one line, but may need further editing in WordPress's editor, as the first table cell will be rather |w i d e'|.
Appendix
The above example texts can also be used to experiment with the process page. Remember, you can also use your browsers 'back' button to go back to the form and edit the input if the output is not what is required.
Once the output is produced, simply paste into Wordpress's editor.
By the way, please do not be scared to experiment - the script will and can only produce garbage if input is in the wrong format :)
created 23/10/2010
updated: 05/01/2011
comments: nick@ukfsn.org