@yozora/tokenizer-html-block 2.0.0-alpha.0 → 2.0.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/README.md +4 -6
- package/lib/cjs/index.js +8 -9
- package/lib/esm/index.js +9 -10
- package/lib/types/index.d.ts +1 -1
- package/lib/types/match.d.ts +2 -2
- package/lib/types/parse.d.ts +2 -2
- package/lib/types/tokenizer.d.ts +4 -4
- package/lib/types/types.d.ts +3 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `GfmExParser` / `GfmParser` directly.
|
|
|
84
84
|
registered in *YastParser* as a plugin-in before it can be used.
|
|
85
85
|
|
|
86
86
|
```typescript {4,9}
|
|
87
|
-
import {
|
|
87
|
+
import { DefaultParser } from '@yozora/core-parser'
|
|
88
88
|
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
|
|
89
89
|
import TextTokenizer from '@yozora/tokenizer-text'
|
|
90
90
|
import HtmlBlockTokenizer from '@yozora/tokenizer-html-block'
|
|
91
91
|
|
|
92
|
-
const parser = new
|
|
93
|
-
.
|
|
94
|
-
.
|
|
92
|
+
const parser = new DefaultParser()
|
|
93
|
+
.useFallbackTokenizer(new ParagraphTokenizer())
|
|
94
|
+
.useFallbackTokenizer(new TextTokenizer())
|
|
95
95
|
.useTokenizer(new HtmlBlockTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -240,7 +240,6 @@ Name | Type | Required | Default
|
|
|
240
240
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
241
241
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
242
242
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
243
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
244
243
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
245
244
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
246
245
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -300,7 +299,6 @@ Name | Type | Required | Default
|
|
|
300
299
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
301
300
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
302
301
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
303
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
304
302
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
305
303
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
306
304
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -364,8 +364,8 @@ const match = function () {
|
|
|
364
364
|
const token = {
|
|
365
365
|
nodeType: ast.HtmlType,
|
|
366
366
|
position: {
|
|
367
|
-
start: coreTokenizer.
|
|
368
|
-
end: coreTokenizer.
|
|
367
|
+
start: coreTokenizer.calcStartPoint(nodePoints, startIndex),
|
|
368
|
+
end: coreTokenizer.calcEndPoint(nodePoints, nextIndex - 1),
|
|
369
369
|
},
|
|
370
370
|
condition,
|
|
371
371
|
lines: [line],
|
|
@@ -480,16 +480,15 @@ const match = function () {
|
|
|
480
480
|
}
|
|
481
481
|
};
|
|
482
482
|
|
|
483
|
-
const parse = function () {
|
|
483
|
+
const parse = function (api) {
|
|
484
484
|
return {
|
|
485
|
-
parse: token => {
|
|
485
|
+
parse: tokens => tokens.map(token => {
|
|
486
486
|
const contents = coreTokenizer.mergeContentLinesFaithfully(token.lines);
|
|
487
|
-
const node =
|
|
488
|
-
type: 'html',
|
|
489
|
-
value: character.calcStringFromNodePoints(contents)
|
|
490
|
-
};
|
|
487
|
+
const node = api.shouldReservePosition
|
|
488
|
+
? { type: 'html', position: token.position, value: character.calcStringFromNodePoints(contents) }
|
|
489
|
+
: { type: 'html', value: character.calcStringFromNodePoints(contents) };
|
|
491
490
|
return node;
|
|
492
|
-
},
|
|
491
|
+
}),
|
|
493
492
|
};
|
|
494
493
|
};
|
|
495
494
|
|
package/lib/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAsciiLetter, AsciiCodePoint, isAsciiDigitCharacter, isWhitespaceCharacter, calcStringFromNodePoints, isAsciiUpperLetter } from '@yozora/character';
|
|
2
|
-
import { eatOptionalWhitespaces,
|
|
2
|
+
import { eatOptionalWhitespaces, calcStartPoint, calcEndPoint, mergeContentLinesFaithfully, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
3
3
|
import { HtmlType } from '@yozora/ast';
|
|
4
4
|
|
|
5
5
|
function eatHTMLAttribute(nodePoints, startIndex, endIndex) {
|
|
@@ -360,8 +360,8 @@ const match = function () {
|
|
|
360
360
|
const token = {
|
|
361
361
|
nodeType: HtmlType,
|
|
362
362
|
position: {
|
|
363
|
-
start:
|
|
364
|
-
end:
|
|
363
|
+
start: calcStartPoint(nodePoints, startIndex),
|
|
364
|
+
end: calcEndPoint(nodePoints, nextIndex - 1),
|
|
365
365
|
},
|
|
366
366
|
condition,
|
|
367
367
|
lines: [line],
|
|
@@ -476,16 +476,15 @@ const match = function () {
|
|
|
476
476
|
}
|
|
477
477
|
};
|
|
478
478
|
|
|
479
|
-
const parse = function () {
|
|
479
|
+
const parse = function (api) {
|
|
480
480
|
return {
|
|
481
|
-
parse: token => {
|
|
481
|
+
parse: tokens => tokens.map(token => {
|
|
482
482
|
const contents = mergeContentLinesFaithfully(token.lines);
|
|
483
|
-
const node =
|
|
484
|
-
type: 'html',
|
|
485
|
-
value: calcStringFromNodePoints(contents)
|
|
486
|
-
};
|
|
483
|
+
const node = api.shouldReservePosition
|
|
484
|
+
? { type: 'html', position: token.position, value: calcStringFromNodePoints(contents) }
|
|
485
|
+
: { type: 'html', value: calcStringFromNodePoints(contents) };
|
|
487
486
|
return node;
|
|
488
|
-
},
|
|
487
|
+
}),
|
|
489
488
|
};
|
|
490
489
|
};
|
|
491
490
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export { match as htmlBlockMatch } from './match';
|
|
|
4
4
|
export { parse as htmlBlockParse } from './parse';
|
|
5
5
|
export { HtmlBlockTokenizer, HtmlBlockTokenizer as default } from './tokenizer';
|
|
6
6
|
export { uniqueName as HtmlBlockTokenizerName } from './types';
|
|
7
|
-
export type {
|
|
7
|
+
export type { IThis as IHtmlBlockHookContext, IToken as IHtmlBlockToken, ITokenizerProps as IHtmlBlockTokenizerProps, } from './types';
|
package/lib/types/match.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IThis, IToken, T } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* An HTML block is a group of lines that is treated as raw HTML (and will not
|
|
5
5
|
* be escaped in HTML output).
|
|
@@ -7,4 +7,4 @@ import type { IHookContext, IToken, T } from './types';
|
|
|
7
7
|
* @see https://github.com/syntax-tree/mdast#html
|
|
8
8
|
* @see https://github.github.com/gfm/#html-blocks
|
|
9
9
|
*/
|
|
10
|
-
export declare const match: IMatchBlockHookCreator<T, IToken,
|
|
10
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
|
package/lib/types/parse.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const parse: IParseBlockHookCreator<T, IToken, INode,
|
|
2
|
+
import type { INode, IThis, IToken, T } from './types';
|
|
3
|
+
export declare const parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
3
|
-
import type {
|
|
3
|
+
import type { INode, IThis, IToken, ITokenizerProps, T } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Lexical Analyzer for HtmlBlock.
|
|
6
6
|
* @see https://github.com/syntax-tree/mdast#html
|
|
7
7
|
* @see https://github.github.com/gfm/#html-blocks
|
|
8
8
|
*/
|
|
9
|
-
export declare class HtmlBlockTokenizer extends BaseBlockTokenizer<T, IToken, INode,
|
|
9
|
+
export declare class HtmlBlockTokenizer extends BaseBlockTokenizer<T, IToken, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
|
|
10
10
|
constructor(props?: ITokenizerProps);
|
|
11
|
-
readonly match: IMatchBlockHookCreator<T, IToken,
|
|
12
|
-
readonly parse: IParseBlockHookCreator<T, IToken, INode,
|
|
11
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
|
|
12
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
|
13
13
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Html, HtmlType } from '@yozora/ast';
|
|
2
2
|
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = HtmlType;
|
|
4
|
-
export declare type INode =
|
|
4
|
+
export declare type INode = Html;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-html-block";
|
|
6
6
|
export declare type HtmlBlockConditionType = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
7
7
|
/**
|
|
@@ -60,5 +60,5 @@ export interface IToken extends IPartialYastBlockToken<T> {
|
|
|
60
60
|
*/
|
|
61
61
|
lines: Array<Readonly<IPhrasingContentLine>>;
|
|
62
62
|
}
|
|
63
|
-
export declare type
|
|
63
|
+
export declare type IThis = ITokenizer;
|
|
64
64
|
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-html-block",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "guanghechen",
|
|
6
6
|
"url": "https://github.com/guanghechen/"
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@yozora/ast": "^2.0.0
|
|
39
|
-
"@yozora/character": "^2.0.0
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.0
|
|
38
|
+
"@yozora/ast": "^2.0.0",
|
|
39
|
+
"@yozora/character": "^2.0.0",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "65e99d1709fdd1c918465dce6b1e91de96bdab5e"
|
|
43
43
|
}
|