@difizen/libro-markdown 0.1.0 → 0.1.2
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/es/anchor.d.ts +42 -0
- package/es/anchor.d.ts.map +1 -0
- package/es/anchor.js +8 -8
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/markdown-protocol.d.ts +18 -0
- package/es/markdown-protocol.d.ts.map +1 -0
- package/es/markdown-render.d.ts +11 -0
- package/es/markdown-render.d.ts.map +1 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/anchor.ts +1 -1
- package/src/index.spec.ts +3 -3
package/es/anchor.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PluginWithOptions } from 'markdown-it';
|
|
2
|
+
import type State from 'markdown-it/lib/rules_core/state_core.js';
|
|
3
|
+
import type Token from 'markdown-it/lib/token.js';
|
|
4
|
+
export type RenderHref = (slug: string, state: State) => string;
|
|
5
|
+
export type RenderAttrs = (slug: string, state: State) => Record<string, string | number>;
|
|
6
|
+
export interface PermalinkOptions {
|
|
7
|
+
class: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
renderHref: RenderHref;
|
|
10
|
+
renderAttrs: RenderAttrs;
|
|
11
|
+
space: boolean;
|
|
12
|
+
placement: keyof typeof position;
|
|
13
|
+
ariaHidden: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function renderHref(slug: string): string;
|
|
16
|
+
export declare function renderAttrs(slug: string): {};
|
|
17
|
+
declare const position: {
|
|
18
|
+
readonly false: "push";
|
|
19
|
+
readonly true: "unshift";
|
|
20
|
+
readonly after: "push";
|
|
21
|
+
readonly before: "unshift";
|
|
22
|
+
};
|
|
23
|
+
export type PermalinkGenerator = (slug: string, opts: Partial<PermalinkOptions>, state: State, index: number) => void;
|
|
24
|
+
export declare const linkInsideHeader: PermalinkGenerator;
|
|
25
|
+
interface AnchorOptions {
|
|
26
|
+
level: number;
|
|
27
|
+
slugify: (val: string) => string;
|
|
28
|
+
getTokensText(tokens: Token[]): string;
|
|
29
|
+
uniqueSlugStartIndex: number;
|
|
30
|
+
tabIndex: string | false;
|
|
31
|
+
permalink: PermalinkGenerator;
|
|
32
|
+
permalinkOptions: Partial<PermalinkOptions>;
|
|
33
|
+
}
|
|
34
|
+
export declare const slugify: (s: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* fork from markdown-it-anchor
|
|
37
|
+
* @param md
|
|
38
|
+
* @param options
|
|
39
|
+
*/
|
|
40
|
+
export declare const libroAnchor: PluginWithOptions<Partial<AnchorOptions>>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor.d.ts","sourceRoot":"","sources":["../src/anchor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,KAAK,MAAM,0CAA0C,CAAC;AAClE,OAAO,KAAK,KAAK,MAAM,0BAA0B,CAAC;AAElD,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,MAAM,CAAC;AAChE,MAAM,MAAM,WAAW,GAAG,CACxB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,KACT,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAErC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,OAAO,QAAQ,CAAC;IACjC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAEtC;AAGD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,MAEvC;AAgBD,QAAA,MAAM,QAAQ;;;;;CAKJ,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAC/B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,MAAM,KACV,IAAI,CAAC;AAEV,eAAO,MAAM,gBAAgB,EAAE,kBA2B9B,CAAC;AAIF,UAAU,aAAa;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACjC,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACvC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,OAAO,MAAO,MAAM,WACwC,CAAC;AAiD1E;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,iBAAiB,CAAC,OAAO,CAAC,aAAa,CAAC,CAoDjE,CAAC"}
|
package/es/anchor.js
CHANGED
|
@@ -15,7 +15,7 @@ export function renderHref(slug) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
-
export function renderAttrs(
|
|
18
|
+
export function renderAttrs(slug) {
|
|
19
19
|
return {};
|
|
20
20
|
}
|
|
21
21
|
var commonDefaults = {
|
|
@@ -127,22 +127,22 @@ export var libroAnchor = function libroAnchor(md, options) {
|
|
|
127
127
|
|
|
128
128
|
// Aggregate the next token children text.
|
|
129
129
|
var title = opts.getTokensText((_tokens$children = tokens[idx + 1].children) !== null && _tokens$children !== void 0 ? _tokens$children : []);
|
|
130
|
-
var
|
|
131
|
-
if (
|
|
132
|
-
|
|
130
|
+
var _slug = token.attrGet('id');
|
|
131
|
+
if (_slug === null) {
|
|
132
|
+
_slug = uniqueSlug(opts.slugify(title), slugs, false, opts.uniqueSlugStartIndex);
|
|
133
133
|
} else {
|
|
134
|
-
|
|
134
|
+
_slug = uniqueSlug(_slug, slugs, true, opts.uniqueSlugStartIndex);
|
|
135
135
|
}
|
|
136
136
|
if (cellId) {
|
|
137
|
-
token.attrSet('id', "".concat(cellId, "-").concat(
|
|
137
|
+
token.attrSet('id', "".concat(cellId, "-").concat(_slug));
|
|
138
138
|
} else {
|
|
139
|
-
token.attrSet('id',
|
|
139
|
+
token.attrSet('id', _slug);
|
|
140
140
|
}
|
|
141
141
|
if (opts.tabIndex !== false) {
|
|
142
142
|
token.attrSet('tabindex', "".concat(opts.tabIndex));
|
|
143
143
|
}
|
|
144
144
|
if (typeof opts.permalink === 'function') {
|
|
145
|
-
opts.permalink(
|
|
145
|
+
opts.permalink(_slug, opts.permalinkOptions, state, idx);
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
// A permalink renderer could modify the `tokens` array so
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const MarkdownParser: unique symbol;
|
|
2
|
+
export interface MarkdownRenderOption {
|
|
3
|
+
cellId?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The interface for a Markdown parser.
|
|
7
|
+
*/
|
|
8
|
+
export interface MarkdownParser {
|
|
9
|
+
/**
|
|
10
|
+
* Render a markdown source.
|
|
11
|
+
*
|
|
12
|
+
* @param source - The string to render.
|
|
13
|
+
* @returns - string.
|
|
14
|
+
*/
|
|
15
|
+
render(source: string, options?: MarkdownRenderOption): string;
|
|
16
|
+
slugify: (val: string) => string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=markdown-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-protocol.d.ts","sourceRoot":"","sources":["../src/markdown-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAC;IAE/D,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CAClC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import type { MarkdownRenderOption } from './markdown-protocol.js';
|
|
3
|
+
import { MarkdownParser } from './markdown-protocol.js';
|
|
4
|
+
export declare class MarkdownRender implements MarkdownParser {
|
|
5
|
+
protected mkt: MarkdownIt;
|
|
6
|
+
slugify: (s: string) => string;
|
|
7
|
+
enablePermalink: boolean;
|
|
8
|
+
init(): void;
|
|
9
|
+
render(markdownText: string, options?: MarkdownRenderOption): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=markdown-render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-render.d.ts","sourceRoot":"","sources":["../src/markdown-render.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,qBACa,cAAe,YAAW,cAAc;IACnD,SAAS,CAAC,GAAG,EAAE,UAAU,CAAC;IAC1B,OAAO,wBAAW;IAClB,eAAe,UAAS;IAGxB,IAAI;IAaJ,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM;CAIrE"}
|
package/es/module.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,eAAO,MAAM,cAAc,YAG1B,CAAC"}
|
package/package.json
CHANGED
package/src/anchor.ts
CHANGED
package/src/index.spec.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
1
2
|
import assert from 'assert';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import 'reflect-metadata';
|
|
4
|
+
import { MarkdownModule } from './index.js';
|
|
5
5
|
|
|
6
6
|
describe('libro-markdown', () => {
|
|
7
7
|
it('#import', () => {
|
|
8
|
-
assert(
|
|
8
|
+
assert(MarkdownModule);
|
|
9
9
|
});
|
|
10
10
|
});
|