Skip to content

Commit

Permalink
feat(MediaWiki): templates for table syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
bhsd-harry committed Aug 16, 2024
1 parent 9df3b7f commit f7d0e05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## 2.17.2

*2024-08-14*
*2024-08-16*

**Added**

- The [openLinks](./mw/README.md#openlinks) extension can now be triggered by clicking on the link fragment
- [Autocompletion](./README.md#autocompletion) for `<ref>` names in the MediaWiki mode
- Table syntax using templates `{{(!}}`, `{{!)}}`, `{{!-}}`, `{{!+}}` and `{{!!}}` in the MediaWiki mode

**Fixed**

Expand Down
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export class MediaWiki {
ch = stream.next()!;
const isTemplate = ['inTemplateArgument', 'inParserFunctionArgument', 'inVariable']
.includes(state.tokenize.name),
pipe = String.raw`${isTemplate ? '' : String.raw`\||`}\{\{\s*!\s*\}\}`;
pipe = String.raw`${isTemplate ? '' : String.raw`\||`}\{(?:\{\s*|\s*\()!\s*\}\}`;
switch (ch) {
case '#':
if (stream.match(this.redirectRegex)) {
Expand Down Expand Up @@ -957,7 +957,7 @@ export class MediaWiki {
@getTokenizer
get eatStartTable(): Tokenizer {
return (stream, state) => {
stream.match(/^(?:\{\||\{{3}\s*!\s*\}\})\s*/u);
stream.match(/^(?:\{\||\{\{(?:\{\s*|\s*\()!\s*\}\})\s*/u);
state.tokenize = this.inTableDefinition();
return makeLocalTagStyle('tableBracket', state);
};
Expand Down Expand Up @@ -1008,19 +1008,21 @@ export class MediaWiki {
return (stream, state) => {
if (stream.sol()) {
stream.eatSpace();
if (stream.match(/^(?:\||\{\{\s*!\s*\}\})/u)) {
if (stream.match(/^-+\s*/u)) {
const mt = stream.match(/^(?:\||\{\{\s*!([!)+-])?\s*\}\})/u) as RegExpMatchArray | false;
if (mt) {
if (mt[1] === '-' || !mt[1] && stream.eat('-')) {
stream.match(/^-*\s*/u);
state.tokenize = this.inTableDefinition(true);
return makeLocalTagStyle('tableDelimiter', state);
} else if (stream.match(/^\+\s*/u)) {
} else if (mt[1] === '+' || !mt[1] && stream.match(/^\+\s*/u)) {
state.tokenize = this.inTableCell(tokens.tableCaption);
return makeLocalTagStyle('tableDelimiter', state);
} else if (stream.eat('}')) {
} else if (mt[1] === ')' || !mt[1] && stream.eat('}')) {
pop(state);
return makeLocalTagStyle('tableBracket', state);
}
stream.eatSpace();
state.tokenize = this.inTableCell(tokens.tableTd);
state.tokenize = this.inTableCell(tokens.tableTd, mt[1] !== '!');
return makeLocalTagStyle('tableDelimiter', state);
} else if (stream.match(/^!\s*/u)) {
state.tokenize = this.inTableCell(tokens.tableTh);
Expand All @@ -1040,7 +1042,7 @@ export class MediaWiki {
const chars = "'<~_-{";
return (stream, state) => {
if (stream.sol()) {
if (stream.match(/^\s*(?:[|!]|\{\{\s*!\s*\}\})/u, false)) {
if (stream.match(/^\s*(?:[|!]|\{\{\s*![!)+-]?\s*\}\})/u, false)) {
state.tokenize = this.inTable;
return '';
} else if (firstLine) {
Expand All @@ -1052,7 +1054,7 @@ export class MediaWiki {
}
if (firstLine) {
if (
stream.match(/^(?:\||\{\{\s*!\s*\}\}){2}\s*/u)
stream.match(/^(?:(?:\||\{\{\s*!\s*\}\}){2}|\{\{\s*!!\s*\}\})\s*/u)
|| style === tokens.tableTh && stream.match(/^!!\s*/u)
) {
state.bold = false;
Expand Down

0 comments on commit f7d0e05

Please sign in to comment.