Trichome

Content deleted Content added
Mortense (talk | contribs)
m →‎Command line tools: Is proper noun.
Mortense (talk | contribs)
m →‎GNU Emacs: Is a proper noun [2].
Line 167: Line 167:
There are a couple of [[Emacs]] major modes available for editing Wikipedia articles:
There are a couple of [[Emacs]] major modes available for editing Wikipedia articles:


* [[Wikipedia:wikipedia-mode.el|wikipedia-mode.el]] is a simple major mode that mostly provides syntax highlighting for wikipedia markup.
* [[Wikipedia:wikipedia-mode.el|wikipedia-mode.el]] is a simple major mode that mostly provides syntax highlighting for Wikipedia markup.
* [http://gna.org/projects/wikipedia-el/ wikipedia.el] is a much more advanced major mode which provides [[WYSIWYG]] editing of wikipedia articles. Note, however, that it is developed using the current [[Concurrent Versions System|CVS]] version of GNU Emacs, may not be compatible with older versions, and has been effectively discontinued because it's not being actively maintained. Also, the mode was in the alpha stage of development when it was orphaned, so use it at your own risk.
* [http://gna.org/projects/wikipedia-el/ wikipedia.el] is a much more advanced major mode which provides [[WYSIWYG]] editing of Wikipedia articles. Note, however, that it is developed using the current [[Concurrent Versions System|CVS]] version of GNU Emacs, may not be compatible with older versions, and has been effectively discontinued because it's not being actively maintained. Also, the mode was in the alpha stage of development when it was orphaned, so use it at your own risk.


Since Wikipedia articles [[Wikipedia:don't use line breaks|don't use line breaks]], you may want to install [http://homepage1.nifty.com/bmonkey/emacs/elisp/screen-lines.el screen-lines.el], which redefines movement commands to work in terms of screen lines as opposed to text lines, or install [http://www.emacswiki.org/elisp/longlines.el longlines.el], which implements "word wrap" functionality for Emacs (<code>longlines.el</code> is now part of GNU Emacs). Installation instructions are [[Wikipedia:Wikipedia-mode.el#Installing longlines-mode|here]].
Since Wikipedia articles [[Wikipedia:don't use line breaks|don't use line breaks]], you may want to install [http://homepage1.nifty.com/bmonkey/emacs/elisp/screen-lines.el screen-lines.el], which redefines movement commands to work in terms of screen lines as opposed to text lines, or install [http://www.emacswiki.org/elisp/longlines.el longlines.el], which implements "word wrap" functionality for Emacs (<code>longlines.el</code> is now part of GNU Emacs). Installation instructions are [[Wikipedia:Wikipedia-mode.el#Installing longlines-mode|here]].

Revision as of 12:36, 23 October 2010

It is often convenient to edit Wikipedia articles using a full-fledged text editor, instead of the standard text area of a web browser. Text editors provide facilities that are very useful for writing articles (especially long articles), such as spell checking, search and replace, macros, and syntax highlighting. They also provide a quick and easy way of saving a local backup copy of an article, possibly for future offline editing.

This article contains pointers for adapting several external and in-browser text editors to editing Wikipedia articles.

How to open articles in your text editor

Manual method

A "manual" way of editing in an external GUI text editor is to use copy and paste.

  1. Start editing the article as normally in browser (click the Edit tab of a wiki page, or use the keyboard shortcut Shift+Alt+e )
  2. Select the entire contents of the browser text area (as with Ctrl-A or ⌘A), then copy-paste it to a new external editor window
  3. Perform the editing
  4. Select the editor window contents, then copy and paste back to the browser text area.

Be careful not to mangle any special characters.

For a given software combination, there may be more efficient methods available:

Mozilla and Mozilla Firefox

If you are using the Mozilla web browser, it is possible to configure an external editor for editing text areas, including the Wikipedia edit area. This then avoids the need to copy and paste the article text between browser and editor. Several solutions exist:

  • MozEx. The official package does not support editing UTF-8-encoded documents and does not install properly on Mozilla Firefox. However, the development version does not have these problems. A quick MozEx tutorial is available.
  • ViewSourceWith provides similar functionality vis-a-vis the text editing.
  • Editus Externus. Similar to the others, but the editor blocks the browser, so it is not possible to check other articles while writing.
  • TextArea Sputnik, supports nonblocking editing and different encodings in an external editor. (You may see question marks in an edit textbox unrelated to the edits you are making (for example, the Unicode grapheme and other glyphs at the bottom), but your edits won't destroy the characters.)
  • It's All Text!, supports nonblocking editing and UTF-8 encoding.
  • Vimperator, has a shortcut in its insert mode that allows external text editing.

With all these solutions, once you are done editing, you need to save in your editor, then click into the browser's text area and it will be updated. You can then hit Preview. If you want to continue editing after the preview, hit Back in your browser, then work in your editor. Alternatively, you can hit Preview before you start editing for the first time, then work in your editor, save, preview, edit some more, save, preview etc., without the need for hitting Back in between.

Use It's All Text! to invoke an external editor

When It's All Text! plugin has been installed, a little blue edit button will appear at the bottom right corner of the text area. Just click the button to open the contents of the text area in your editor.

However, before you can use It's All Text!, you need to specify the path to your editor in the Preferences dialog box. The Preferences dialog opens automatically when you use It's All Text! for the first time, but you can open it manually as follows: Right click in the text area to open context menu; select "It's All Text" → "Preferences".

If your editor requires some other command line options in addition to the filename, use a shell script (.bat file) to call your editor, and specify path to that script instead of calling your editor directly. In addition, you can add filename extension for wiki file type in Preferences dialog, in case your editor uses file type specific configuration.

Once the above is done, you can edit any text area in your editor by clicking at the Edit button at the lower-right corner of the text area. Alternatively, you can right-click on the text area. From the "It's All Text" menu, you can choose which filename extension to use for editing. Next time you use the blue edit button, the extension will be the one you used last time.

After editing, just save the file from your editor. The contents will be automatically copied to the text area in Firefox. To indicate this, the text area turns yellow briefly.

A temporary file is created for editing and it will be removed at the end. So if you want to preserve a text file for later editing, you can change the filename and/or save the file to another directory.

Using Vim or another console editor

Some macros may work under Vim, but not under gVim for some reason (e.g., the macro to format text paragraphs). Or you just want to use Vim within an X terminal as you used to do, instead of using gVim. To invoke Vim within an X terminal window, you can write a shell script (see below) to invoke an X terminal and to run the vim command within that X terminal, or generally your preferred editor. Assume that the filename of this script is wiki.edit.vim, and that you put the script in the directory /home_dir/bin/ so that the path of the script would be /home_dir/bin/wiki.edit.vim Put the above path in the Preferences box (instead of /usr/bin/gvim) of It's All Text. It should work. Note that /home_dir/ is the complete path to your home directory from the root (/) directory; don't use ~/ (tilde) instead of /home_dir/; it won't work. The listing of the script wiki.edit.vim is given below:

#! /bin/sh
# $Id$
# vql, Thu, 27 Sep 2007, 17:56:09 EDT
#
# To pop up an X terminal (xterm) and run vim command within this
# terminal window.
# This script is intended to be invoked by the Firefox addon It's
# All Text for editing wiki pages
#
# The arguments for xterm are the same as those used to open up
# X terminals in laptop io2. See ~/manuals/laptop.io2.fc3.html,
# Section on xfce.
# For gray background: (NOT NEEDED, since the X terminal would be
# closed down after quitting the wiki file); the \ is for
# continuation to the next line:
#
# -bg gray \
#
# For font size:
# -fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 \
#
# For the sidebar:
# -sb
#
# For the size of the window (80 columns, 39 lines, right justified)
# -geometry 80x39+800 \
#
# For executing vim on the file being the first argument of the script
# -e /usr/bin/vim $argv[1]
#
# Exit codes:
# 0 = no problem
#
# Updated for generic Bourne shell by Eeera 2008-03-27
/usr/bin/xterm \
-sb \
-fn -misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1 \
-geometry 80x39+800 \
-e /usr/bin/vim "$1"

You can delete one or more xterm options used in the above script such as -sb, -fn, -geometry, etc., if you don't need them. For example, the option -bg was already deleted, as explained in the comment block of the script. Enjoy editing wiki pages! If you do not like the look and feel of the standard xterm console, you could also open another terminal emulator of your choice. This might be an option, if you already have a terminal emulator you like with a saved profile. You would need to comment out the last 5 lines of the above script and you could replace it with something like this (example given for a gnome-terminal):

/usr/bin/gnome-terminal \
-x /usr/bin/vim "$1"
Using Vim on Mac OS X

To get It's All Text to work nicely with Vim on the Mac, you will need Macvim. Unpack the .tbz file and drag MacVim.app to your Applications folder. MacVim also comes with a script called mvim. You will need to tell It's All Text to use this script and not MacVim.app. You can put this script anywhere (like a MyScripts folder in your Applications folder), it will find MacVim.

External editor feature

Starting with MediaWiki Version 1.5, the software allows you to edit any resource using any external tool. See Help:External editors for details.

Text browsers

elinks

The text-only browser elinks also provides a function to edit text areas. The Key combination Ctrl-T calls an external editor, e.g. Vim. This allows also to use syntax highlighting, edit functions, spelling corrections and saving local copies.

w3m

w3m opens an external editor for textareas by default.

Lynx

Lynx allows editing a textarea with an external editor by typing Ctrl-X and e when the cursor is in the textarea. In addition, it accepts a user-definable key-binding (normally not bound) to invoke the external editor. Some packagers may assign the user-definable binding in lynx's configuration file.

Command line tools

There are also command line tools that allow you to download articles, edit them using your favorite text editor, and upload the edited articles back into Wikipedia (or into any MediaWiki server). This bypasses the need for a web browser. These are (at least):

  • mvs, a Perl program available from CPAN. There's more information at Meta:WWW::Mediawiki::Client. Unfortunately, mvs uses the name of the local file as the title of the page for the wiki remote server. If you need title pages in UTF-8 for Russian, Japanese or Arabic for example, you won't be able to upload such files. It seems that Mediawiki::Client as well as Perl libraries are not enough advanced in the management of UTF-8 characters to be fully operational, even if your terminal and shell are correctly set for UTF-8. But see Debian bug reports.
  • Meta:pywikipedia is an extensive library and set of utilities for doing innumerable things with wikipedia. It can also do something as simple as editing Wikipedia pages. It has some ways to avoid the wrong transmission of titles in UTF-8, for example it allows to incorporate the name of the title within the file itself and to use another command line tool. The local filename could then be written in simple ASCII. Here is an example of a file, named locally 'foo.wiki', using pagefromfile.py (from Meta:pywikipedia):
{{-start-}}'''Демография'', или наука о народонаселении, изучает численность, состав, размещение и движение населения. 
{{-stop-}}

{{-start-}}'''人口学'''はヒトの人口の科学的研究をいい、主としてその大きさ、構造 2そしてその成長発展を研究対象とする。
{{-stop-}}

{{-start-}}'''Demography''' is the scientific study of human populations primarily with respect to their size, their structure and their development
{{-stop-}}

{{-start-}}'''الديمغرافية''': علم يتناول دراسة المجتمعات البشرية من حيث حجومها و بناها و تطورها و خصائصها العامة و لا سيما من النواحي الكمية.
{{-stop-}}

In the above example, the command line to upload the four pages in one submission (the 'start' and 'stop' markups drive successively the four different pages Демография, 人口学, Demography and الديمغرافية) is:

  python pagefromfile.py -file:foo.wiki

WikipediaFS

Users of POSIX-compliant operating systems like Linux or Mac OS X also can use the virtual filesystem Wikipedia filesystem based on Python and FUSE. It allows the user to treat articles of any Mediawiki-based implementation like real files.

This software (version 0.3) was not easy to install since it required the installation of several other items of software. If you are a Firefox and Vim user, a much simpler solution would be to use It's All Text and gVim to edit wiki pages.

Emacs support for the WikipediaFS is provided by wikipediafs.el.

How to set up specific editors for Wikipedia editing

Eclipse plug-in

The Wikipedia Editor plugin Eclipse Wikipedia Editor is available for Eclipse (cross-platform) with an automatically updating outline of the article. It has many features which are very helpful for editing wikipedia. It also downloads articles directly from Wikipedia and has highlighting.

GNU Emacs

There are a couple of Emacs major modes available for editing Wikipedia articles:

  • wikipedia-mode.el is a simple major mode that mostly provides syntax highlighting for Wikipedia markup.
  • wikipedia.el is a much more advanced major mode which provides WYSIWYG editing of Wikipedia articles. Note, however, that it is developed using the current CVS version of GNU Emacs, may not be compatible with older versions, and has been effectively discontinued because it's not being actively maintained. Also, the mode was in the alpha stage of development when it was orphaned, so use it at your own risk.

Since Wikipedia articles don't use line breaks, you may want to install screen-lines.el, which redefines movement commands to work in terms of screen lines as opposed to text lines, or install longlines.el, which implements "word wrap" functionality for Emacs (longlines.el is now part of GNU Emacs). Installation instructions are here.

wikipediafs.el can be used along with one of the aforementioned major modes, when using the virtual Wikipedia filesystem.

jEdit

For jEdit (Java-supporting OSes) there is a plugin available at http://www.djini.de/software/mwjed/ . Apart from providing syntax highlighting for wikipedia markup, it can communicate directly with the Wikipedia website using the HttpClient component from the Jakarta Project.

Kate/KWrite

For Kate (for GNU/Linux KDE desktop), rules for syntax highlighting are provided by the XML file on Wikipedia Commons kate-highlighting. It recognizes HTML tags and entities, wiki control characters, templates, variables, keywords, links, section titles, tables and <nowiki> sections.

To install this template, copy it to your home directory of KDE ~/.kde/share/apps/katepart/syntax/ for per user settings or a global settings:

  • Mostly, put it on $(PREFIX)/share/apps/katepart/syntax/.
  • on Ubuntu Linux ,use /usr/share/kde4/apps/katepart/syntax/.
  • on OpenSUSE-Linux for instance PREFIX=/opt/kde3/.

There's also an import tool : Settings → Configure Kate → Highlighting → Download.

NoteTab

A Clip Library plugin for the NoteTab (Windows) text editor contains some functions to automate Wiki markup.

SubEthaEdit

A syntax highlighting mode is available for SubEthaEdit (Mac OS X) as well. After downloading the mode bundle, drop it in /Library/Application Support/SubEthaEdit/Modes/ (system-wide) or ~/Library/Application Support/SubEthaEdit/Modes/ (user-specific). You may need to create the final two directories by hand. The mode will be automatically selected for files with a .wiki or .wikipedia extension.

TextMate

A "MediaWiki" bundle is available in the TextMate bundle subversion repository. To learn how to load this bundle, see the TextMate manual page about installing more bundles, or view this shell script that downloads and installs it. [1] The bundle for now (8 August 2006) only does syntax highlighting, but the ability to fetch and post articles is coming soon.

Vedit

Wiki Tools for VEDIT contains syntax highlighting, keyboard configuration, User and Tools menus and several macros for inserting and editing wiki tags and for some more complex operations such as add/delete/copy/paste columns in a wiki table. Installation instructions included, as well as instructions for configuring It's All Text! for Vedit.

Vim

To make Vim support the MediaWiki markup used on Wikipedia (basically syntax highlighting), save the following lines to "~/.vim/syntax/Wikipedia.vim" or "vimfiles\syntax\Wikipedia.vim". If any of the directories above don't exist you may create them (the Unix/Linux command is mkdir).

" Taken from
" http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim

" Wikipedia syntax file for Vim
" Published on Wikipedia in 2003-04 and declared authorless.
" 
" Based on the HTML syntax file. Probably too closely based, in fact.
" There may well be name collisions everywhere, but ignorance is bliss,
" so they say.
"
" To do: plug-in support for downloading and uploading to the server.

if !exists("main_syntax")
  if version < 600
    syntax clear
  elseif exists("b:current_syntax")
    finish
  endif
  let main_syntax = "html"
endif

syntax case ignore
if v:version >= 700
  syntax spell toplevel
endif

" Mark illegal characters
sy match htmlError "[<>&]"

" Tags
sy region  htmlString   contained start=+"+                        end=+"+ contains=htmlSpecialChar,@htmlPreproc
sy region  htmlString   contained start=+'+                        end=+'+ contains=htmlSpecialChar,@htmlPreproc
sy match   htmlValue    contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1         contains=@htmlPreproc
sy region  htmlEndTag             start=+</+                       end=+>+ contains=htmlTagN,htmlTagError
sy region  htmlTag                start=+<[^/]+                    end=+>+ contains=htmlTagN,htmlString,htmlArg,htmlValue,htmlTagError,htmlEvent,htmlCssDefinition,@htmlPreproc,@htmlArgCluster
sy match   htmlTagN     contained +<\s*[-a-zA-Z0-9]\++hs=s+1               contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
sy match   htmlTagN     contained +</\s*[-a-zA-Z0-9]\++hs=s+2              contains=htmlTagName,htmlSpecialTagName,@htmlTagNameCluster
sy match   htmlTagError contained "[^>]<"ms=s+1

" Allowed HTML tag names
sy keyword htmlTagName contained big blockquote br caption center cite code
sy keyword htmlTagName contained dd del div dl dt font hr ins li
sy keyword htmlTagName contained ol p pre rb rp rt ruby s small span strike sub
sy keyword htmlTagName contained sup table td th tr tt ul var
sy match   htmlTagName contained "\<\(b\|i\|u\|h[1-6]\|em\|strong\)\>"
" Allowed Wiki tag names
sy keyword htmlTagName contained math nowiki references source syntaxhighlight

" Allowed arg names
sy keyword htmlArg contained align lang dir width height nowrap bgcolor clear
sy keyword htmlArg contained noshade cite datetime size face color type start
sy keyword htmlArg contained value compact summary border frame rules
sy keyword htmlArg contained cellspacing cellpadding valign char charoff
sy keyword htmlArg contained colgroup col span abbr axis headers scope rowspan
sy keyword htmlArg contained colspan id class name style title

" Special characters
sy match htmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};"

" Comments
sy region htmlComment                start=+<!+                end=+>+     contains=htmlCommentPart,htmlCommentError
sy match  htmlCommentError contained "[^><!]"
sy region htmlCommentPart  contained start=+--+                end=+--\s*+ contains=@htmlPreProc
sy region htmlComment                start=+<!DOCTYPE+ keepend end=+>+

if !exists("html_no_rendering")
  sy cluster htmlTop contains=@Spell,htmlTag,htmlEndTag,htmlSpecialChar,htmlPreProc,htmlComment,htmlLink,@htmlPreproc

  sy region htmlBold                          start="<b\>"      end="</b>"me=e-4      contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
  sy region htmlBold                          start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlBoldUnderline,htmlBoldItalic
  sy region htmlBoldUnderline       contained start="<u\>"      end="</u>"me=e-4      contains=@htmlTop,htmlBoldUnderlineItalic
  sy region htmlBoldItalic          contained start="<i\>"      end="</i>"me=e-4      contains=@htmlTop,htmlBoldItalicUnderline
  sy region htmlBoldItalic          contained start="<em\>"     end="</em>"me=e-5     contains=@htmlTop,htmlBoldItalicUnderline
  sy region htmlBoldUnderlineItalic contained start="<i\>"      end="</i>"me=e-4      contains=@htmlTop
  sy region htmlBoldUnderlineItalic contained start="<em\>"     end="</em>"me=e-5     contains=@htmlTop
  sy region htmlBoldItalicUnderline contained start="<u\>"      end="</u>"me=e-4      contains=@htmlTop,htmlBoldUnderlineItalic

  sy region htmlUnderline                     start="<u\>"      end="</u>"me=e-4      contains=@htmlTop,htmlUnderlineBold,htmlUnderlineItalic
  sy region htmlUnderlineBold       contained start="<b\>"      end="</b>"me=e-4      contains=@htmlTop,htmlUnderlineBoldItalic
  sy region htmlUnderlineBold       contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlUnderlineBoldItalic
  sy region htmlUnderlineItalic     contained start="<i\>"      end="</i>"me=e-4      contains=@htmlTop,htmlUnderlineItalicBold
  sy region htmlUnderlineItalic     contained start="<em\>"     end="</em>"me=e-5     contains=@htmlTop,htmlUnderlineItalicBold
  sy region htmlUnderlineItalicBold contained start="<b\>"      end="</b>"me=e-4      contains=@htmlTop
  sy region htmlUnderlineItalicBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop
  sy region htmlUnderlineBoldItalic contained start="<i\>"      end="</i>"me=e-4      contains=@htmlTop
  sy region htmlUnderlineBoldItalic contained start="<em\>"     end="</em>"me=e-5     contains=@htmlTop

  sy region htmlItalic                        start="<i\>"      end="</i>"me=e-4      contains=@htmlTop,htmlItalicBold,htmlItalicUnderline
  sy region htmlItalic                        start="<em\>"     end="</em>"me=e-5     contains=@htmlTop
  sy region htmlItalicBold          contained start="<b\>"      end="</b>"me=e-4      contains=@htmlTop,htmlItalicBoldUnderline
  sy region htmlItalicBold          contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop,htmlItalicBoldUnderline
  sy region htmlItalicBoldUnderline contained start="<u\>"      end="</u>"me=e-4      contains=@htmlTop
  sy region htmlItalicUnderline     contained start="<u\>"      end="</u>"me=e-4      contains=@htmlTop,htmlItalicUnderlineBold
  sy region htmlItalicUnderlineBold contained start="<b\>"      end="</b>"me=e-4      contains=@htmlTop
  sy region htmlItalicUnderlineBold contained start="<strong\>" end="</strong>"me=e-9 contains=@htmlTop

  sy region htmlH1    start="<h1\>"    end="</h1>"me=e-5    contains=@htmlTop
  sy region htmlH2    start="<h2\>"    end="</h2>"me=e-5    contains=@htmlTop
  sy region htmlH3    start="<h3\>"    end="</h3>"me=e-5    contains=@htmlTop
  sy region htmlH4    start="<h4\>"    end="</h4>"me=e-5    contains=@htmlTop
  sy region htmlH5    start="<h5\>"    end="</h5>"me=e-5    contains=@htmlTop
  sy region htmlH6    start="<h6\>"    end="</h6>"me=e-5    contains=@htmlTop
endif


" No htmlTop and wikiPre inside HTML preformatted areas, because
" Wikipedia renders everything in there literally (HTML tags and
" entities, too): <pre> tags work as the combination of <nowiki> and
" the standard HTML <pre> tag: the content will preformatted, and it
" will not be parsed, but shown as in the wikitext source.
"
" With wikiPre, indented lines would be rendered differently from
" unindented lines.
sy match htmlPreTag       /<pre>/         contains=htmlTag
sy match htmlPreEndTag    /<\/pre>/       contains=htmlEndTag
sy match wikiNowikiTag    /<nowiki>/      contains=htmlTag
sy match wikiNowikiEndTag /<\/nowiki>/    contains=htmlEndTag
sy match wikiSourceTag    /<source\s\+[^>]\+>/ contains=htmlTag
sy match wikiSourceEndTag /<\/source>/    contains=htmlEndTag
sy match wikiSyntaxHLTag    /<syntaxhighlight\s\+[^>]\+>/ contains=htmlTag
sy match wikiSyntaxHLEndTag /<\/syntaxhighlight>/    contains=htmlEndTag

" Note: Cannot use 'start="<pre>"rs=e', so still have the <pre> tag
" highlighted correctly via separate sy-match. Unfortunately, this will
" also highlight <pre> tags inside the preformatted region. 
sy region htmlPre    start="<pre>"                 end="<\/pre>"me=e-6    contains=htmlPreTag
sy region wikiNowiki start="<nowiki>"              end="<\/nowiki>"me=e-9 contains=wikiNowikiTag
sy region wikiSource start="<source\s\+[^>]\+>"         keepend end="<\/source>"me=e-9 contains=wikiSourceTag
sy region wikiSyntaxHL start="<syntaxhighlight\s\+[^>]\+>" keepend end="<\/syntaxhighlight>"me=e-18 contains=wikiSyntaxHLTag

sy include @TeX syntax/tex.vim
sy region wikiTeX matchgroup=htmlTag start="<math>" end="<\/math>"  contains=@TeX,wikiNowiki,wikiNowikiEndTag
sy region wikiRef matchgroup=htmlTag start="<ref>"  end="<\/ref>"   contains=wikiNowiki,wikiNowikiEndTag

sy cluster wikiTop contains=@Spell,wikiLink,wikiNowiki,wikiNowikiEndTag

sy region wikiItalic        start=+'\@<!'''\@!+ end=+''+    oneline contains=@wikiTop,wikiItalicBold
sy region wikiBold          start=+'''+         end=+'''+   oneline contains=@wikiTop,wikiBoldItalic
sy region wikiBoldAndItalic start=+'''''+       end=+'''''+ oneline contains=@wikiTop

sy region wikiBoldItalic contained start=+'\@<!'''\@!+ end=+''+  oneline contains=@wikiTop
sy region wikiItalicBold contained start=+'''+         end=+'''+ oneline contains=@wikiTop

sy region wikiH1 start="^="      end="="      oneline contains=@wikiTop
sy region wikiH2 start="^=="     end="=="     oneline contains=@wikiTop
sy region wikiH3 start="^==="    end="==="    oneline contains=@wikiTop
sy region wikiH4 start="^===="   end="===="   oneline contains=@wikiTop
sy region wikiH5 start="^====="  end="====="  oneline contains=@wikiTop
sy region wikiH6 start="^======" end="======" oneline contains=@wikiTop

sy region wikiLink start="\[\[" end="\]\]\(s\|'s\|es\|ing\|\)" oneline contains=wikiLink,wikiNowiki,wikiNowikiEndTag

sy region wikiLink start="\[http:"   end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag
sy region wikiLink start="\[https:"  end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag
sy region wikiLink start="\[ftp:"    end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag
sy region wikiLink start="\[gopher:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag
sy region wikiLink start="\[news:"   end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag
sy region wikiLink start="\[mailto:" end="\]" oneline contains=wikiNowiki,wikiNowikiEndTag

sy region wikiTemplate start="{{" end="}}" contains=wikiNowiki,wikiNowikiEndTag

sy match wikiParaFormatChar /^[\:|\*|;|#]\+/
sy match wikiParaFormatChar /^-----*/
sy match wikiPre            /^\ .*$/         contains=wikiNowiki,wikiNowikiEndTag


" HTML highlighting

if version < 508
  command! -nargs=+ HtmlHiLink hi link     <args>
else
  command! -nargs=+ HtmlHiLink hi def link <args>
endif

if version >= 508 || !exists("did_html_syn_inits")
  HtmlHiLink htmlTag            Function
  HtmlHiLink htmlEndTag         Identifier
  HtmlHiLink htmlArg            Type
  HtmlHiLink htmlTagName        htmlStatement
  HtmlHiLink htmlSpecialTagName Exception
  HtmlHiLink htmlValue          String
  HtmlHiLink htmlSpecialChar    Special

  if !exists("html_no_rendering")
    HtmlHiLink htmlTitle Title
    HtmlHiLink htmlH1    htmlTitle
    HtmlHiLink htmlH2    htmlTitle
    HtmlHiLink htmlH3    htmlTitle
    HtmlHiLink htmlH4    htmlTitle
    HtmlHiLink htmlH5    htmlTitle
    HtmlHiLink htmlH6    htmlTitle

    HtmlHiLink htmlPreProc          PreProc
    HtmlHiLink htmlHead             htmlPreProc
    HtmlHiLink htmlPreProcAttrName  htmlPreProc
    HtmlHiLink htmlPreStmt          htmlPreProc

    HtmlHiLink htmlSpecial          Special
    HtmlHiLink htmlCssDefinition    htmlSpecial
    HtmlHiLink htmlEvent            htmlSpecial
    HtmlHiLink htmlSpecialChar      htmlSpecial

    HtmlHiLink htmlComment          Comment
    HtmlHiLink htmlCommentPart      htmlComment
    HtmlHiLink htmlCssStyleComment  htmlComment

    HtmlHiLink htmlString           String
    HtmlHiLink htmlPreAttr          htmlString
    HtmlHiLink htmlValue            htmlString

    HtmlHiLink htmlError            Error
    HtmlHiLink htmlBadArg           htmlError
    HtmlHiLink htmlBadTag           htmlError
    HtmlHiLink htmlCommentError     htmlError
    HtmlHiLink htmlPreError         htmlError  
    HtmlHiLink htmlPreProcAttrError htmlError
    HtmlHiLink htmlTagError         htmlError

    HtmlHiLink htmlStatement        Statement

    HtmlHiLink htmlConstant         Constant

    HtmlHiLink htmlBoldItalicUnderline htmlBoldUnderlineItalic
    HtmlHiLink htmlUnderlineItalicBold htmlBoldUnderlineItalic
    HtmlHiLink htmlUnderlineBoldItalic htmlBoldUnderlineItalic
    HtmlHiLink htmlItalicBoldUnderline htmlBoldUnderlineItalic
    HtmlHiLink htmlItalicUnderlineBold htmlBoldUnderlineItalic

    HtmlHiLink htmlItalicBold          htmlBoldItalic
    HtmlHiLink htmlItalicUnderline     htmlUnderlineItalic
    HtmlHiLink htmlUnderlineBold       htmlBoldUnderline

    HtmlHiLink htmlLink Underlined

    if !exists("html_my_rendering")
      hi def htmlBold                term=bold                  cterm=bold                  gui=bold
      hi def htmlBoldUnderline       term=bold,underline        cterm=bold,underline        gui=bold,underline
      hi def htmlBoldItalic          term=bold,italic           cterm=bold,italic           gui=bold,italic
      hi def htmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
      hi def htmlUnderline           term=underline             cterm=underline             gui=underline
      hi def htmlUnderlineItalic     term=italic,underline      cterm=italic,underline      gui=italic,underline
      hi def htmlItalic              term=italic                cterm=italic                gui=italic
    endif

  endif " !exists("html_no_rendering")

  if version < 508
    let did_html_syn_inits = 1
  endif

endif " version >= 508 || !exists("did_html_syn_inits")

" Wiki highlighting

HtmlHiLink wikiItalic        htmlItalic
HtmlHiLink wikiBold          htmlBold
HtmlHiLink wikiBoldItalic    htmlBoldItalic
HtmlHiLink wikiItalicBold    htmlBoldItalic
HtmlHiLink wikiBoldAndItalic htmlBoldItalic

HtmlHiLink wikiH1 htmlTitle
HtmlHiLink wikiH2 htmlTitle
HtmlHiLink wikiH3 htmlTitle
HtmlHiLink wikiH4 htmlTitle
HtmlHiLink wikiH5 htmlTitle
HtmlHiLink wikiH6 htmlTitle

HtmlHiLink wikiLink           htmlLink
HtmlHiLink wikiTemplate       htmlSpecial
HtmlHiLink wikiParaFormatChar htmlSpecial
HtmlHiLink wikiPre            htmlConstant
HtmlHiLink wikiRef            htmlComment

HtmlHiLink wikiSource         wikiPre
HtmlHiLink wikiSyntaxHL       wikiPre


let b:current_syntax = "html"

delcommand HtmlHiLink

if main_syntax == "html"
  unlet main_syntax
endif

" vim: set et sts=2 sw=2:

To autodetect files ending in ".wiki", add the following lines to ".vim/filetype.vim" or "vimfiles\filetype.vim" (or create the file if it doesn't exist):

 augroup filetypedetect
     autocmd BufRead,BufNewFile *.wiki setfiletype Wikipedia
     autocmd BufRead,BufNewFile *.wikipedia.org* setfiletype Wikipedia
 augroup END

Alternatively, add the following line to the vimrc file (typically ~/.vimrc on Unix and C:\Program Files\Vim\_vimrc on Windows) (this doesn't work in Vim 7, use the above example):

 autocmd BufRead,BufNewFile *.wiki setfiletype Wikipedia
 autocmd BufRead,BufNewFile *.wikipedia.org* setfiletype Wikipedia

Alternatively, the command ":setf Wikipedia" will temporarily set the syntax for the current file.

The above mentioned Firefox extension Mozex creates a temporary file ending in ".txt" rather than ".wiki" so the above autodetection will not work in combination with that plugin. One solution is to have Mozex invoke vim with these arguments:

-c "setf Wikipedia"

A complete editor command can look some thing like that

gnome-terminal -e "vim -c 'setf Wikipedia' $1"

Wikipedia articles often only have line-breaks at the end of each paragraph, a situation Vim by default doesn't handle as other text editors. Save the following lines to "~/.vim/ftplugin/Wikipedia.vim" or "vimfiles\ftplugin\Wikipedia.vim" to make it as you may be used to from Notepad:

" Wikipedia prefers line breaks only at the end of paragraphs (like in a text
" processor), which results in long, wrapping lines. 
setlocal wrap linebreak
setlocal textwidth=0

" No auto-wrap at all.
setlocal formatoptions-=tc formatoptions+=l
if v:version >= 602 | setlocal formatoptions-=a | endif

" Make navigation more amenable to the long wrapping lines. 
noremap <buffer> k gk
noremap <buffer> j gj
noremap <buffer> <Up> gk
noremap <buffer> <Down> gj
noremap <buffer> 0 g0
noremap <buffer> ^ g^
noremap <buffer> $ g$
noremap <buffer> D dg$ 
noremap <buffer> C cg$ 
noremap <buffer> A g$a

inoremap <buffer> <Up> <C-O>gk
inoremap <buffer> <Down> <C-O>gj

Additional to that you may want to save the following lines to "~/.vim/ftplugin/Wikipedia.vim" or "vimfiles\ftplugin\Wikipedia.vim" for some more gimmicks (you may need to put "filetype plugin on" in your vimrc):

" utf-8 should be set if not already done globally
setlocal fileencoding=utf-8
setlocal matchpairs+=<:>

" Treat lists, indented text and tables as comment lines and continue with the
" same formatting in the next line (i.e. insert the comment leader) when hitting
" <CR> or using "o".
setlocal comments=n:#,n:*,n:\:,s:{\|,m:\|,ex:\|} 
setlocal formatoptions+=roq

" match HTML tags (taken directly from $VIM/ftplugin/html.vim)
if exists("loaded_matchit")
    let b:match_ignorecase=0
    let b:match_skip = 's:Comment'
    let b:match_words = '<:>,' .
    \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
    \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
    \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
endif

" Other useful mappings
" Insert a matching = automatically while starting a new header.
inoremap <buffer> <silent> = <C-R>=(getline('.')==''\|\|getline('.')=~'^=\+$')?"==\<Lt>Left>":"="<CR>

" Enable folding based on ==sections==
setlocal foldexpr=getline(v:lnum)=~'^\\(=\\+\\)[^=]\\+\\1\\(\\s*<!--.*-->\\)\\=\\s*$'?\">\".(len(matchstr(getline(v:lnum),'^=\\+'))-1):\"=\"
setlocal fdm=expr

Please feel free to contribute improvements to the above scripts, or to check on the vim-devel list if anyone has requested the upload of Wikipedia.vim, and if not, to request it. (As of 11 July 2008, it is not in Vim's "syntax/" directory.)

The above scripts are also posted in the vim.org script collection, where they are occasionally updated with newer versions taken from community contributions on this site. Feel free to remind mvc to upload a newer copy periodically if those become stale, since they were uploaded from his vim.org account.

In-browser editors

wikEd

wikEd is a full-featured in-browser text editor that adds enhanced text processing functions to Wikipedia and other MediaWiki edit pages (as of October 2009, wikEd works with Firefox, SeaMonkey, Safari and Google Chrome, but not with Internet Explorer or Opera).

Features include:

  • Powerful search and replace (including Regular expressions)
  • Wikicode syntax highlighting
  • Fullscreen editing mode
  • Edit preview and show changes on the same page without reloading
  • MS-Word and web page import (including tables)
  • Single-click fixing of common mistakes

wikEd can either be installed by pasting a small code snippet to your vector.js page (or monobook.js) or locally as a Greasemonkey user script. For detailed installation instructions see the wikEd homepage.

Dealing with special characters

The English Wikipedia (and most others) are now encoded using the UTF-8 character set, which allows the use of many non-English characters and special symbols. Such characters may appear even in articles where you wouldn't expect them due to the use of interwiki links to non-English versions of the article. Therefore, it's very important to use an editor that does not mangle these characters or replace them with question marks. Check your editor's documentation to make sure that it supports Unicode or UTF-8, and enable it if needed. You don't necessarily need a special editor; recent versions of Notepad and Microsoft Word support Unicode, for example. An extensive list of Unicode-supporting editors is available for Windows and other operating systems (see also: Comparison_of_text_editors).

If your editor does not support UTF-8, then copy-paste from web browser may mangle the characters. For example pasting from Windows Clipboard automatically converts characters to whatever character set is used in your editor and any characters not included in this character set are replaced with question marks. You can avoid this by using one of the helper applications or browser plugins mentioned above. For example It's All Text! does not mangle any characters.

When making an edit to an article with special characters using a new editor, it's a good idea to use the "Show changes" button (next to "Show preview") to see exactly what changes your edit will make - if areas with special characters that you didn't intend to modify are highlighted as red, that means they will be corrupted, even though both versions may look the same to you because you don't have foreign fonts installed.

BabelPad is a free editor for Windows with special support for dealing with Unicode, and is ideal if you need to determine which of several similar-looking characters an article is using, or deal with hard-to-edit Unicode control codes (like for multidirectional text).

See also

Leave a Reply