Skip to content

Commit

Permalink
Added support for gallery tags, partially implemented Open in WP action.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewmutt committed May 13, 2017
1 parent ed16914 commit 8cc3ca0
Show file tree
Hide file tree
Showing 18 changed files with 477 additions and 332 deletions.
385 changes: 203 additions & 182 deletions gen/com/mwplugin/MediaWikiLexer.java

Large diffs are not rendered by default.

252 changes: 152 additions & 100 deletions gen/com/mwplugin/parser/MediaWikiParser.java

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions gen/com/mwplugin/psi/MediaWikiTypes.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gen/com/mwplugin/psi/MediaWikiVisitor.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified out/production/wikimedia/com/mwplugin/MediaWikiAnnotator.class
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/MediaWikiLexer.class
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/MediaWikiUtil.class
Binary file not shown.
51 changes: 32 additions & 19 deletions out/production/wikimedia/com/mwplugin/mediawiki.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
tokens = [
// space='regexp:\s+'
// comment='regexp://.*'
tablesectionstart = "|-"
tablesectionstartcaptionable = "|+"
galleryopen = "<gallery>"
galleryclose = "</gallery>"
pipedash = "|-"
pipeplus = "|+"
quote5 = "'''''"
quote3 = "'''"
quote2 = "''"
tablestart = "{|"
tableend = "|}"
pipeclosecurly = "|}"
tableheaderdoubledelimiter = "!!"
doublepipe = "||"
htmlcommentopen = "<!--"
Expand Down Expand Up @@ -63,6 +65,7 @@
curlyopen2 = "{{"
curlyclose2 = "}}"
pipe = "|"
symboltoken = "regexp:[\.,\(\)\-\:#\/';–\!%\?_—\+\$~·’†½\*@−‘\^ᴥ•…`“”、」「』『。\"±€‐×°]"

// okaysymbols = "regexp:[\(|\)|_|\.|\!|\/|\-|\:|#]"
// lcaseletter="regexp:\d"
Expand Down Expand Up @@ -182,9 +185,11 @@ letter ::=
symbol ::=
html-unsafe-symbol|
underscore|
"."|
","|
"("|")"|"-"|":"|"#"|"/"|"'"|";"|"|"|"–"|doublequote|"!"|"%"|"?"|"_"|"—"|"+"|"$"|"~"|"·"|"’"|equals|"†"|"½"|"*"|"@"|"−"|"‘"|"^"|"ᴥ"|"•"|"…"|"`"|tableheaderdoubledelimiter|"“"|"”"|htmltagselfclose
symboltoken|
doublequote|
equals|
tableheaderdoubledelimiter|
htmltagselfclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -261,7 +266,7 @@ interwiki-prefix ::=
}

interwiki ::=
"Wikipedia"|"File"
"Wikipedia"|"File"|"Image"

{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
Expand Down Expand Up @@ -387,7 +392,8 @@ template-block-end ::= "}}"
}


template-block ::= template-block-start template-name whitespace? newline* ("|" whitespace? (template-property-named|template-property-unassigned)? whitespace? newline* noparse-block?)* template-block-end
//(("|"|doublepipe) (internal-link-property | internal-link-unassigned-property))*
template-block ::= template-block-start template-name whitespace? newline* (("|"|doublepipe|pipedash|pipeplus) whitespace? (template-property-named|template-property-unassigned)? whitespace? newline* noparse-block?)* (template-block-end|pipeclosecurly "}")
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -460,15 +466,16 @@ inline-text ::=
inline-element-sans-pipe ::= ( !"|" (all-inline-elements))*

all-inline-elements ::= (letter|symbol|decimaldigit|whitespace-char|inline-element|special-block)
all-inline-elements-including-pipe ::= (letter|symbol|decimaldigit|whitespace-char|inline-element|special-block|"|")

inline-element ::=
gallery-block |
html-tag |
url|
category-link |
link |
magic-link |
image-inline |
gallery-block |
media-inline |
text-with-formatting |
template-block
Expand Down Expand Up @@ -570,7 +577,7 @@ extra-description ::=
}

external-link ::=
openbracket url whitespace? (inline-element)* closebracket
openbracket url whitespace? (all-inline-elements-including-pipe)* closebracket
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -711,7 +718,13 @@ image-extension ::=
"png"|
"svg"|
"gif"|
"bmp"
"bmp"|
"JPG"|
"JPEG"|
"PNG"|
"SVG"|
"GIF"|
"BMP"
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -748,7 +761,7 @@ image-mode-manual-thumb ::=
}

image-name ::=
page-name "." image-extension
interwiki-prefix (letter|decimal-number|symbol|whitespace)*
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -934,7 +947,7 @@ image-param-border ::=
}

gallery-block ::=
"<gallery>" newline? gallery-image (newline? gallery-image)* newline? "</gallery>"
galleryopen newline? gallery-image (newline? gallery-image)* newline? galleryclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1182,7 +1195,7 @@ pre-closing-tag ::=
}

html-comment ::=
htmlcommentopen whitespace? all-inline-elements* whitespace? htmlcommentclose
htmlcommentopen whitespace? all-inline-elements-including-pipe* whitespace? htmlcommentclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1260,7 +1273,7 @@ plain-text ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

friendly-ref-link-char ::= ("!"|"$"|"%"|"&"|"("")"|"*"|","|"-"|"."|":"|";"|"<"|"@"|"["|"]"|"^"|"_"|"`"|"{"|"|"|"}"|"~"|letter|decimaldigit|"–"|"'"|"/"|template-block)
friendly-ref-link-char ::= ("!"|"$"|"%"|"&"|"("|")"|"*"|","|"-"|"."|":"|";"|"<"|"@"|"["|"]"|"^"|"_"|"`"|"{"|"|"|"}"|"~"|letter|decimaldigit|"–"|"'"|"/"|template-block|"?")

unicode-wiki ::=
letter |
Expand Down Expand Up @@ -1451,13 +1464,13 @@ table-start ::= tablestart
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

table-end ::= tableend
table-end ::= pipeclosecurly
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

table-section-start ::= (tablesectionstart | tablesectionstartcaptionable)
table-section-start ::= (pipedash | pipeplus)
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1493,14 +1506,14 @@ cell-formatting ::= cell-content
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

cell-content ::= ((!tableheaderdoubledelimiter !doublepipe !(newline whitespace? (tablesectionstart | tablesectionstartcaptionable))) (!(newline whitespace? "|}")) !(newline whitespace? "|") (!(newline whitespace? "!")) all-inline-elements)*
cell-content ::= ((!tableheaderdoubledelimiter !doublepipe !(newline whitespace? (pipedash | pipeplus))) (!(newline whitespace? "|}")) !(newline whitespace? "|") (!(newline whitespace? "!")) all-inline-elements)*
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

paragraph-and-more ::=
paragraph (EOF | newline? special-block-and-more | newline paragraph-and-more | (tablesectionstart | tablesectionstartcaptionable))?
paragraph (EOF | newline? special-block-and-more | newline paragraph-and-more | (pipedash | pipeplus))?
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down
Binary file modified out/production/wikimedia/com/mwplugin/parser/MediaWikiParser.class
Binary file not shown.
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/psi/MediaWikiTypes.class
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/psi/MediaWikiVisitor.class
Binary file not shown.
3 changes: 3 additions & 0 deletions src/com/mwplugin/MediaWikiAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public MediaWikiAnnotator()
keysMap.put(MediaWikiTableHeaderDoubleDelimitedStart.class, TextAttributesKey.createTextAttributesKey("MEDIAWIKI_TABLE"));


keysMap.put(MediaWikiGalleryBlock.class, DefaultLanguageHighlighterColors.STRING);
keysMap.put(MediaWikiImageName.class, DefaultLanguageHighlighterColors.NUMBER);

// / addNewKey(MediaWikiTypes.CONTENT, HighlighterColors.TEXT);
// addNewKey(MediaWikiTypes.LINK, DefaultLanguageHighlighterColors.STRING);
// addNewKey(MediaWikiTypes.TEMPLATE, DefaultLanguageHighlighterColors.CONSTANT);
Expand Down
8 changes: 4 additions & 4 deletions src/com/mwplugin/MediaWikiCompletionContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public void beforeCompletion(@NotNull CompletionInitializationContext context) {
int selectionEndOffset = context.getSelectionEndOffset();
int identifierEndOffset = context.getIdentifierEndOffset();

System.out.println(replacementOffset );
System.out.println(startOffset );
System.out.println(selectionEndOffset );
System.out.println(identifierEndOffset );
// System.out.println(replacementOffset );
// System.out.println(startOffset );
// System.out.println(selectionEndOffset );
// System.out.println(identifierEndOffset );
}


Expand Down
2 changes: 1 addition & 1 deletion src/com/mwplugin/MediaWikiPairedBraceMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public BracePair[] getPairs()
{
BracePair[] pairs = new BracePair[4];
pairs[0] = new BracePair(MediaWikiTypes.curlyopen2, MediaWikiTypes.curlyclose2, true);
pairs[1] = new BracePair(MediaWikiTypes.tablestart, MediaWikiTypes.tableend, true);
pairs[1] = new BracePair(MediaWikiTypes.tablestart, MediaWikiTypes.pipeclosecurly, true);
pairs[2] = new BracePair(MediaWikiTypes.refopencomplete, MediaWikiTypes.refclose, true);
pairs[3] = new BracePair(MediaWikiTypes.openbracket2, MediaWikiTypes.closebracket2, true);
return pairs;
Expand Down
12 changes: 8 additions & 4 deletions src/com/mwplugin/_MediaWikiLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ lcaseletter=[a-z]
ucaseletter=[A-Z]
decimaldigit=[0-9]
tab=\t
symboltoken = [\.,\(\)\-\:#\/';–\!%\?_—\+\$~·’†½\*@−‘\^ᴥ•…`“”、」「』『。\"±‐×°]
//okaysymbols = "regexp:[\(|\)|_|\.|\!|\/|\\|\-|\:|#]"

%%
<YYINITIAL> {
"|-" { return tablesectionstart; }
"|+" {return tablesectionstartcaptionable;}
"|}" { return tableend; }
"|-" { return pipedash; }
"|+" {return pipeplus;}
"|}" { return pipeclosecurly; }
"{|" { return tablestart; }
"||" { return doublepipe; }
"!!" { return tableheaderdoubledelimiter; }
Expand All @@ -44,6 +45,8 @@ tab=\t
"<ref>" { return refopencomplete; }
"<ref" { return refopen; }
"</ref>" { return refclose; }
"<gallery>" {return galleryopen;}
"</gallery>" {return galleryclose;}
// "<br/>" {return htmltagnewline;}
"=====" { return equals5; }
"====" { return equals4; }
Expand All @@ -65,14 +68,15 @@ tab=\t
"[" { return openbracket; }
"]" { return closebracket; }


// {okaysymbols} { return okaysymbols; }
{newline} { return newline; }
{lcaseletter} { return lcaseletter; }
{ucaseletter} { return ucaseletter; }
{decimaldigit} { return decimaldigit; }
{otherletter} { return otherletter; }
{tab} { return tab; }

{symboltoken} {return symboltoken;}
}

[^] { return com.intellij.psi.TokenType.BAD_CHARACTER; }
27 changes: 27 additions & 0 deletions src/com/mwplugin/actions/ViewArticleInBrowserAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.mwplugin.actions;

import com.intellij.ide.browsers.BrowserLauncher;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.vfs.VirtualFile;

import java.net.URI;

/**
* Created by andrewsimmons on 5/12/17.
*/
public class ViewArticleInBrowserAction extends AnAction
{
@Override
public void actionPerformed(AnActionEvent e)
{
Document currentDoc = FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor().getDocument();
VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc);
String fileName = currentFile.getPath();
}
}
Loading

0 comments on commit 8cc3ca0

Please sign in to comment.