Skip to content

Commit 4aff057

Browse files
committed
feat: configurable contentPreservingTags
1 parent e9418b8 commit 4aff057

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can find a live demo [here](https://wikistxr.t7ru.link/).
1111
- Very fast!
1212
- Easily portable to every modern browser environments.
1313
- Wikitext-aware tokenization (templates, links, tables, comments, tags, magic words, etc.).
14-
- Configurable protocols, redirect keywords, and extension tags.
14+
- Configurable protocols, redirect keywords, extension tags, etc.
1515
- HTML output with granular CSS classes (`getDefaultStyles()` provided).
1616
- Incremental mode caches line tokens and state for fast live editing.
1717

@@ -48,10 +48,11 @@ document.head.appendChild(styleTag);
4848

4949
### Configuration
5050
```typescript
51-
const editor = new WikitextEditor({
51+
const highlighter = new WikitextHighlighter({
5252
urlProtocols: /^(?:http|https|mailto)/i,
5353
redirectKeywords: ['REDIRECT', 'RINVIA'],
54-
extensionTags: ['nowiki', 'ref', 'gallery']
54+
extensionTags: ['nowiki', 'ref', 'gallery'],
55+
contentPreservingTags: ['nowiki', 'pre', 'tabber']
5556
});
5657
```
5758

src/lib/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const DEFAULT_EXTENSION_TAGS = [
3232
"source",
3333
];
3434

35-
export const CONTENT_PRESERVING_TAGS = [
35+
export const DEFAULT_CONTENT_PRESERVING_TAGS = [
3636
"nowiki",
3737
"pre",
3838
"syntaxhighlight",
@@ -75,7 +75,7 @@ const generateSectionStyles = () => {
7575
};
7676

7777
const generateExtensionTagStyles = () => {
78-
return CONTENT_PRESERVING_TAGS.map(
78+
return DEFAULT_CONTENT_PRESERVING_TAGS.map(
7979
(tag) => `.wt-ext-${tag} { background-color: ${COLORS.lightGrayBg}; }`
8080
).join("\n ");
8181
};

src/lib/highlighter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DEFAULT_URL_PROTOCOLS,
1010
DEFAULT_REDIRECT_KEYWORDS,
1111
DEFAULT_EXTENSION_TAGS,
12-
CONTENT_PRESERVING_TAGS,
12+
DEFAULT_CONTENT_PRESERVING_TAGS,
1313
DEFAULT_STYLES
1414
} from './constants';
1515
import { createSpan } from './utils';
@@ -26,6 +26,7 @@ export class WikitextHighlighter {
2626
protected urlProtocols: RegExp;
2727
protected redirectRegex: RegExp;
2828
protected extensionTags: string[];
29+
protected contentPreservingTags: string[];
2930
protected tokenizer: WikitextTokenizer;
3031

3132
constructor(config: HighlightConfig = {}) {
@@ -36,11 +37,12 @@ export class WikitextHighlighter {
3637
'i'
3738
);
3839
this.extensionTags = config.extensionTags || DEFAULT_EXTENSION_TAGS;
40+
this.contentPreservingTags = config.contentPreservingTags || DEFAULT_CONTENT_PRESERVING_TAGS;
3941
this.tokenizer = new WikitextTokenizer(
4042
this.urlProtocols,
4143
this.redirectRegex,
4244
this.extensionTags,
43-
CONTENT_PRESERVING_TAGS
45+
this.contentPreservingTags
4446
);
4547
}
4648

src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export {
88
DEFAULT_URL_PROTOCOLS,
99
DEFAULT_REDIRECT_KEYWORDS,
1010
DEFAULT_EXTENSION_TAGS,
11+
DEFAULT_CONTENT_PRESERVING_TAGS,
1112
DEFAULT_STYLES,
1213
} from "./constants";

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface HighlightConfig {
1111
urlProtocols?: RegExp;
1212
redirectKeywords?: string[];
1313
extensionTags?: string[];
14+
contentPreservingTags?: string[];
1415
}
1516

1617
export interface ClosingResult {

0 commit comments

Comments
 (0)