@diplodoc/tabs-extension 3.10.8-transform5.1 → 3.10.8-transform5.3

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 CHANGED
@@ -89,6 +89,57 @@ Options:
89
89
  Example: `my-own-class and-other-class`<br>
90
90
  Default: `undefined`<br>
91
91
 
92
+ ### Colon directive syntax
93
+
94
+ Legacy `{% list tabs %}` remains the standalone default. Opt in at factory
95
+ creation with `transform({directiveSyntax: 'enabled'})` to accept both forms,
96
+ or use `directiveSyntax: 'only'` for colon directives only. The default
97
+ `'disabled'` retains the legacy-only, core-rule host contract; enabling a
98
+ directive requires a Markdown-it host with the block and inline capabilities
99
+ used by `@diplodoc/directive`.
100
+
101
+ ```markdown
102
+ :::tabs {variant=radio group="shared"}
103
+
104
+ - First
105
+
106
+ First body.
107
+
108
+ - Second {selected}
109
+
110
+ Second body.
111
+
112
+ :::
113
+ ```
114
+
115
+ The body uses the same Markdown lists and selected markers as legacy tabs.
116
+ `variant` is `regular` (the default), `radio`, `dropdown`, or `accordion`;
117
+ `group`, if present, must be nonempty. A valid but disabled variant falls back
118
+ to regular. Titles, destinations, unknown or repeated attributes, `#id` and
119
+ `.class` are unsupported. Invalid parameters remain ordinary Markdown. An
120
+ optional `onDiagnostic({line, reason})` reports rejected parameters with a
121
+ one-based line; it is not a general Markdown validator and does not promise a
122
+ diagnostic for every malformed or unclosed marker. Directive attributes do not
123
+ require general Markdown attributes to be enabled.
124
+
125
+ ### Inspect legacy boundaries
126
+
127
+ The pure `@diplodoc/tabs-extension/plugin` entry exports
128
+ `recognizeTabsBoundary(tokens, index)` alongside `transform`. Pass original
129
+ normalized block tokens before semantic core plugins run. The helper returns a
130
+ readonly observation with a copied line map and raw source marker, or
131
+ `undefined` when the candidate is not a recognized legacy boundary. An opening
132
+ reports whether a variant or group was authored; an authored group includes its
133
+ raw spelling and the value decoded by the existing Tabs parser. Unknown,
134
+ repeated, or ambiguous parameters are reported as unsupported. Missing group
135
+ and variant are distinct from explicitly authored defaults.
136
+
137
+ This observes one edge at a time, including unclosed openings. It does not pair
138
+ boundaries, validate nesting or body eligibility, allocate a default group ID,
139
+ render tokens, or modify the input. A caller that rewrites source must verify
140
+ matching scopes and renderer equivalence separately; line maps refer to the
141
+ parser's normalized input, not original byte offsets.
142
+
92
143
  ## API
93
144
 
94
145
  ### Syntax
@@ -0,0 +1,18 @@
1
+ import type { BlockContentState, DirectiveBlockState, DirectiveInlineState, DirectiveParserHost } from '@diplodoc/directive';
2
+ import { TabsVariants } from '../common';
3
+ export type TabsDirectiveDiagnostic = {
4
+ line: number;
5
+ reason: string;
6
+ };
7
+ export type TabsMarker = {
8
+ kind: 'open';
9
+ end: object;
10
+ variant: TabsVariants;
11
+ group?: string;
12
+ } | {
13
+ kind: 'close';
14
+ };
15
+ export declare function installTabsDirective<B extends DirectiveBlockState & BlockContentState<B>, I extends DirectiveInlineState>(md: DirectiveParserHost<B, I>, markers: WeakMap<object, TabsMarker>, onDiagnostic?: (diagnostic: TabsDirectiveDiagnostic) => void): void;
16
+ export declare function validateTabsMarkers(tokens: readonly {
17
+ type: string;
18
+ }[], markers: WeakMap<object, TabsMarker>): void;
@@ -5,6 +5,17 @@ import type { StateCore, Token } from './markdown-it';
5
5
  */
6
6
  import type { RuntimeTab, TabsProps } from './types';
7
7
  import type { IDGenerator } from '@diplodoc/utils';
8
+ export type TabsBoundaryToken = {
9
+ readonly type: string;
10
+ readonly content: string;
11
+ readonly map: readonly [number, number] | null;
12
+ };
13
+ /**
14
+ * Allocate a default group even when a source provides an explicit group.
15
+ * @param generateID - Per-file ID generator
16
+ * @returns Generated default group
17
+ */
18
+ export declare function defaultTabsGroup(generateID: IDGenerator): string;
8
19
  /**
9
20
  * Parse `{% list tabs group=... %}` content into variant and group id.
10
21
  * @param content - Raw tag content after "list tabs"
@@ -12,6 +23,34 @@ import type { IDGenerator } from '@diplodoc/utils';
12
23
  * @returns Parsed props (variant, group)
13
24
  */
14
25
  export declare function props(content: string, generateID: IDGenerator): TabsProps;
26
+ export type TabsBoundary = {
27
+ readonly map: readonly [number, number] | null;
28
+ readonly raw: string;
29
+ } & ({
30
+ readonly kind: 'open';
31
+ readonly variant: {
32
+ readonly present: false;
33
+ } | {
34
+ readonly present: true;
35
+ readonly raw: string;
36
+ };
37
+ readonly group: {
38
+ readonly present: false;
39
+ } | {
40
+ readonly present: true;
41
+ readonly raw: string;
42
+ readonly value: string;
43
+ };
44
+ } | {
45
+ readonly kind: 'close' | 'unsupported';
46
+ });
47
+ /**
48
+ * Classify one original block edge without pairing it or validating the body.
49
+ * @param tokens - Original pre-semantic block tokens.
50
+ * @param i - Candidate paragraph index.
51
+ * @returns A copied boundary observation when recognized.
52
+ */
53
+ export declare function recognizeTabsBoundary(tokens: readonly TabsBoundaryToken[], i: number): TabsBoundary | undefined;
15
54
  type Result = {
16
55
  step: number;
17
56
  } | {
@@ -32,7 +71,8 @@ export declare function tryToFindTabs(tokens: Token[], index: number): Result;
32
71
  * @param idx - Index after list open
33
72
  * @param closeTokenIdx - Index of {% endlist %} paragraph
34
73
  * @param TokenConstructor - Token constructor from the current MarkdownIt state
74
+ * @param end - Exclusive scan bound
35
75
  * @returns Array of RuntimeTab
36
76
  */
37
- export declare function findTabs(tokens: Token[], idx: number, closeTokenIdx: number, TokenConstructor: StateCore['Token']): RuntimeTab[];
77
+ export declare function findTabs(tokens: Token[], idx: number, closeTokenIdx: number, TokenConstructor: StateCore['Token'], end: number): RuntimeTab[];
38
78
  export {};
@@ -1,3 +1,9 @@
1
- import { type PluginOptions, type TabsPlugin } from './transform';
1
+ import type { PluginOptions, TabsDirectivePlugin, TabsPlugin } from './transform';
2
2
  export * from './index';
3
- export declare function transform(options?: Partial<PluginOptions>): TabsPlugin;
3
+ export declare function transform(options?: Partial<PluginOptions> & {
4
+ directiveSyntax?: 'disabled';
5
+ }): TabsPlugin;
6
+ export declare function transform(options: Partial<PluginOptions> & {
7
+ directiveSyntax: 'enabled' | 'only';
8
+ }): TabsDirectivePlugin;
9
+ export declare function transform(options: Partial<PluginOptions>): TabsDirectivePlugin;