Jump to content

User:Johantheghost/Cite

From Wikipedia, the free encyclopedia

wp-refconvert.pl

[edit]

I've written a perl helper script to automate the process of converting {{ref}}-style references to <ref>-style. It works on Linux, but should be usable on any system where you can execute a perl script.

The script: User:Johantheghost/wp-refconvert.pl

Usage:

  1. Edit the article
  2. Save your article text in a file (eg. article.txt)
  3. Run this command: wp-refconvert article.txt
  4. Paste the contents of the file article-new.txt into the edit buffer
  5. Preview and check the changes before saving; check that Unicode characters (eg. em dash, accents, etc.) are still intact

What it does:

  • Scans the article for all {{ref}}, {{ref_label}}, {{ref_num}}, {{note}}, and {{note_label}} tags.
  • Checks that all tags refer to the correct notes.
  • Converts {{ref}}, {{ref_label}}, and {{ref_num}} to <ref>text</ref>, where text is taken from the appropriate {{note}} / {{note_label}}.
  • Replaces the {{note}}s with <references/>.

Assumptions:

  • All the {{ref}}s and {{note}}s are consistent.
  • All the {{note}}s are in a single block, numbered consecutively, with one {{note}} and possibly multiple {{note_label}}s per line.

Notes:

  • The script attempts to handle Unicode correctly, and should do as long as your perl system does. BUT make sure that when you cut-and-paste the text in and out of the edit buffer that the text doesn't get wrecked — Windows seems to take pleasure in doing this. Bottom line, check before comitting the edit. Make sure em dashes etc. are still OK.
  • The script attempts to output an error message if it finds any inconsistency; if you get a mismatch message, the script thinks that the {{ref}}s and {{note}}s don't match. This is quite possible, due to the lack of checking in {{ref}} / {{note}}. Check them carefully.

Error messages:

can't open foo.txt
obvious.
can't create foo-new.txt
can't create the output file.
unknown reference style {{ref-xxx|foo}}
don't understand the reference tag.
note mismatch- ref 3=foo; note=bla
the third reference in the article was called foo, but the third note in the note list was called bla.
note number mismatch- seq = 4, explicit = 5
a {{note_label|foo|5|a}} tag was found in line 4 in the note list (the number should match the position in the list).
unknown note style {{note-xxx|foo}}
don't understand the note tag.
note mismatch- no ref 4 (foo)
note 4, named foo, was found, but there is no fourth reference.
ref mismatch- no ref 4 (foo)
reference 4, named foo, was found on pass 2, but not pass 1 (should never happen).