@bhsd/codemirror-mediawiki 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mediawiki.js CHANGED
@@ -10,6 +10,7 @@ import { commonHtmlAttrs, htmlAttrs, extAttrs } from 'wikiparser-node/dist/util/
10
10
  import { MediaWiki } from './token';
11
11
  import { htmlTags, tokens } from './config';
12
12
  import { braceStackUpdate } from './fold';
13
+ import { EditorView } from '@codemirror/view';
13
14
  const re = new RegExp(String.raw `\.(?:${wmf})\.org$`, 'u');
14
15
  /**
15
16
  * 检查首字母大小写并插入正确的自动填充内容
@@ -359,11 +360,154 @@ export class FullMediaWiki extends MediaWiki {
359
360
  };
360
361
  }
361
362
  }
363
+ const getSelector = (cls, prefix = '') => typeof prefix === 'string'
364
+ ? cls.map(c => `.cm-mw-${prefix}${c}`).join()
365
+ : prefix.map(p => getSelector(cls, p)).join();
366
+ const getGround = (type, ground) => ground ? `${type}${ground === 1 ? '' : ground}-` : '';
367
+ const getGrounds = (grounds, r, g, b, a) => ({
368
+ [grounds.map(([template, ext, link]) => `.cm-mw-${getGround('template', template)}${getGround('exttag', ext)}${getGround('link', link)}ground`).join()]: {
369
+ backgroundColor: `rgb(${r},${g},${b},${a})`,
370
+ },
371
+ });
372
+ /**
373
+ * @author pastakhov and others
374
+ * @license GPL-2.0-or-later
375
+ * @see https://gerrit.wikimedia.org/g/mediawiki/extensions/CodeMirror
376
+ */
377
+ const theme = /* @__PURE__ */ EditorView.theme({
378
+ [getSelector(['', '~*'], 'section--1')]: {
379
+ fontSize: '1.8em',
380
+ lineHeight: '1.2em',
381
+ },
382
+ [getSelector(['', '~*'], 'section--2')]: {
383
+ fontSize: '1.5em',
384
+ lineHeight: '1.2em',
385
+ },
386
+ [getSelector(['3~*', '4~*', '5~*', '6~*'], 'section--')]: {
387
+ fontWeight: 'bold',
388
+ },
389
+ [`${getSelector(['section-header', 'template', 'parserfunction', 'file-delimiter', 'magic-link'])},${getSelector(['pagename', 'bracket', 'delimiter'], 'link-')},${getSelector(['extlink'], ['', 'free-'])},${getSelector(['bracket', 'attribute'], ['exttag-', 'htmltag-'])},${getSelector(['delimiter2', 'definition'], 'table-')}`]: {
390
+ fontWeight: 'normal',
391
+ },
392
+ [`${getSelector(['redirect', 'list', 'free-extlink-protocol', 'strong'])},${getSelector(['protocol', 'bracket'], 'extlink-')},${getSelector(['tag-name'], ['ext', 'html'])},${getSelector(['bracket', 'delimiter', 'th', 'caption'], 'table-')},${getSelector(['bracket', 'delimiter'], 'convert-')}`]: {
393
+ fontWeight: 'bold',
394
+ },
395
+ [`${getSelector(['pagename', 'link-tosection', 'magic-link'])},${getSelector(['extlink', 'extlink-protocol'], ['', 'free-'])}`]: {
396
+ textDecoration: 'underline',
397
+ },
398
+ '.cm-mw-em': {
399
+ fontStyle: 'italic',
400
+ },
401
+ [getSelector(['section-header', 'redirect', 'list', 'apostrophes'])]: {
402
+ color: 'var(--cm-hr)',
403
+ },
404
+ '.cm-mw-error': {
405
+ color: 'var(--cm-error)',
406
+ },
407
+ '.cm-mw-skipformatting': {
408
+ backgroundColor: 'var(--cm-sp)',
409
+ },
410
+ [getSelector(['double-underscore', 'signature', 'hr'])]: {
411
+ color: 'var(--cm-hr)',
412
+ fontWeight: 'bold',
413
+ backgroundColor: 'var(--cm-hr-bg)',
414
+ },
415
+ [getSelector(['comment', 'ignored'])]: {
416
+ color: 'var(--cm-comment)',
417
+ fontWeight: 'normal',
418
+ },
419
+ [getSelector(['name', 'delimiter', 'bracket'], 'template-')]: {
420
+ color: 'var(--cm-tpl)',
421
+ fontWeight: 'bold',
422
+ },
423
+ '.cm-mw-template-argument-name': {
424
+ color: 'var(--cm-arg)',
425
+ fontWeight: 'normal',
426
+ },
427
+ '.cm-mw-templatevariable': {
428
+ color: 'var(--cm-var)',
429
+ fontWeight: 'normal',
430
+ },
431
+ [getSelector(['name', 'bracket', 'delimiter'], 'templatevariable-')]: {
432
+ color: 'var(--cm-var-name)',
433
+ fontWeight: 'bold',
434
+ },
435
+ [getSelector(['name', 'bracket', 'delimiter'], 'parserfunction-')]: {
436
+ color: 'var(--cm-func)',
437
+ fontWeight: 'bold',
438
+ },
439
+ [`${getSelector(['pagename', 'bracket', 'delimiter'], 'link-')},${getSelector(['file-delimiter', 'magic-link'])},${getSelector(['', '-protocol', '-bracket'], 'extlink')},${getSelector(['', '-protocol'], 'free-extlink')}`]: {
440
+ color: 'var(--cm-link)',
441
+ },
442
+ [getSelector(['image-parameter', 'link-tosection'])]: {
443
+ color: 'var(--cm-sect)',
444
+ fontWeight: 'normal',
445
+ },
446
+ [getSelector(['name', 'bracket', 'attribute'], ['exttag-', 'htmltag-'])]: {
447
+ color: 'var(--cm-tag)',
448
+ },
449
+ [getSelector(['tag-attribute-value'], ['ext', 'html'])]: {
450
+ color: 'var(--cm-attr)',
451
+ fontWeight: 'normal',
452
+ },
453
+ [getSelector(['bracket', 'delimiter', 'delimiter2', 'definition'], 'table-')]: {
454
+ color: 'var(--cm-table)',
455
+ },
456
+ '.cm-mw-table-definition-value': {
457
+ color: 'var(--cm-table-attr)',
458
+ fontWeight: 'normal',
459
+ },
460
+ [getSelector(['bracket', 'delimiter', 'flag', 'lang'], 'convert-')]: {
461
+ color: 'var(--cm-convert)',
462
+ },
463
+ '.cm-mw-entity': {
464
+ color: 'var(--cm-entity)',
465
+ },
466
+ '.cm-mw-exttag': {
467
+ backgroundColor: 'rgb(119,0,170,.04)',
468
+ },
469
+ /* eslint-disable no-sparse-arrays */
470
+ ...getGrounds([[1]], 170, 17, 17, 0.04),
471
+ ...getGrounds([[2]], 170, 17, 17, 0.08),
472
+ ...getGrounds([[3]], 170, 17, 17, 0.12),
473
+ ...getGrounds([[1, 1], [, 1]], 119, 0, 170, 0.04),
474
+ ...getGrounds([[1, 2], [, 2]], 119, 0, 170, 0.08),
475
+ ...getGrounds([[1, 3], [, 3]], 119, 0, 170, 0.12),
476
+ ...getGrounds([[1, , 1], [, 1, 1], [, , 1]], 34, 17, 153, 0.04),
477
+ ...getGrounds([[1, 1, 1], [, 2, 1]], 77, 9, 162, 0.08),
478
+ ...getGrounds([[1, 2, 1], [, 3, 1]], 91, 6, 164, 0.12),
479
+ ...getGrounds([[1, 3, 1]], 98, 4, 166, 0.16),
480
+ ...getGrounds([[2, 1]], 145, 9, 94, 0.08),
481
+ ...getGrounds([[2, 2]], 136, 6, 119, 0.12),
482
+ ...getGrounds([[2, 3]], 132, 4, 132, 0.16),
483
+ ...getGrounds([[2, , 1]], 102, 17, 85, 0.08),
484
+ ...getGrounds([[2, 1, 1]], 108, 11, 113, 0.12),
485
+ ...getGrounds([[2, 2, 1]], 111, 9, 128, 0.16),
486
+ ...getGrounds([[2, 3, 1]], 112, 7, 136, 0.2),
487
+ ...getGrounds([[3, 1]], 153, 11, 68, 0.12),
488
+ ...getGrounds([[3, 2]], 145, 9, 94, 0.16),
489
+ ...getGrounds([[3, 3]], 139, 7, 109, 0.2),
490
+ ...getGrounds([[3, , 1]], 125, 17, 62, 0.12),
491
+ ...getGrounds([[3, 1, 1]], 123, 13, 89, 0.16),
492
+ ...getGrounds([[3, 2, 1]], 122, 10, 105, 0.2),
493
+ ...getGrounds([[3, 3, 1]], 122, 9, 116, 0.24),
494
+ /* eslint-enable no-sparse-arrays */
495
+ [getSelector(['pre', 'nowiki'], 'tag-')]: {
496
+ backgroundColor: 'rgb(0,0,0,.04)',
497
+ },
498
+ '.cm-bidi-isolate, &[dir="rtl"] .cm-mw-template-name': {
499
+ unicodeBidi: 'isolate',
500
+ },
501
+ '.cm-bidi-ltr': {
502
+ direction: 'ltr',
503
+ display: 'inline-block',
504
+ },
505
+ });
362
506
  /**
363
507
  * Gets a LanguageSupport instance for the MediaWiki mode.
364
508
  * @param config Configuration for the MediaWiki mode
365
509
  */
366
510
  export const mediawiki = (config) => {
367
511
  const mode = new FullMediaWiki(config), lang = StreamLanguage.define(mode.mediawiki()), highlighter = syntaxHighlighting(HighlightStyle.define(mode.getTagStyles()));
368
- return new LanguageSupport(lang, highlighter);
512
+ return new LanguageSupport(lang, [highlighter, theme]);
369
513
  };