(refs #7358) Initial 4.7 update commit
[simantics/platform.git] / bundles / org.simantics.wiki.ui / src / org / simantics / wiki / ui / language / MediaWikiLanguage.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.wiki.ui.language;
13
14 import org.eclipse.mylyn.wikitext.mediawiki.internal.phrase.EscapePhraseModifier;
15 import org.eclipse.mylyn.wikitext.mediawiki.internal.phrase.SimplePhraseModifier;
16 import org.eclipse.mylyn.wikitext.parser.DocumentBuilder.SpanType;
17 import org.eclipse.mylyn.wikitext.parser.markup.phrase.HtmlCommentPhraseModifier;
18 import org.eclipse.mylyn.wikitext.parser.markup.phrase.LimitedHtmlEndTagPhraseModifier;
19 import org.eclipse.mylyn.wikitext.parser.markup.phrase.LimitedHtmlStartTagPhraseModifier;
20
21 /**
22  * A markup language for <a href="http://www.mediawiki.org">MediaWiki</a> <a
23  * href="http://en.wikipedia.org/wiki/Wikitext">Wikitext markup</a>, which is the wiki format used by <a
24  * href="http://www.wikipedia.org>WikiPedia</a> and <a href="http://www.wikimedia.org/">several other major sites</a>.
25  * 
26  * @author David Green
27  * @since 1.0
28  */
29 @SuppressWarnings("restriction")
30 public class MediaWikiLanguage extends org.eclipse.mylyn.wikitext.mediawiki.MediaWikiLanguage {
31         public MediaWikiLanguage() {
32                 super();
33         }
34
35     @Override
36         protected void addStandardPhraseModifiers(PatternBasedSyntax phraseModifierSyntax) {
37                 phraseModifierSyntax.beginGroup("(?:(?<=[\\s\\.,\\\"'?!;:\\)\\(\\{\\}\\[\\]])|^)(?:", 0); //$NON-NLS-1$
38                 phraseModifierSyntax.add(new EscapePhraseModifier());
39                 phraseModifierSyntax.add(new SimplePhraseModifier("'''''", new SpanType[] { SpanType.BOLD, SpanType.ITALIC }, //$NON-NLS-1$
40                                 true));
41                 phraseModifierSyntax.add(new SimplePhraseModifier("'''", SpanType.BOLD, true)); //$NON-NLS-1$
42                 phraseModifierSyntax.add(new SimplePhraseModifier("''", SpanType.ITALIC, true)); //$NON-NLS-1$
43                 phraseModifierSyntax.endGroup(")(?=\\W|$)", 0); //$NON-NLS-1$
44
45                 boolean escapingHtml = configuration == null ? false : configuration.isEscapingHtmlAndXml();
46
47                 if (!escapingHtml) {
48                         String[] allowedHtmlTags = new String[] { // HANDLED BY LineBreakToken "<br>",
49                                         // HANDLED BY LineBreakToken "<br/>",
50                                         "b", "big", "blockquote", "caption", "center", "cite", "code", "dd", "del", "div", "dl", "dt", "em", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$
51                                         "font", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "i", "ins", "li", "ol", "p", "pre", "rb", "rp", "rt", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ //$NON-NLS-15$ //$NON-NLS-16$ //$NON-NLS-17$
52                                         "ruby", "s", "small", "span", "strike", "strong", "sub", "sup", "table", "td", "th", "tr", "tt", "u", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$
53                                         "ul", "var", //$NON-NLS-1$ //$NON-NLS-2$
54                                         "applet", "object", "embed" };
55                         phraseModifierSyntax.add(new LimitedHtmlEndTagPhraseModifier(allowedHtmlTags));
56                         phraseModifierSyntax.add(new LimitedHtmlStartTagPhraseModifier(allowedHtmlTags));
57                         phraseModifierSyntax.add(new HtmlCommentPhraseModifier());
58                 }
59         }
60 }