@diplodoc/folding-headings-extension 0.1.2 → 0.2.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 +7 -2
- package/build/plugin/index.js +98 -87
- package/build/plugin/index.js.map +3 -3
- package/build/runtime/index.css +1 -1
- package/build/runtime/index.css.map +3 -3
- package/build/runtime/index.js +1 -1
- package/build/runtime/index.js.map +2 -2
- package/build/src/plugin/plugin.d.ts +12 -0
- package/build/src/plugin/sectionsCoreRule.d.ts +10 -0
- package/build/{plugin → src/plugin}/transform.d.ts +2 -0
- package/build/{plugin → src/plugin}/utils.d.ts +1 -2
- package/build/test/data.d.ts +147 -0
- package/build/test/plugin.spec.d.ts +1 -0
- package/package.json +21 -17
- package/build/plugin/plugin.d.ts +0 -2
- package/build/plugin/sectionsCoreRule.d.ts +0 -2
- /package/build/{common → src/common}/const.d.ts +0 -0
- /package/build/{plugin → src/plugin}/const.d.ts +0 -0
- /package/build/{plugin → src/plugin}/headingBlockRule.d.ts +0 -0
- /package/build/{plugin → src/plugin}/index.d.ts +0 -0
- /package/build/{runtime → src/runtime}/const.d.ts +0 -0
- /package/build/{runtime → src/runtime}/controller.d.ts +0 -0
- /package/build/{runtime → src/runtime}/index.d.ts +0 -0
- /package/build/{runtime → src/runtime}/utils.d.ts +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
# Diplodoc folding headings
|
|
2
|
-
|
|
3
1
|
[](https://www.npmjs.org/package/@diplodoc/folding-headings-extension)
|
|
2
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_folding-headings-extension)
|
|
3
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_folding-headings-extension)
|
|
4
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_folding-headings-extension)
|
|
5
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_folding-headings-extension)
|
|
6
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_folding-headings-extension)
|
|
7
|
+
|
|
8
|
+
# Diplodoc folding headings
|
|
4
9
|
|
|
5
10
|
This is an extension of the Diplodoc platform, which allows adding folding headings in the documentation.
|
|
6
11
|
|
package/build/plugin/index.js
CHANGED
|
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/plugin/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
TokenType: () => TokenType,
|
|
24
24
|
transform: () => transform
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
|
|
28
28
|
// src/common/const.ts
|
|
29
29
|
var DATA_KEY = "heading-section";
|
|
@@ -105,10 +105,10 @@ var headingBlockRule = (state, startLine, _endLine, silent) => {
|
|
|
105
105
|
return true;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
// src/plugin/sectionsCoreRule.ts
|
|
109
|
+
var import_utils = require("@diplodoc/utils");
|
|
110
|
+
|
|
108
111
|
// src/plugin/utils.ts
|
|
109
|
-
function generateID() {
|
|
110
|
-
return DATA_KEY + "-" + Math.random().toString(36).substr(2, 8);
|
|
111
|
-
}
|
|
112
112
|
function headingLevel(header) {
|
|
113
113
|
return parseInt(header.charAt(1), 10);
|
|
114
114
|
}
|
|
@@ -150,100 +150,110 @@ function dynrequire(module) {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// src/plugin/sectionsCoreRule.ts
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
function createSectionsCoreRule(externalGenerateID) {
|
|
154
|
+
const generateID = externalGenerateID ?? (0, import_utils.createIDGeneratorByStrategy)("random");
|
|
155
|
+
return (state) => {
|
|
156
|
+
const Token = state.Token;
|
|
157
|
+
const tokens = [];
|
|
158
|
+
const sections = [];
|
|
159
|
+
let nestedLevel = 0;
|
|
160
|
+
for (const token of state.tokens) {
|
|
161
|
+
if (token.type.search(TokenType.Heading) !== 0) {
|
|
162
|
+
nestedLevel += token.nesting;
|
|
163
|
+
}
|
|
164
|
+
if (last(sections) && nestedLevel < last(sections).nesting) {
|
|
165
|
+
closeSectionsToCurrentNesting(nestedLevel);
|
|
166
|
+
}
|
|
167
|
+
const hasFolding = token.markup.endsWith("#+");
|
|
168
|
+
if (token.type === TokenType.HeadingOpen) {
|
|
169
|
+
const section = {
|
|
170
|
+
header: headingLevel(token.tag),
|
|
171
|
+
nesting: nestedLevel
|
|
172
|
+
};
|
|
173
|
+
closeSections(section);
|
|
174
|
+
if (hasFolding) {
|
|
175
|
+
tokens.push(openSection());
|
|
176
|
+
sections.push(section);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
tokens.push(token);
|
|
180
|
+
if (token.type === TokenType.HeadingClose && hasFolding) {
|
|
181
|
+
tokens.push(openContent());
|
|
182
|
+
}
|
|
161
183
|
}
|
|
162
|
-
|
|
163
|
-
|
|
184
|
+
closeAllSections();
|
|
185
|
+
if (state.tokens.length !== tokens.length) {
|
|
186
|
+
state.env ??= {};
|
|
187
|
+
state.env[ENV_FLAG_NAME] = true;
|
|
164
188
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
tokens.push(openSection());
|
|
174
|
-
sections.push(section);
|
|
175
|
-
}
|
|
189
|
+
state.tokens = tokens;
|
|
190
|
+
function openSection() {
|
|
191
|
+
const t = new Token(TokenType.SectionOpen, "section", 1);
|
|
192
|
+
t.attrPush(["class", SectionCN.Section]);
|
|
193
|
+
t.attrPush([SectionAttr.DataKey, DATA_KEY]);
|
|
194
|
+
t.attrPush([SectionAttr.DataId, generateID(DATA_KEY)]);
|
|
195
|
+
t.block = true;
|
|
196
|
+
return t;
|
|
176
197
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
function closeSection() {
|
|
199
|
+
const t = new Token(TokenType.SectionClose, "section", -1);
|
|
200
|
+
t.block = true;
|
|
201
|
+
return t;
|
|
180
202
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
state.tokens = tokens;
|
|
188
|
-
function openSection() {
|
|
189
|
-
const t = new Token(TokenType.SectionOpen, "section", 1);
|
|
190
|
-
t.attrPush(["class", SectionCN.Section]);
|
|
191
|
-
t.attrPush([SectionAttr.DataKey, DATA_KEY]);
|
|
192
|
-
t.attrPush([SectionAttr.DataId, generateID()]);
|
|
193
|
-
t.block = true;
|
|
194
|
-
return t;
|
|
195
|
-
}
|
|
196
|
-
function closeSection() {
|
|
197
|
-
const t = new Token(TokenType.SectionClose, "section", -1);
|
|
198
|
-
t.block = true;
|
|
199
|
-
return t;
|
|
200
|
-
}
|
|
201
|
-
function openContent() {
|
|
202
|
-
const t = new Token(TokenType.ContentOpen, "div", 1);
|
|
203
|
-
t.attrPush(["class", SectionCN.Content]);
|
|
204
|
-
t.block = true;
|
|
205
|
-
return t;
|
|
206
|
-
}
|
|
207
|
-
function closeContent() {
|
|
208
|
-
const t = new Token(TokenType.ContentClose, "div", -1);
|
|
209
|
-
t.block = true;
|
|
210
|
-
return t;
|
|
211
|
-
}
|
|
212
|
-
function closeSections(section) {
|
|
213
|
-
while (last(sections) && section.header <= last(sections).header && section.nesting <= last(sections).nesting) {
|
|
214
|
-
sections.pop();
|
|
215
|
-
tokens.push(closeContent());
|
|
216
|
-
tokens.push(closeSection());
|
|
203
|
+
function openContent() {
|
|
204
|
+
const t = new Token(TokenType.ContentOpen, "div", 1);
|
|
205
|
+
t.attrPush(["class", SectionCN.Content]);
|
|
206
|
+
t.block = true;
|
|
207
|
+
return t;
|
|
217
208
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
tokens.push(closeContent());
|
|
223
|
-
tokens.push(closeSection());
|
|
209
|
+
function closeContent() {
|
|
210
|
+
const t = new Token(TokenType.ContentClose, "div", -1);
|
|
211
|
+
t.block = true;
|
|
212
|
+
return t;
|
|
224
213
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
214
|
+
function closeSections(section) {
|
|
215
|
+
while (last(sections) && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
216
|
+
section.header <= last(sections).header && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
217
|
+
section.nesting <= last(sections).nesting) {
|
|
218
|
+
sections.pop();
|
|
219
|
+
tokens.push(closeContent());
|
|
220
|
+
tokens.push(closeSection());
|
|
221
|
+
}
|
|
230
222
|
}
|
|
231
|
-
|
|
232
|
-
|
|
223
|
+
function closeSectionsToCurrentNesting(nesting) {
|
|
224
|
+
while (last(sections) && nesting < last(sections).nesting) {
|
|
225
|
+
sections.pop();
|
|
226
|
+
tokens.push(closeContent());
|
|
227
|
+
tokens.push(closeSection());
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function closeAllSections() {
|
|
231
|
+
while (sections.pop()) {
|
|
232
|
+
tokens.push(closeContent());
|
|
233
|
+
tokens.push(closeSection());
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
233
238
|
|
|
234
239
|
// src/plugin/plugin.ts
|
|
235
|
-
|
|
236
|
-
md
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
function createFoldingHeadingPlugin(generateID) {
|
|
241
|
+
return (md) => {
|
|
242
|
+
md.block.ruler.at("heading", headingBlockRule, {
|
|
243
|
+
alt: ["paragraph", "reference", "blockquote"]
|
|
244
|
+
});
|
|
245
|
+
md.core.ruler.push("heading_sections", createSectionsCoreRule(generateID));
|
|
246
|
+
};
|
|
247
|
+
}
|
|
239
248
|
|
|
240
249
|
// src/plugin/transform.ts
|
|
241
250
|
var registerTransform = (md, {
|
|
242
251
|
runtime,
|
|
243
252
|
bundle,
|
|
244
|
-
output
|
|
253
|
+
output,
|
|
254
|
+
generateID
|
|
245
255
|
}) => {
|
|
246
|
-
md.use(
|
|
256
|
+
md.use(createFoldingHeadingPlugin(generateID));
|
|
247
257
|
md.core.ruler.push("heading_sections_after", ({ env }) => {
|
|
248
258
|
hidden(env, "bundled", /* @__PURE__ */ new Set());
|
|
249
259
|
if (env?.[ENV_FLAG_NAME]) {
|
|
@@ -267,11 +277,12 @@ function transform(options = {}) {
|
|
|
267
277
|
script: "_assets/folding-headings-extension.js",
|
|
268
278
|
style: "_assets/folding-headings-extension.css"
|
|
269
279
|
};
|
|
270
|
-
const plugin = function(md, { output = "." } = {}) {
|
|
280
|
+
const plugin = function(md, { output = ".", generateID } = {}) {
|
|
271
281
|
registerTransform(md, {
|
|
272
282
|
runtime,
|
|
273
283
|
bundle,
|
|
274
|
-
output
|
|
284
|
+
output,
|
|
285
|
+
generateID
|
|
275
286
|
});
|
|
276
287
|
};
|
|
277
288
|
Object.assign(plugin, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/plugin/index.ts", "../../src/common/const.ts", "../../src/plugin/const.ts", "../../src/plugin/headingBlockRule.ts", "../../src/plugin/
|
|
4
|
-
"sourcesContent": ["export type {TransformOptions} from './transform';\nexport {transform} from './transform';\nexport {TokenType} from './const';\n", "export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionCN, DATA_KEY, SectionAttr} from '../common/const';\n\nexport const ENV_FLAG_NAME = 'has-folding-headings';\n\nexport const TokenType = {\n Heading: 'heading',\n HeadingOpen: 'heading_open',\n HeadingClose: 'heading_close',\n Section: 'heading_section',\n SectionOpen: 'heading_section_open',\n SectionClose: 'heading_section_close',\n Content: 'heading_section_content',\n ContentOpen: 'heading_section_content_open',\n ContentClose: 'heading_section_content_close',\n} as const;\n", "import type ParserBlock from 'markdown-it/lib/parser_block';\n\nimport {TokenType} from './const';\n\n// copied from https://github.com/markdown-it/markdown-it/blob/14.1.0/lib/rules_block/heading.mjs\n// modified: support syntax ###+ for folding headings\nexport const headingBlockRule: ParserBlock.RuleBlock = (state, startLine, _endLine, silent) => {\n const {isSpace} = state.md.utils;\n\n let pos = state.bMarks[startLine] + state.tShift[startLine];\n let max = state.eMarks[startLine];\n\n // if it's indented more than 3 spaces, it should be a code block\n if (state.sCount[startLine] - state.blkIndent >= 4) {\n return false;\n }\n\n let ch = state.src.charCodeAt(pos);\n\n if (ch !== 0x23 /* # */ || pos >= max) {\n return false;\n }\n\n // count heading level\n let level = 1;\n ch = state.src.charCodeAt(++pos);\n while (ch === 0x23 /* # */ && pos < max && level <= 6) {\n level++;\n ch = state.src.charCodeAt(++pos);\n }\n\n let folding = false;\n if (ch === 0x2b /* + */) {\n folding = true;\n ch = state.src.charCodeAt(++pos);\n }\n\n if (level > 6 || (pos < max && !isSpace(ch))) {\n return false;\n }\n\n if (silent) {\n return true;\n }\n\n // Let's cut tails like ' ### ' from the end of string\n\n max = state.skipSpacesBack(max, pos);\n const tmp = state.skipCharsBack(max, 0x23, pos); // #\n if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {\n max = tmp;\n }\n\n state.line = startLine + 1;\n\n let token = state.push(TokenType.HeadingOpen, 'h' + String(level), 1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n token.map = [startLine, state.line];\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n token = state.push('inline', '', 0);\n token.content = state.src.slice(pos, max).trim();\n token.map = [startLine, state.line];\n token.children = [];\n\n token = state.push(TokenType.HeadingClose, 'h' + String(level), -1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n return true;\n};\n", "import {DATA_KEY} from './const';\n\nexport function generateID() {\n return DATA_KEY + '-' + Math.random().toString(36).substr(2, 8);\n}\n\nexport function headingLevel(header: string) {\n return parseInt(header.charAt(1), 10);\n}\n\nexport function last<T>(arr: T[]): T | undefined {\n return arr[arr.length - 1];\n}\n\nexport function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(\n box: B,\n field: F,\n value: V,\n) {\n if (!(field in box)) {\n Object.defineProperty(box, field, {\n enumerable: false,\n value: value,\n });\n }\n\n return box as B & {[P in F]: V};\n}\n\nexport type Runtime = {\n script: string;\n style: string;\n};\n\ndeclare const __dirname: string;\nexport function copyRuntime(\n {runtime, output}: {runtime: Runtime; output: string},\n cache: Set<string>,\n) {\n const PATH_TO_RUNTIME = '../runtime';\n const {join, resolve} = dynrequire('node:path');\n const runtimeFiles = {\n 'index.js': runtime.script,\n 'index.css': runtime.style,\n };\n for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {\n const file = join(PATH_TO_RUNTIME, originFile);\n if (!cache.has(file)) {\n cache.add(file);\n copy(resolve(__dirname, file), join(output, outputFile));\n }\n }\n}\n\nexport function copy(from: string, to: string) {\n const {mkdirSync, copyFileSync} = dynrequire('node:fs');\n const {dirname} = dynrequire('node:path');\n\n mkdirSync(dirname(to), {recursive: true});\n copyFileSync(from, to);\n}\n\n/*\n * Runtime require hidden for builders.\n * Used for nodejs api\n */\nexport function dynrequire(module: string) {\n return eval(`require('${module}')`);\n}\n", "import type Core from 'markdown-it/lib/parser_core';\n\nimport {DATA_KEY, ENV_FLAG_NAME, SectionAttr, SectionCN, TokenType} from './const';\nimport {generateID, headingLevel, last} from './utils';\n\ntype Section = {header: number; nesting: number};\n\nexport const sectionsCoreRule: Core.RuleCore = (state) => {\n const Token = state.Token;\n const tokens: typeof state.tokens = []; // output\n const sections: Section[] = [];\n let nestedLevel = 0;\n\n for (const token of state.tokens) {\n // record level of nesting\n if (token.type.search(TokenType.Heading) !== 0) {\n nestedLevel += token.nesting;\n }\n if (last(sections) && nestedLevel < last(sections)!.nesting) {\n closeSectionsToCurrentNesting(nestedLevel);\n }\n\n const hasFolding = token.markup.endsWith('#+');\n\n // add sections before headers\n if (token.type === TokenType.HeadingOpen) {\n const section: Section = {\n header: headingLevel(token.tag),\n nesting: nestedLevel,\n };\n closeSections(section);\n if (hasFolding) {\n tokens.push(openSection());\n sections.push(section);\n }\n }\n\n tokens.push(token);\n\n if (token.type === TokenType.HeadingClose && hasFolding) {\n tokens.push(openContent());\n }\n }\n\n // end for every token\n closeAllSections();\n\n if (state.tokens.length !== tokens.length) {\n state.env ??= {};\n state.env[ENV_FLAG_NAME] = true;\n }\n\n state.tokens = tokens;\n\n function openSection() {\n const t = new Token(TokenType.SectionOpen, 'section', 1);\n t.attrPush(['class', SectionCN.Section]);\n t.attrPush([SectionAttr.DataKey, DATA_KEY]);\n t.attrPush([SectionAttr.DataId, generateID()]);\n t.block = true;\n return t;\n }\n\n function closeSection() {\n const t = new Token(TokenType.SectionClose, 'section', -1);\n t.block = true;\n return t;\n }\n\n function openContent() {\n const t = new Token(TokenType.ContentOpen, 'div', 1);\n t.attrPush(['class', SectionCN.Content]);\n t.block = true;\n return t;\n }\n\n function closeContent() {\n const t = new Token(TokenType.ContentClose, 'div', -1);\n t.block = true;\n return t;\n }\n\n function closeSections(section: Section) {\n while (\n last(sections) &&\n section.header <= last(sections)!.header &&\n section.nesting <= last(sections)!.nesting\n ) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeSectionsToCurrentNesting(nesting: number) {\n while (last(sections) && nesting < last(sections)!.nesting) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeAllSections() {\n while (sections.pop()) {\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n};\n", "import type {PluginSimple} from 'markdown-it';\n\nimport {headingBlockRule} from './headingBlockRule';\nimport {sectionsCoreRule} from './sectionsCoreRule';\n\nexport const foldingHeadingPlugin: PluginSimple = (md) => {\n md.block.ruler.at('heading', headingBlockRule, {alt: ['paragraph', 'reference', 'blockquote']});\n md.core.ruler.push('heading_sections', sectionsCoreRule);\n};\n", "import type MarkdownIt from 'markdown-it';\nimport {PluginWithOptions} from 'markdown-it';\n\nimport {ENV_FLAG_NAME} from './const';\nimport {foldingHeadingPlugin} from './plugin';\nimport {type Runtime, copyRuntime, dynrequire, hidden} from './utils';\n\nconst registerTransform = (\n md: MarkdownIt,\n {\n runtime,\n bundle,\n output,\n }: Pick<NormalizedPluginOptions, 'bundle' | 'runtime'> & {\n output: string;\n },\n) => {\n md.use(foldingHeadingPlugin);\n md.core.ruler.push('heading_sections_after', ({env}) => {\n hidden(env, 'bundled', new Set<string>());\n\n if (env?.[ENV_FLAG_NAME]) {\n env.meta = env.meta || {};\n env.meta.script = env.meta.script || [];\n env.meta.script.push(runtime.script);\n env.meta.style = env.meta.style || [];\n env.meta.style.push(runtime.style);\n\n if (bundle) {\n copyRuntime({runtime, output}, env.bundled);\n }\n }\n });\n};\n\ntype NormalizedPluginOptions = Omit<TransformOptions, 'runtime'> & {\n runtime: Runtime;\n};\n\nexport type TransformOptions = {\n runtime?:\n | string\n | {\n script: string;\n style: string;\n };\n bundle?: boolean;\n};\n\ntype InputOptions = {\n destRoot: string;\n};\n\nexport function transform(options: Partial<TransformOptions> = {}) {\n const {bundle = true} = options;\n\n if (bundle && typeof options.runtime === 'string') {\n throw new TypeError('Option `runtime` should be record when `bundle` is enabled.');\n }\n\n const runtime: Runtime =\n typeof options.runtime === 'string'\n ? {script: options.runtime, style: options.runtime}\n : options.runtime || {\n script: '_assets/folding-headings-extension.js',\n style: '_assets/folding-headings-extension.css',\n };\n\n const plugin: PluginWithOptions<{output?: string}> = function (\n md: MarkdownIt,\n {output = '.'} = {},\n ) {\n registerTransform(md, {\n runtime,\n bundle,\n output,\n });\n };\n\n Object.assign(plugin, {\n collect(input: string, {destRoot = '.'}: InputOptions) {\n const MdIt = dynrequire('markdown-it');\n const md = new MdIt().use((md: MarkdownIt) => {\n registerTransform(md, {\n runtime,\n bundle,\n output: destRoot,\n });\n });\n\n md.parse(input, {});\n },\n });\n\n return plugin;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AAEjB,IAAM,cAAc;AAAA,EACvB,QAAQ;AAAA,EACR,SAAS;AACb;AAEO,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,SAAS;AACb;;;ACRO,IAAM,gBAAgB;AAEtB,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAClB;;;ACRO,IAAM,mBAA0C,CAAC,OAAO,WAAW,UAAU,WAAW;AAC3F,QAAM,EAAC,QAAO,IAAI,MAAM,GAAG;AAE3B,MAAI,MAAM,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,SAAS;AAC1D,MAAI,MAAM,MAAM,OAAO,SAAS;AAGhC,MAAI,MAAM,OAAO,SAAS,IAAI,MAAM,aAAa,GAAG;AAChD,WAAO;AAAA,EACX;AAEA,MAAI,KAAK,MAAM,IAAI,WAAW,GAAG;AAEjC,MAAI,OAAO,MAAgB,OAAO,KAAK;AACnC,WAAO;AAAA,EACX;AAGA,MAAI,QAAQ;AACZ,OAAK,MAAM,IAAI,WAAW,EAAE,GAAG;AAC/B,SAAO,OAAO,MAAgB,MAAM,OAAO,SAAS,GAAG;AACnD;AACA,SAAK,MAAM,IAAI,WAAW,EAAE,GAAG;AAAA,EACnC;AAEA,MAAI,UAAU;AACd,MAAI,OAAO,IAAc;AACrB,cAAU;AACV,SAAK,MAAM,IAAI,WAAW,EAAE,GAAG;AAAA,EACnC;AAEA,MAAI,QAAQ,KAAM,MAAM,OAAO,CAAC,QAAQ,EAAE,GAAI;AAC1C,WAAO;AAAA,EACX;AAEA,MAAI,QAAQ;AACR,WAAO;AAAA,EACX;AAIA,QAAM,MAAM,eAAe,KAAK,GAAG;AACnC,QAAM,MAAM,MAAM,cAAc,KAAK,IAAM,GAAG;AAC9C,MAAI,MAAM,OAAO,QAAQ,MAAM,IAAI,WAAW,MAAM,CAAC,CAAC,GAAG;AACrD,UAAM;AAAA,EACV;AAEA,QAAM,OAAO,YAAY;AAEzB,MAAI,QAAQ,MAAM,KAAK,UAAU,aAAa,MAAM,OAAO,KAAK,GAAG,CAAC;AACpE,QAAM,SAAS,WAAW,MAAM,GAAG,KAAK,KAAK,UAAU,MAAM;AAC7D,QAAM,MAAM,CAAC,WAAW,MAAM,IAAI;AAClC,MAAI,SAAS;AACT,UAAM,SAAS,CAAC;AAChB,UAAM,KAAK,UAAU;AAAA,EACzB;AAEA,UAAQ,MAAM,KAAK,UAAU,IAAI,CAAC;AAClC,QAAM,UAAU,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE,KAAK;AAC/C,QAAM,MAAM,CAAC,WAAW,MAAM,IAAI;AAClC,QAAM,WAAW,CAAC;AAElB,UAAQ,MAAM,KAAK,UAAU,cAAc,MAAM,OAAO,KAAK,GAAG,EAAE;AAClE,QAAM,SAAS,WAAW,MAAM,GAAG,KAAK,KAAK,UAAU,MAAM;AAC7D,MAAI,SAAS;AACT,UAAM,SAAS,CAAC;AAChB,UAAM,KAAK,UAAU;AAAA,EACzB;AAEA,SAAO;AACX;;;
|
|
3
|
+
"sources": ["../../src/plugin/index.ts", "../../src/common/const.ts", "../../src/plugin/const.ts", "../../src/plugin/headingBlockRule.ts", "../../src/plugin/sectionsCoreRule.ts", "../../src/plugin/utils.ts", "../../src/plugin/plugin.ts", "../../src/plugin/transform.ts"],
|
|
4
|
+
"sourcesContent": ["export type {TransformOptions} from './transform';\nexport {transform} from './transform';\nexport {TokenType} from './const';\n", "export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionCN, DATA_KEY, SectionAttr} from '../common/const';\n\nexport const ENV_FLAG_NAME = 'has-folding-headings';\n\nexport const TokenType = {\n Heading: 'heading',\n HeadingOpen: 'heading_open',\n HeadingClose: 'heading_close',\n Section: 'heading_section',\n SectionOpen: 'heading_section_open',\n SectionClose: 'heading_section_close',\n Content: 'heading_section_content',\n ContentOpen: 'heading_section_content_open',\n ContentClose: 'heading_section_content_close',\n} as const;\n", "import type ParserBlock from 'markdown-it/lib/parser_block';\n\nimport {TokenType} from './const';\n\n// copied from https://github.com/markdown-it/markdown-it/blob/14.1.0/lib/rules_block/heading.mjs\n// modified: support syntax ###+ for folding headings\nexport const headingBlockRule: ParserBlock.RuleBlock = (state, startLine, _endLine, silent) => {\n const {isSpace} = state.md.utils;\n\n let pos = state.bMarks[startLine] + state.tShift[startLine];\n let max = state.eMarks[startLine];\n\n // if it's indented more than 3 spaces, it should be a code block\n if (state.sCount[startLine] - state.blkIndent >= 4) {\n return false;\n }\n\n let ch = state.src.charCodeAt(pos);\n\n if (ch !== 0x23 /* # */ || pos >= max) {\n return false;\n }\n\n // count heading level\n let level = 1;\n ch = state.src.charCodeAt(++pos);\n while (ch === 0x23 /* # */ && pos < max && level <= 6) {\n level++;\n ch = state.src.charCodeAt(++pos);\n }\n\n let folding = false;\n if (ch === 0x2b /* + */) {\n folding = true;\n ch = state.src.charCodeAt(++pos);\n }\n\n if (level > 6 || (pos < max && !isSpace(ch))) {\n return false;\n }\n\n if (silent) {\n return true;\n }\n\n // Let's cut tails like ' ### ' from the end of string\n\n max = state.skipSpacesBack(max, pos);\n const tmp = state.skipCharsBack(max, 0x23, pos); // #\n if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {\n max = tmp;\n }\n\n state.line = startLine + 1;\n\n let token = state.push(TokenType.HeadingOpen, 'h' + String(level), 1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n token.map = [startLine, state.line];\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n token = state.push('inline', '', 0);\n token.content = state.src.slice(pos, max).trim();\n token.map = [startLine, state.line];\n token.children = [];\n\n token = state.push(TokenType.HeadingClose, 'h' + String(level), -1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n return true;\n};\n", "import type Core from 'markdown-it/lib/parser_core';\nimport type {IDGenerator} from '@diplodoc/utils';\n\nimport {createIDGeneratorByStrategy} from '@diplodoc/utils';\n\nimport {DATA_KEY, ENV_FLAG_NAME, SectionAttr, SectionCN, TokenType} from './const';\nimport {headingLevel, last} from './utils';\n\ntype Section = {header: number; nesting: number};\n\n/**\n * Creates a core rule that wraps folding headings in `<section>` elements with unique IDs.\n * @param externalGenerateID - Optional external ID generator (e.g. from MarkdownItPluginOpts).\n * When provided, ensures all plugins share the same per-file generator.\n * When omitted, uses random fallback behavior.\n * @returns Markdown-it core rule that injects section wrapper tokens around folding headings.\n */\nexport function createSectionsCoreRule(externalGenerateID?: IDGenerator): Core.RuleCore {\n // Use the external generator if provided, otherwise use random fallback.\n // Random IDs are the default behavior for production builds.\n const generateID: IDGenerator =\n externalGenerateID ?? (createIDGeneratorByStrategy('random') as IDGenerator);\n\n return (state) => {\n const Token = state.Token;\n const tokens: typeof state.tokens = []; // output\n const sections: Section[] = [];\n let nestedLevel = 0;\n\n for (const token of state.tokens) {\n // record level of nesting\n if (token.type.search(TokenType.Heading) !== 0) {\n nestedLevel += token.nesting;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (last(sections) && nestedLevel < last(sections)!.nesting) {\n closeSectionsToCurrentNesting(nestedLevel);\n }\n\n const hasFolding = token.markup.endsWith('#+');\n\n // add sections before headers\n if (token.type === TokenType.HeadingOpen) {\n const section: Section = {\n header: headingLevel(token.tag),\n nesting: nestedLevel,\n };\n closeSections(section);\n if (hasFolding) {\n tokens.push(openSection());\n sections.push(section);\n }\n }\n\n tokens.push(token);\n\n if (token.type === TokenType.HeadingClose && hasFolding) {\n tokens.push(openContent());\n }\n }\n\n // end for every token\n closeAllSections();\n\n if (state.tokens.length !== tokens.length) {\n state.env ??= {};\n state.env[ENV_FLAG_NAME] = true;\n }\n\n state.tokens = tokens;\n\n function openSection() {\n const t = new Token(TokenType.SectionOpen, 'section', 1);\n t.attrPush(['class', SectionCN.Section]);\n t.attrPush([SectionAttr.DataKey, DATA_KEY]);\n t.attrPush([SectionAttr.DataId, generateID(DATA_KEY)]);\n t.block = true;\n return t;\n }\n\n function closeSection() {\n const t = new Token(TokenType.SectionClose, 'section', -1);\n t.block = true;\n return t;\n }\n\n function openContent() {\n const t = new Token(TokenType.ContentOpen, 'div', 1);\n t.attrPush(['class', SectionCN.Content]);\n t.block = true;\n return t;\n }\n\n function closeContent() {\n const t = new Token(TokenType.ContentClose, 'div', -1);\n t.block = true;\n return t;\n }\n\n function closeSections(section: Section) {\n while (\n last(sections) &&\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n section.header <= last(sections)!.header &&\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n section.nesting <= last(sections)!.nesting\n ) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeSectionsToCurrentNesting(nesting: number) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n while (last(sections) && nesting < last(sections)!.nesting) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeAllSections() {\n while (sections.pop()) {\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n };\n}\n", "export function headingLevel(header: string) {\n return parseInt(header.charAt(1), 10);\n}\n\nexport function last<T>(arr: T[]): T | undefined {\n return arr[arr.length - 1];\n}\n\nexport function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(\n box: B,\n field: F,\n value: V,\n) {\n if (!(field in box)) {\n Object.defineProperty(box, field, {\n enumerable: false,\n value: value,\n });\n }\n\n return box as B & Record<F, V>;\n}\n\nexport type Runtime = {\n script: string;\n style: string;\n};\n\ndeclare const __dirname: string;\nexport function copyRuntime(\n {runtime, output}: {runtime: Runtime; output: string},\n cache: Set<string>,\n) {\n const PATH_TO_RUNTIME = '../runtime';\n const {join, resolve} = dynrequire('node:path');\n const runtimeFiles = {\n 'index.js': runtime.script,\n 'index.css': runtime.style,\n };\n for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {\n const file = join(PATH_TO_RUNTIME, originFile);\n if (!cache.has(file)) {\n cache.add(file);\n copy(resolve(__dirname, file), join(output, outputFile));\n }\n }\n}\n\nexport function copy(from: string, to: string) {\n const {mkdirSync, copyFileSync} = dynrequire('node:fs');\n const {dirname} = dynrequire('node:path');\n\n mkdirSync(dirname(to), {recursive: true});\n copyFileSync(from, to);\n}\n\n/*\n * Runtime require hidden for builders.\n * Used for nodejs api\n */\nexport function dynrequire(module: string) {\n // eslint-disable-next-line no-eval\n return eval(`require('${module}')`);\n}\n", "import type MarkdownIt from 'markdown-it';\nimport type {IDGenerator} from '@diplodoc/utils';\n\nimport {headingBlockRule} from './headingBlockRule';\nimport {createSectionsCoreRule} from './sectionsCoreRule';\n\n/**\n * Creates a folding-heading plugin with an optional external ID generator.\n * When `generateID` is provided, all generated section IDs share the same counter\n * as other plugins, ensuring deterministic output regardless of --merge-includes.\n * When omitted, the plugin uses its internal fallback generator.\n *\n * @param generateID - Optional external ID generator shared with the rest of the transform pipeline.\n * @returns Markdown-it plugin that registers folding heading parsing and section wrapping rules.\n */\nexport function createFoldingHeadingPlugin(generateID?: IDGenerator) {\n return (md: MarkdownIt) => {\n md.block.ruler.at('heading', headingBlockRule, {\n alt: ['paragraph', 'reference', 'blockquote'],\n });\n md.core.ruler.push('heading_sections', createSectionsCoreRule(generateID));\n };\n}\n", "import type MarkdownIt from 'markdown-it';\nimport type {PluginWithOptions} from 'markdown-it';\nimport type {IDGenerator} from '@diplodoc/utils';\n\nimport {ENV_FLAG_NAME} from './const';\nimport {createFoldingHeadingPlugin} from './plugin';\nimport {type Runtime, copyRuntime, dynrequire, hidden} from './utils';\n\nconst registerTransform = (\n md: MarkdownIt,\n {\n runtime,\n bundle,\n output,\n generateID,\n }: Pick<NormalizedPluginOptions, 'bundle' | 'runtime'> & {\n output: string;\n generateID?: IDGenerator;\n },\n) => {\n md.use(createFoldingHeadingPlugin(generateID));\n md.core.ruler.push('heading_sections_after', ({env}) => {\n hidden(env, 'bundled', new Set<string>());\n\n if (env?.[ENV_FLAG_NAME]) {\n env.meta = env.meta || {};\n env.meta.script = env.meta.script || [];\n env.meta.script.push(runtime.script);\n env.meta.style = env.meta.style || [];\n env.meta.style.push(runtime.style);\n\n if (bundle) {\n copyRuntime({runtime, output}, env.bundled);\n }\n }\n });\n};\n\ntype NormalizedPluginOptions = Omit<TransformOptions, 'runtime'> & {\n runtime: Runtime;\n};\n\nexport type TransformOptions = {\n runtime?:\n | string\n | {\n script: string;\n style: string;\n };\n bundle?: boolean;\n};\n\ntype InputOptions = {\n destRoot: string;\n};\n\nexport function transform(options: Partial<TransformOptions> = {}) {\n const {bundle = true} = options;\n\n if (bundle && typeof options.runtime === 'string') {\n throw new TypeError('Option `runtime` should be record when `bundle` is enabled.');\n }\n\n const runtime: Runtime =\n typeof options.runtime === 'string'\n ? {script: options.runtime, style: options.runtime}\n : options.runtime || {\n script: '_assets/folding-headings-extension.js',\n style: '_assets/folding-headings-extension.css',\n };\n\n const plugin: PluginWithOptions<{output?: string; generateID?: IDGenerator}> = function (\n md: MarkdownIt,\n {output = '.', generateID} = {},\n ) {\n registerTransform(md, {\n runtime,\n bundle,\n output,\n generateID,\n });\n };\n\n Object.assign(plugin, {\n collect(input: string, {destRoot = '.'}: InputOptions) {\n const MdIt = dynrequire('markdown-it');\n const md = new MdIt().use((md: MarkdownIt) => {\n registerTransform(md, {\n runtime,\n bundle,\n output: destRoot,\n });\n });\n\n md.parse(input, {});\n },\n });\n\n return plugin;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AAEjB,IAAM,cAAc;AAAA,EACvB,QAAQ;AAAA,EACR,SAAS;AACb;AAEO,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,SAAS;AACb;;;ACRO,IAAM,gBAAgB;AAEtB,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAClB;;;ACRO,IAAM,mBAA0C,CAAC,OAAO,WAAW,UAAU,WAAW;AAC3F,QAAM,EAAC,QAAO,IAAI,MAAM,GAAG;AAE3B,MAAI,MAAM,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,SAAS;AAC1D,MAAI,MAAM,MAAM,OAAO,SAAS;AAGhC,MAAI,MAAM,OAAO,SAAS,IAAI,MAAM,aAAa,GAAG;AAChD,WAAO;AAAA,EACX;AAEA,MAAI,KAAK,MAAM,IAAI,WAAW,GAAG;AAEjC,MAAI,OAAO,MAAgB,OAAO,KAAK;AACnC,WAAO;AAAA,EACX;AAGA,MAAI,QAAQ;AACZ,OAAK,MAAM,IAAI,WAAW,EAAE,GAAG;AAC/B,SAAO,OAAO,MAAgB,MAAM,OAAO,SAAS,GAAG;AACnD;AACA,SAAK,MAAM,IAAI,WAAW,EAAE,GAAG;AAAA,EACnC;AAEA,MAAI,UAAU;AACd,MAAI,OAAO,IAAc;AACrB,cAAU;AACV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.yfm h6[data-folded]{position:relative;padding-left:28px}.yfm h1[data-folded]:before,.yfm h2[data-folded]:before,.yfm h3[data-folded]:before,.yfm h4[data-folded]:before,.yfm h5[data-folded]:before,.yfm h6[data-folded]:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.yfm h1[data-folded]:before{width:28px;height:28px;mask-size:20px}.yfm h2[data-folded]:before,.yfm h3[data-folded]:before{left:2px;width:24px;height:24px;mask-size:20px}.yfm h4[data-folded]:before{left:6px;width:20px;height:20px;mask-size:16px}.yfm h5[data-folded]:before{left:8px;width:20px;height:20px;mask-size:14px}.yfm h6[data-folded]:before{left:8px;width:20px;height:20px;mask-size:12px}.yfm h1[data-folded=false]:before,.yfm h2[data-folded=false]:before,.yfm h3[data-folded=false]:before,.yfm h4[data-folded=false]:before,.yfm h5[data-folded=false]:before,.yfm h6[data-folded=false]:before{transform:translateY(-50%)}.heading-section-content{display:none;padding-left:28px;transition:height .3s ease-in-out}.heading-section-content>.heading-section{margin-left:-28px}.heading-section>h1,.heading-section>h2,.heading-section>h3,.heading-section>h4,.heading-section>h5,.heading-section>h6{cursor:pointer;position:relative;padding-left:28px}.heading-section>h1:before,.heading-section>h2:before,.heading-section>h3:before,.heading-section>h4:before,.heading-section>h5:before,.heading-section>h6:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.heading-section>h1 .yfm-anchor,.heading-section>h2 .yfm-anchor,.heading-section>h3 .yfm-anchor,.heading-section>h4 .yfm-anchor,.heading-section>h5 .yfm-anchor,.heading-section>h6 .yfm-anchor{margin-left:-52px}.heading-section>h1:before{width:28px;height:28px;mask-size:20px}.heading-section>h2:before,.heading-section>h3:before{left:2px;width:24px;height:24px;mask-size:20px}.heading-section>h4:before{left:6px;width:20px;height:20px;mask-size:16px}.heading-section>h5:before{left:8px;width:20px;height:20px;mask-size:14px}.heading-section>h6:before{left:8px;width:20px;height:20px;mask-size:12px}.heading-section.open>.heading-section-content{display:revert}.heading-section.open>h1:before,.heading-section.open>h2:before,.heading-section.open>h3:before,.heading-section.open>h4:before,.heading-section.open>h5:before,.heading-section.open>h6:before{transform:translateY(-50%)}
|
|
1
|
+
.yfm h1[data-folded],.yfm h2[data-folded],.yfm h3[data-folded],.yfm h4[data-folded],.yfm h5[data-folded],.yfm h6[data-folded]{position:relative;padding-left:28px}.yfm h1[data-folded]:before,.yfm h2[data-folded]:before,.yfm h3[data-folded]:before,.yfm h4[data-folded]:before,.yfm h5[data-folded]:before,.yfm h6[data-folded]:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.yfm h1[data-folded]:before{width:28px;height:28px;mask-size:20px}.yfm h2[data-folded]:before,.yfm h3[data-folded]:before{left:2px;width:24px;height:24px;mask-size:20px}.yfm h4[data-folded]:before{left:6px;width:20px;height:20px;mask-size:16px}.yfm h5[data-folded]:before{left:8px;width:20px;height:20px;mask-size:14px}.yfm h6[data-folded]:before{left:8px;width:20px;height:20px;mask-size:12px}.yfm h1[data-folded=false]:before,.yfm h2[data-folded=false]:before,.yfm h3[data-folded=false]:before,.yfm h4[data-folded=false]:before,.yfm h5[data-folded=false]:before,.yfm h6[data-folded=false]:before{transform:translateY(-50%)}.heading-section-content{display:none;padding-left:28px;transition:height .3s ease-in-out}.heading-section-content>.heading-section{margin-left:-28px}.heading-section>h1,.heading-section>h2,.heading-section>h3,.heading-section>h4,.heading-section>h5,.heading-section>h6{cursor:pointer;position:relative;padding-left:28px}.heading-section>h1:before,.heading-section>h2:before,.heading-section>h3:before,.heading-section>h4:before,.heading-section>h5:before,.heading-section>h6:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.heading-section>h1 .yfm-anchor,.heading-section>h1 .yfm-clipboard-anchor,.heading-section>h2 .yfm-anchor,.heading-section>h2 .yfm-clipboard-anchor,.heading-section>h3 .yfm-anchor,.heading-section>h3 .yfm-clipboard-anchor,.heading-section>h4 .yfm-anchor,.heading-section>h4 .yfm-clipboard-anchor,.heading-section>h5 .yfm-anchor,.heading-section>h5 .yfm-clipboard-anchor,.heading-section>h6 .yfm-anchor,.heading-section>h6 .yfm-clipboard-anchor{margin-left:-52px}.yfm table .heading-section>h1 .yfm-anchor,.yfm table .heading-section>h1 .yfm-clipboard-anchor,.yfm table .heading-section>h2 .yfm-anchor,.yfm table .heading-section>h2 .yfm-clipboard-anchor,.yfm table .heading-section>h3 .yfm-anchor,.yfm table .heading-section>h3 .yfm-clipboard-anchor,.yfm table .heading-section>h4 .yfm-anchor,.yfm table .heading-section>h4 .yfm-clipboard-anchor,.yfm table .heading-section>h5 .yfm-anchor,.yfm table .heading-section>h5 .yfm-clipboard-anchor,.yfm table .heading-section>h6 .yfm-anchor,.yfm table .heading-section>h6 .yfm-clipboard-anchor{margin-left:-2.5em}.heading-section>h1:before{width:28px;height:28px;mask-size:20px}.heading-section>h2:before,.heading-section>h3:before{left:2px;width:24px;height:24px;mask-size:20px}.heading-section>h4:before{left:6px;width:20px;height:20px;mask-size:16px}.heading-section>h5:before{left:8px;width:20px;height:20px;mask-size:14px}.heading-section>h6:before{left:8px;width:20px;height:20px;mask-size:12px}.heading-section.open>.heading-section-content{display:revert}.heading-section.open>h1:before,.heading-section.open>h2:before,.heading-section.open>h3:before,.heading-section.open>h4:before,.heading-section.open>h5:before,.heading-section.open>h6:before{transform:translateY(-50%)}
|
|
2
2
|
/*# sourceMappingURL=index.css.map */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/runtime/
|
|
4
|
-
"sourcesContent": ["// this styles for folding headings in markdown editor\n\n@use './mixins' as m;\n\n.yfm {\n h1[data-folded],\n h2[data-folded],\n h3[data-folded],\n h4[data-folded],\n h5[data-folded],\n h6[data-folded] {\n @include m.chevron();\n }\n\n h1[data-folded] {\n @include m.chevron_size_xl();\n }\n\n h2[data-folded],\n h3[data-folded] {\n @include m.chevron_size_l();\n }\n\n h4[data-folded] {\n @include m.chevron_size_m();\n }\n\n h5[data-folded] {\n @include m.chevron_size_s();\n }\n\n h6[data-folded] {\n @include m.chevron_size_xs();\n }\n\n h1[data-folded=false],\n h2[data-folded=false],\n h3[data-folded=false],\n h4[data-folded=false],\n h5[data-folded=false],\n h6[data-folded=false] {\n @include m.chevron_open();\n }\n}\n", "$chevronIcon: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"none\" viewBox=\"0 0 16 16\"><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06\" clip-rule=\"evenodd\"/></svg>');\n\n@mixin chevron() {\n position: relative;\n\n padding-left: 28px;\n\n &::before {\n position: absolute;\n z-index: 1;\n top: 50%;\n left: 0;\n\n content: '';\n cursor: pointer;\n\n background-color: currentColor;\n mask-image: $chevronIcon;\n mask-repeat: no-repeat;\n mask-position: center;\n\n transition: transform 0.3s ease;\n transform: translateY(-50%) rotate(-90deg);\n }\n}\n\n@mixin chevron_size_xs() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 12px;\n }\n}\n\n@mixin chevron_size_s() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 14px;\n }\n}\n\n@mixin chevron_size_m() {\n &::before {\n left: 6px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 16px;\n }\n}\n\n@mixin chevron_size_l() {\n &::before {\n left: 2px;\n\n width: 24px;\n height: 24px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_size_xl() {\n &::before {\n width: 28px;\n height: 28px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_open() {\n &::before {\n transform: translateY(-50%);\n }\n}\n", "@use './mixins' as m;\n@use './editor';\n\n$paddingLeft: 28px;\n$yfmAnchorWidth: 24px;\n\n.heading-section {\n $class: &;\n\n &-content {\n display: none;\n padding-left: $paddingLeft;\n transition: height 0.3s ease-in-out;\n\n & > #{$class} {\n margin-left: -#{$paddingLeft};\n }\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n cursor: pointer;\n\n @include m.chevron();\n\n .yfm-anchor {\n margin-left: -#{$yfmAnchorWidth + $paddingLeft}; // width of yfm-anchor (24px) + padding of heading (28px)\n }\n }\n\n > h1 {\n @include m.chevron_size_xl();\n }\n\n > h2,\n > h3 {\n @include m.chevron_size_l();\n }\n\n > h4 {\n @include m.chevron_size_m();\n }\n\n > h5 {\n @include m.chevron_size_s();\n }\n\n > h6 {\n @include m.chevron_size_xs();\n }\n\n &.open {\n > #{$class}-content {\n display: revert;\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n @include m.chevron_open();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKI,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aCFA,SAAA,SAEA,aAAA,KAEA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QACI,SAAA,SACA,QAAA,EACA,IAAA,IACA,KAAA,EAEA,QAAA,GACA,OAAA,QAEA,iBAAA,aACA,WAjBM,6UAkBN,YAAA,UACA,cAAA,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AA,EAAA,QACI,SAAA,SACA,QAAA,EACA,IAAA,IACA,KAAA,EAEA,QAAA,GACA,OAAA,QAEA,iBAAA,aACA,WAjBM,6UAkBN,YAAA,UACA,cAAA,OAEA,WAAA,UAAA,IAAA,KACA,UAAA,WAAA,MAAA,OAAA,QCOA,CAfA,eAeA,CAAA,GAAA,CAAA,WAAA,CAfA,eAeA,CAAA,GAAA,CAAA,WAAA,CAfA,eAeA,CAAA,GAAA,CAAA,WAAA,CAfA,eAeA,CAAA,GAAA,CAAA,WAAA,CAfA,eAeA,CAAA,GAAA,CAAA,WAAA,CAfA,eAeA,CAAA,GAAA,CAAA,
|
|
3
|
+
"sources": ["../../src/runtime/_editor.scss", "../../src/runtime/_mixins.scss", "../../src/runtime/index.scss"],
|
|
4
|
+
"sourcesContent": ["// this styles for folding headings in markdown editor\n\n@use './mixins' as m;\n\n.yfm {\n h1[data-folded],\n h2[data-folded],\n h3[data-folded],\n h4[data-folded],\n h5[data-folded],\n h6[data-folded] {\n @include m.chevron();\n }\n\n h1[data-folded] {\n @include m.chevron_size_xl();\n }\n\n h2[data-folded],\n h3[data-folded] {\n @include m.chevron_size_l();\n }\n\n h4[data-folded] {\n @include m.chevron_size_m();\n }\n\n h5[data-folded] {\n @include m.chevron_size_s();\n }\n\n h6[data-folded] {\n @include m.chevron_size_xs();\n }\n\n h1[data-folded='false'],\n h2[data-folded='false'],\n h3[data-folded='false'],\n h4[data-folded='false'],\n h5[data-folded='false'],\n h6[data-folded='false'] {\n @include m.chevron_open();\n }\n}\n", "$chevronIcon: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"none\" viewBox=\"0 0 16 16\"><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06\" clip-rule=\"evenodd\"/></svg>');\n\n@mixin chevron() {\n position: relative;\n\n padding-left: 28px;\n\n &::before {\n position: absolute;\n z-index: 1;\n top: 50%;\n left: 0;\n\n content: '';\n cursor: pointer;\n\n background-color: currentColor;\n mask-image: $chevronIcon;\n mask-repeat: no-repeat;\n mask-position: center;\n\n transition: transform 0.3s ease;\n transform: translateY(-50%) rotate(-90deg);\n }\n}\n\n@mixin chevron_size_xs() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 12px;\n }\n}\n\n@mixin chevron_size_s() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 14px;\n }\n}\n\n@mixin chevron_size_m() {\n &::before {\n left: 6px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 16px;\n }\n}\n\n@mixin chevron_size_l() {\n &::before {\n left: 2px;\n\n width: 24px;\n height: 24px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_size_xl() {\n &::before {\n width: 28px;\n height: 28px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_open() {\n &::before {\n transform: translateY(-50%);\n }\n}\n", "@use './mixins' as m;\n@use './editor';\n\n$paddingLeft: 28px;\n$yfmAnchorWidth: 24px;\n\n.heading-section {\n $class: &;\n\n &-content {\n display: none;\n padding-left: $paddingLeft;\n transition: height 0.3s ease-in-out;\n\n & > #{$class} {\n margin-left: -#{$paddingLeft};\n }\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n cursor: pointer;\n\n @include m.chevron();\n\n .yfm-anchor,\n .yfm-clipboard-anchor {\n margin-left: -#{$yfmAnchorWidth + $paddingLeft}; // width of yfm-anchor (24px) + padding of heading (28px)\n\n // overrides styles from transformer\n // https://github.com/diplodoc-platform/transform/blob/f2626e8658c06100dfb081e64ba1dbb06510c8dd/src/scss/_anchor.scss#L63\n .yfm table & {\n margin-left: -2.5em;\n }\n }\n }\n\n > h1 {\n @include m.chevron_size_xl();\n }\n\n > h2,\n > h3 {\n @include m.chevron_size_l();\n }\n\n > h4 {\n @include m.chevron_size_m();\n }\n\n > h5 {\n @include m.chevron_size_s();\n }\n\n > h6 {\n @include m.chevron_size_xs();\n }\n\n &.open {\n > #{$class}-content {\n display: revert;\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n @include m.chevron_open();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKI,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aCFA,SAAA,SAEA,aAAA,KAEA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QAAA,CDFA,ICEA,EAAA,CAAA,YAAA,QACI,SAAA,SACA,QAAA,EACA,IAAA,IACA,KAAA,EAEA,QAAA,GACA,OAAA,QAEA,iBAAA,aACA,WAjBM,6UAkBN,YAAA,UACA,cAAA,OAEA,WAAA,UAAA,IAAA,KACA,UAAA,WAAA,MAAA,OAAA,QAiDJ,CDlEA,ICkEA,EAAA,CAAA,YAAA,QACI,MAAA,KACA,OAAA,KAEA,UAAA,KAfJ,CDvDA,ICuDA,EAAA,CAAA,YAAA,QAAA,CDvDA,ICuDA,EAAA,CAAA,YAAA,QACI,KAAA,IAEA,MAAA,KACA,OAAA,KAEA,UAAA,KAjBJ,CD5CA,IC4CA,EAAA,CAAA,YAAA,QACI,KAAA,IAEA,MAAA,KACA,OAAA,KAEA,UAAA,KAjBJ,CDjCA,ICiCA,EAAA,CAAA,YAAA,QACI,KAAA,IAEA,MAAA,KACA,OAAA,KAEA,UAAA,KAjBJ,CD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A,EAAA,QACI,KAAA,IAEA,MAAA,KACA,OAAA,KAEA,UAAA,KAjBJ,CCbI,eDaJ,CAAA,EAAA,QACI,KAAA,IAEA,MAAA,KACA,OAAA,KAEA,UAAA,KC8BA,CAjDA,eAiDA,CAAA,IAAA,CAAA,CAtDJ,wBAuDQ,QAAA,ODgBR,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QAAA,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QAAA,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QAAA,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QAAA,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QAAA,CClEI,eDkEJ,CCjBI,IDiBJ,CAAA,EAAA,QACI,UAAA,WAAA",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/runtime/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
1
|
+
"use strict";(()=>{var c="heading-section",o={DataId:"data-diplodoc-id",DataKey:"data-diplodoc-key"};var a="heading_sections",I={Heading:".yfm .heading-section > h1,h2,h3,h4,h5,h6",Section:".yfm .heading-section",Content:".yfm .heading-section-content"},i={Open:"open"};var A=g=>{let e=g.composedPath();return Array.isArray(e)&&e.length>0?e[0]:g.target},C=g=>{let e=A(g);return!e||!e.matches};var n=class{__doc;constructor(e){this.__doc=e,this.__doc.addEventListener("click",this._onDocClick)}open(e){for(let t of this._findSections(e))t.classList.add(i.Open)}toggle(e){for(let t of this._findSections(e))t.classList.toggle(i.Open)}close(e){for(let t of this._findSections(e))t.classList.remove(i.Open)}destroy(){this.__doc.removeEventListener("click",this._onDocClick)}_findSections(e){return Array.from(this.__doc.querySelectorAll(`section[${o.DataKey}=${c}][${o.DataId}=${e}]`))}_onDocClick=e=>{if(C(e))return;let t=this._findHeading(e);t&&this._toogleSection(t)};_findHeading(e){let t=A(e);return this._matchHeading(t)?t:e.composedPath?.()?.find(this._matchHeading)}_matchHeading=e=>e instanceof HTMLElement?e?.matches?.(I.Heading)&&e.parentElement?.matches(I.Section):!1;_toogleSection(e){let t=e.parentElement;t instanceof HTMLElement&&t.classList.toggle(i.Open)}};typeof window<"u"&&typeof document<"u"&&!window[a]&&(window[a]=new n(document));})();
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/common/const.ts", "../../src/runtime/const.ts", "../../src/runtime/utils.ts", "../../src/runtime/controller.ts", "../../src/runtime/index.ts"],
|
|
4
|
-
"sourcesContent": ["export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionAttr, DATA_KEY} from '../common/const';\n\nexport const GLOBAL_KEY = 'heading_sections';\n\nexport const Selector = {\n Heading: '.yfm .heading-section > h1,h2,h3,h4,h5,h6',\n Section: '.yfm .heading-section',\n Content: '.yfm .heading-section-content',\n} as const;\n\nexport const ClassName = {\n Open: 'open',\n} as const;\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "import {ClassName, DATA_KEY, SectionAttr, Selector} from './const';\nimport {getEventTarget, isCustom} from './utils';\n\nexport class HeadingSectionContoller {\n private __doc: Document;\n\n constructor(doc: Document) {\n this.__doc = doc;\n this.__doc.addEventListener('click', this._onDocClick);\n }\n\n open(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.add(ClassName.Open);\n }\n }\n\n toggle(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.toggle(ClassName.Open);\n }\n }\n\n close(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.remove(ClassName.Open);\n }\n }\n\n destroy() {\n this.__doc.removeEventListener('click', this._onDocClick);\n }\n\n private _findSections(id: string) {\n return Array.from(\n this.__doc.querySelectorAll(\n `section[${SectionAttr.DataKey}=${DATA_KEY}][${SectionAttr.DataId}=${id}]`,\n ),\n );\n }\n\n private _onDocClick = (event: MouseEvent) => {\n if (isCustom(event)) return;\n\n const heading = this._findHeading(event);\n if (heading) this._toogleSection(heading);\n };\n\n private _findHeading(event: MouseEvent): HTMLElement | undefined {\n const target = getEventTarget(event);\n\n if (this._matchHeading(target)) return target as HTMLElement;\n\n const path = event.composedPath?.();\n return path?.find(this._matchHeading) as HTMLElement | undefined;\n }\n\n private _matchHeading = (target: EventTarget | null) => {\n if (!(target instanceof HTMLElement)) return false;\n\n return (\n target?.matches?.(Selector.Heading) && target.parentElement?.matches(Selector.Section)\n );\n };\n\n private _toogleSection(heading: HTMLElement) {\n const section = heading.parentElement;\n if (section instanceof HTMLElement) {\n section.classList.toggle(ClassName.Open);\n }\n }\n}\n", "import {GLOBAL_KEY} from './const';\nimport {HeadingSectionContoller} from './controller';\
|
|
5
|
-
"mappings": "mBAAO,IAAMA,EAAW,kBAEXC,EAAc,CACvB,OAAQ,mBACR,QAAS,mBACb,ECHO,IAAMC,EAAa,mBAEbC,EAAW,CACpB,QAAS,4CACT,QAAS,wBACT,QAAS,+BACb,EAEaC,EAAY,CACrB,KAAM,MACV,ECZO,IAAMC,EAAkBC,GAAiB,CAC5C,IAAMC,EAAOD,EAAM,aAAa,EAChC,OAAO,MAAM,QAAQC,CAAI,GAAKA,EAAK,OAAS,EAAIA,EAAK,CAAC,EAAID,EAAM,MACpE,EAEaE,EAAYF,GAAiB,CACtC,IAAMG,EAASJ,EAAeC,CAAK,EACnC,MAAO,CAACG,GAAU,CAAEA,EAAuB,OAC/C,ECLO,IAAMC,EAAN,KAA8B,CACzB,MAER,YAAYC,EAAe,CACvB,KAAK,MAAQA,EACb,KAAK,MAAM,iBAAiB,QAAS,KAAK,WAAW,CACzD,CAEA,KAAKC,EAAY,CACb,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,IAAIC,EAAU,IAAI,CAEzC,CAEA,OAAOF,EAAY,CACf,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,OAAOC,EAAU,IAAI,CAE5C,CAEA,MAAMF,EAAY,CACd,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,OAAOC,EAAU,IAAI,CAE5C,CAEA,SAAU,CACN,KAAK,MAAM,oBAAoB,QAAS,KAAK,WAAW,CAC5D,CAEQ,cAAcF,EAAY,CAC9B,OAAO,MAAM,KACT,KAAK,MAAM,iBACP,WAAWG,EAAY,OAAO,IAAIC,CAAQ,KAAKD,EAAY,MAAM,IAAIH,CAAE,GAC3E,CACJ,CACJ,CAEQ,YAAeK,GAAsB,CACzC,GAAIC,EAASD,CAAK,EAAG,OAErB,IAAME,EAAU,KAAK,aAAaF,CAAK,EACnCE,GAAS,KAAK,eAAeA,CAAO,CAC5C,EAEQ,aAAaF,EAA4C,CAC7D,IAAMG,EAASC,EAAeJ,CAAK,EAEnC,OAAI,KAAK,cAAcG,CAAM,EAAUA,EAE1BH,EAAM,eAAe,GACrB,KAAK,KAAK,aAAa,CACxC,CAEQ,cAAiBG,GACfA,aAAkB,YAGpBA,GAAQ,UAAUE,EAAS,OAAO,GAAKF,EAAO,eAAe,QAAQE,EAAS,OAAO,EAH5C,GAOzC,eAAeH,EAAsB,CACzC,IAAMI,EAAUJ,EAAQ,cACpBI,aAAmB,aACnBA,EAAQ,UAAU,OAAOT,EAAU,IAAI,CAE/C,CACJ,
|
|
4
|
+
"sourcesContent": ["export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionAttr, DATA_KEY} from '../common/const';\n\nexport const GLOBAL_KEY = 'heading_sections';\n\nexport const Selector = {\n Heading: '.yfm .heading-section > h1,h2,h3,h4,h5,h6',\n Section: '.yfm .heading-section',\n Content: '.yfm .heading-section-content',\n} as const;\n\nexport const ClassName = {\n Open: 'open',\n} as const;\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "import {ClassName, DATA_KEY, SectionAttr, Selector} from './const';\nimport {getEventTarget, isCustom} from './utils';\n\nexport class HeadingSectionContoller {\n private __doc: Document;\n\n constructor(doc: Document) {\n this.__doc = doc;\n this.__doc.addEventListener('click', this._onDocClick);\n }\n\n open(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.add(ClassName.Open);\n }\n }\n\n toggle(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.toggle(ClassName.Open);\n }\n }\n\n close(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.remove(ClassName.Open);\n }\n }\n\n destroy() {\n this.__doc.removeEventListener('click', this._onDocClick);\n }\n\n private _findSections(id: string) {\n return Array.from(\n this.__doc.querySelectorAll(\n `section[${SectionAttr.DataKey}=${DATA_KEY}][${SectionAttr.DataId}=${id}]`,\n ),\n );\n }\n\n private _onDocClick = (event: MouseEvent) => {\n if (isCustom(event)) return;\n\n const heading = this._findHeading(event);\n if (heading) this._toogleSection(heading);\n };\n\n private _findHeading(event: MouseEvent): HTMLElement | undefined {\n const target = getEventTarget(event);\n\n if (this._matchHeading(target)) return target as HTMLElement;\n\n const path = event.composedPath?.();\n return path?.find(this._matchHeading) as HTMLElement | undefined;\n }\n\n private _matchHeading = (target: EventTarget | null) => {\n if (!(target instanceof HTMLElement)) return false;\n\n return (\n target?.matches?.(Selector.Heading) && target.parentElement?.matches(Selector.Section)\n );\n };\n\n private _toogleSection(heading: HTMLElement) {\n const section = heading.parentElement;\n if (section instanceof HTMLElement) {\n section.classList.toggle(ClassName.Open);\n }\n }\n}\n", "import {GLOBAL_KEY} from './const';\nimport {HeadingSectionContoller} from './controller';\nimport './styles/index.scss';\n\nif (typeof window !== 'undefined' && typeof document !== 'undefined' && !window[GLOBAL_KEY]) {\n window[GLOBAL_KEY] = new HeadingSectionContoller(document);\n}\n\ndeclare global {\n interface Window {\n [GLOBAL_KEY]: HeadingSectionContoller;\n }\n}\n"],
|
|
5
|
+
"mappings": "mBAAO,IAAMA,EAAW,kBAEXC,EAAc,CACvB,OAAQ,mBACR,QAAS,mBACb,ECHO,IAAMC,EAAa,mBAEbC,EAAW,CACpB,QAAS,4CACT,QAAS,wBACT,QAAS,+BACb,EAEaC,EAAY,CACrB,KAAM,MACV,ECZO,IAAMC,EAAkBC,GAAiB,CAC5C,IAAMC,EAAOD,EAAM,aAAa,EAChC,OAAO,MAAM,QAAQC,CAAI,GAAKA,EAAK,OAAS,EAAIA,EAAK,CAAC,EAAID,EAAM,MACpE,EAEaE,EAAYF,GAAiB,CACtC,IAAMG,EAASJ,EAAeC,CAAK,EACnC,MAAO,CAACG,GAAU,CAAEA,EAAuB,OAC/C,ECLO,IAAMC,EAAN,KAA8B,CACzB,MAER,YAAYC,EAAe,CACvB,KAAK,MAAQA,EACb,KAAK,MAAM,iBAAiB,QAAS,KAAK,WAAW,CACzD,CAEA,KAAKC,EAAY,CACb,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,IAAIC,EAAU,IAAI,CAEzC,CAEA,OAAOF,EAAY,CACf,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,OAAOC,EAAU,IAAI,CAE5C,CAEA,MAAMF,EAAY,CACd,QAAWC,KAAQ,KAAK,cAAcD,CAAE,EACpCC,EAAK,UAAU,OAAOC,EAAU,IAAI,CAE5C,CAEA,SAAU,CACN,KAAK,MAAM,oBAAoB,QAAS,KAAK,WAAW,CAC5D,CAEQ,cAAcF,EAAY,CAC9B,OAAO,MAAM,KACT,KAAK,MAAM,iBACP,WAAWG,EAAY,OAAO,IAAIC,CAAQ,KAAKD,EAAY,MAAM,IAAIH,CAAE,GAC3E,CACJ,CACJ,CAEQ,YAAeK,GAAsB,CACzC,GAAIC,EAASD,CAAK,EAAG,OAErB,IAAME,EAAU,KAAK,aAAaF,CAAK,EACnCE,GAAS,KAAK,eAAeA,CAAO,CAC5C,EAEQ,aAAaF,EAA4C,CAC7D,IAAMG,EAASC,EAAeJ,CAAK,EAEnC,OAAI,KAAK,cAAcG,CAAM,EAAUA,EAE1BH,EAAM,eAAe,GACrB,KAAK,KAAK,aAAa,CACxC,CAEQ,cAAiBG,GACfA,aAAkB,YAGpBA,GAAQ,UAAUE,EAAS,OAAO,GAAKF,EAAO,eAAe,QAAQE,EAAS,OAAO,EAH5C,GAOzC,eAAeH,EAAsB,CACzC,IAAMI,EAAUJ,EAAQ,cACpBI,aAAmB,aACnBA,EAAQ,UAAU,OAAOT,EAAU,IAAI,CAE/C,CACJ,ECnEI,OAAO,OAAW,KAAe,OAAO,SAAa,KAAe,CAAC,OAAOU,CAAU,IACtF,OAAOA,CAAU,EAAI,IAAIC,EAAwB,QAAQ",
|
|
6
6
|
"names": ["DATA_KEY", "SectionAttr", "GLOBAL_KEY", "Selector", "ClassName", "getEventTarget", "event", "path", "isCustom", "target", "HeadingSectionContoller", "doc", "id", "elem", "ClassName", "SectionAttr", "DATA_KEY", "event", "isCustom", "heading", "target", "getEventTarget", "Selector", "section", "GLOBAL_KEY", "HeadingSectionContoller"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
import type { IDGenerator } from '@diplodoc/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a folding-heading plugin with an optional external ID generator.
|
|
5
|
+
* When `generateID` is provided, all generated section IDs share the same counter
|
|
6
|
+
* as other plugins, ensuring deterministic output regardless of --merge-includes.
|
|
7
|
+
* When omitted, the plugin uses its internal fallback generator.
|
|
8
|
+
*
|
|
9
|
+
* @param generateID - Optional external ID generator shared with the rest of the transform pipeline.
|
|
10
|
+
* @returns Markdown-it plugin that registers folding heading parsing and section wrapping rules.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createFoldingHeadingPlugin(generateID?: IDGenerator): (md: MarkdownIt) => void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type Core from 'markdown-it/lib/parser_core';
|
|
2
|
+
import type { IDGenerator } from '@diplodoc/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a core rule that wraps folding headings in `<section>` elements with unique IDs.
|
|
5
|
+
* @param externalGenerateID - Optional external ID generator (e.g. from MarkdownItPluginOpts).
|
|
6
|
+
* When provided, ensures all plugins share the same per-file generator.
|
|
7
|
+
* When omitted, uses random fallback behavior.
|
|
8
|
+
* @returns Markdown-it core rule that injects section wrapper tokens around folding headings.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSectionsCoreRule(externalGenerateID?: IDGenerator): Core.RuleCore;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type MarkdownIt from 'markdown-it';
|
|
2
|
+
import type { IDGenerator } from '@diplodoc/utils';
|
|
2
3
|
export type TransformOptions = {
|
|
3
4
|
runtime?: string | {
|
|
4
5
|
script: string;
|
|
@@ -8,4 +9,5 @@ export type TransformOptions = {
|
|
|
8
9
|
};
|
|
9
10
|
export declare function transform(options?: Partial<TransformOptions>): MarkdownIt.PluginWithOptions<{
|
|
10
11
|
output?: string;
|
|
12
|
+
generateID?: IDGenerator;
|
|
11
13
|
}>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export declare function generateID(): string;
|
|
2
1
|
export declare function headingLevel(header: string): number;
|
|
3
2
|
export declare function last<T>(arr: T[]): T | undefined;
|
|
4
|
-
export declare function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(box: B, field: F, value: V): B &
|
|
3
|
+
export declare function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(box: B, field: F, value: V): B & Record<F, V>;
|
|
5
4
|
export type Runtime = {
|
|
6
5
|
script: string;
|
|
7
6
|
style: string;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
export declare const sectionsHtmlResult: string;
|
|
2
|
+
export declare const commonHeadingTokens: ({
|
|
3
|
+
type: string;
|
|
4
|
+
tag: string;
|
|
5
|
+
attrs: null;
|
|
6
|
+
map: number[];
|
|
7
|
+
nesting: number;
|
|
8
|
+
level: number;
|
|
9
|
+
children: null;
|
|
10
|
+
content: string;
|
|
11
|
+
markup: string;
|
|
12
|
+
info: string;
|
|
13
|
+
meta: null;
|
|
14
|
+
block: boolean;
|
|
15
|
+
hidden: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
type: string;
|
|
18
|
+
tag: string;
|
|
19
|
+
attrs: null;
|
|
20
|
+
map: number[];
|
|
21
|
+
nesting: number;
|
|
22
|
+
level: number;
|
|
23
|
+
children: {
|
|
24
|
+
type: string;
|
|
25
|
+
tag: string;
|
|
26
|
+
attrs: null;
|
|
27
|
+
map: null;
|
|
28
|
+
nesting: number;
|
|
29
|
+
level: number;
|
|
30
|
+
children: null;
|
|
31
|
+
content: string;
|
|
32
|
+
markup: string;
|
|
33
|
+
info: string;
|
|
34
|
+
meta: null;
|
|
35
|
+
block: boolean;
|
|
36
|
+
hidden: boolean;
|
|
37
|
+
}[];
|
|
38
|
+
content: string;
|
|
39
|
+
markup: string;
|
|
40
|
+
info: string;
|
|
41
|
+
meta: null;
|
|
42
|
+
block: boolean;
|
|
43
|
+
hidden: boolean;
|
|
44
|
+
} | {
|
|
45
|
+
type: string;
|
|
46
|
+
tag: string;
|
|
47
|
+
attrs: null;
|
|
48
|
+
map: null;
|
|
49
|
+
nesting: number;
|
|
50
|
+
level: number;
|
|
51
|
+
children: null;
|
|
52
|
+
content: string;
|
|
53
|
+
markup: string;
|
|
54
|
+
info: string;
|
|
55
|
+
meta: null;
|
|
56
|
+
block: boolean;
|
|
57
|
+
hidden: boolean;
|
|
58
|
+
})[];
|
|
59
|
+
export declare const foldingHeadingTokens: ({
|
|
60
|
+
type: string;
|
|
61
|
+
tag: string;
|
|
62
|
+
attrs: string[][];
|
|
63
|
+
map: null;
|
|
64
|
+
nesting: number;
|
|
65
|
+
level: number;
|
|
66
|
+
children: null;
|
|
67
|
+
content: string;
|
|
68
|
+
markup: string;
|
|
69
|
+
info: string;
|
|
70
|
+
meta: null;
|
|
71
|
+
block: boolean;
|
|
72
|
+
hidden: boolean;
|
|
73
|
+
} | {
|
|
74
|
+
type: string;
|
|
75
|
+
tag: string;
|
|
76
|
+
attrs: null;
|
|
77
|
+
map: number[];
|
|
78
|
+
nesting: number;
|
|
79
|
+
level: number;
|
|
80
|
+
children: null;
|
|
81
|
+
content: string;
|
|
82
|
+
markup: string;
|
|
83
|
+
info: string;
|
|
84
|
+
meta: {
|
|
85
|
+
folding: boolean;
|
|
86
|
+
};
|
|
87
|
+
block: boolean;
|
|
88
|
+
hidden: boolean;
|
|
89
|
+
} | {
|
|
90
|
+
type: string;
|
|
91
|
+
tag: string;
|
|
92
|
+
attrs: null;
|
|
93
|
+
map: number[];
|
|
94
|
+
nesting: number;
|
|
95
|
+
level: number;
|
|
96
|
+
children: {
|
|
97
|
+
type: string;
|
|
98
|
+
tag: string;
|
|
99
|
+
attrs: null;
|
|
100
|
+
map: null;
|
|
101
|
+
nesting: number;
|
|
102
|
+
level: number;
|
|
103
|
+
children: null;
|
|
104
|
+
content: string;
|
|
105
|
+
markup: string;
|
|
106
|
+
info: string;
|
|
107
|
+
meta: null;
|
|
108
|
+
block: boolean;
|
|
109
|
+
hidden: boolean;
|
|
110
|
+
}[];
|
|
111
|
+
content: string;
|
|
112
|
+
markup: string;
|
|
113
|
+
info: string;
|
|
114
|
+
meta: null;
|
|
115
|
+
block: boolean;
|
|
116
|
+
hidden: boolean;
|
|
117
|
+
} | {
|
|
118
|
+
type: string;
|
|
119
|
+
tag: string;
|
|
120
|
+
attrs: null;
|
|
121
|
+
map: null;
|
|
122
|
+
nesting: number;
|
|
123
|
+
level: number;
|
|
124
|
+
children: null;
|
|
125
|
+
content: string;
|
|
126
|
+
markup: string;
|
|
127
|
+
info: string;
|
|
128
|
+
meta: {
|
|
129
|
+
folding: boolean;
|
|
130
|
+
};
|
|
131
|
+
block: boolean;
|
|
132
|
+
hidden: boolean;
|
|
133
|
+
} | {
|
|
134
|
+
type: string;
|
|
135
|
+
tag: string;
|
|
136
|
+
attrs: null;
|
|
137
|
+
map: null;
|
|
138
|
+
nesting: number;
|
|
139
|
+
level: number;
|
|
140
|
+
children: null;
|
|
141
|
+
content: string;
|
|
142
|
+
markup: string;
|
|
143
|
+
info: string;
|
|
144
|
+
meta: null;
|
|
145
|
+
block: boolean;
|
|
146
|
+
hidden: boolean;
|
|
147
|
+
})[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/folding-headings-extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Folding headings extension for Diplodoc platform ",
|
|
5
5
|
"main": "build/plugin/index.js",
|
|
6
6
|
"types": "build/plugin/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"npm": ">=11.5.1"
|
|
9
|
+
},
|
|
7
10
|
"exports": {
|
|
8
11
|
".": {
|
|
9
12
|
"types": "./build/plugin/index.d.ts",
|
|
@@ -32,25 +35,26 @@
|
|
|
32
35
|
"scripts": {
|
|
33
36
|
"build": "run-p build:*",
|
|
34
37
|
"build:declarations": "tsc --emitDeclarationOnly --outDir ./build",
|
|
35
|
-
"build:js": "./esbuild/build.mjs",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"test": "
|
|
38
|
+
"build:js": "node ./esbuild/build.mjs",
|
|
39
|
+
"prepublishOnly": "npm run typecheck && npm run lint && npm test && npm run build",
|
|
40
|
+
"test": "vitest run --config vitest.config.mjs",
|
|
41
|
+
"test:watch": "vitest --config vitest.config.mjs",
|
|
42
|
+
"test:coverage": "vitest run --coverage",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"lint": "lint update && lint",
|
|
45
|
+
"lint:fix": "lint update && lint fix",
|
|
46
|
+
"pre-commit": "lint update && lint-staged",
|
|
47
|
+
"prepare": "husky"
|
|
40
48
|
},
|
|
41
49
|
"devDependencies": {
|
|
42
|
-
"@diplodoc/
|
|
43
|
-
"@diplodoc/prettier-config": "^2.0.0",
|
|
44
|
-
"@diplodoc/transform": "^4.20.0",
|
|
50
|
+
"@diplodoc/lint": "^1.14.1",
|
|
45
51
|
"@diplodoc/tsconfig": "^1.0.2",
|
|
46
|
-
"@
|
|
47
|
-
"@types/markdown-it": "^13.0.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"jest": "^29.7.0",
|
|
51
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
52
|
+
"@diplodoc/utils": "^2.2.2",
|
|
53
|
+
"@types/markdown-it": "^13.0.9",
|
|
54
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
55
|
+
"markdown-it": "^13.0.0",
|
|
52
56
|
"npm-run-all": "^4.1.5",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
57
|
+
"typescript": "^5.3.3",
|
|
58
|
+
"vitest": "^3.2.4"
|
|
55
59
|
}
|
|
56
60
|
}
|
package/build/plugin/plugin.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|