@uzum-tech/ui 2.3.4 → 2.3.6
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/dist/index.js +6368 -441
- package/dist/index.mjs +6368 -441
- package/dist/index.prod.js +4 -2
- package/dist/index.prod.mjs +4 -2
- package/es/_utils/markdown/constants.d.ts +27 -0
- package/es/_utils/markdown/constants.mjs +26 -0
- package/es/_utils/markdown/create-markdown-renderer.d.ts +3 -0
- package/es/_utils/markdown/create-markdown-renderer.mjs +65 -0
- package/es/_utils/markdown/index.d.ts +2 -0
- package/es/_utils/markdown/index.mjs +1 -0
- package/es/_utils/markdown/interface.d.ts +14 -0
- package/es/_utils/markdown/interface.mjs +7 -0
- package/es/_utils/markdown/render-markdown.d.ts +3 -0
- package/es/_utils/markdown/render-markdown.mjs +31 -0
- package/es/_utils/markdown/rulers/clamp-heading.d.ts +2 -0
- package/es/_utils/markdown/rulers/clamp-heading.mjs +25 -0
- package/es/_utils/markdown/rulers/equals-divider.d.ts +2 -0
- package/es/_utils/markdown/rulers/equals-divider.mjs +19 -0
- package/es/_utils/markdown/rulers/prune-empty-blocks.d.ts +2 -0
- package/es/_utils/markdown/rulers/prune-empty-blocks.mjs +31 -0
- package/es/_utils/markdown/rulers/strikethrough.d.ts +3 -0
- package/es/_utils/markdown/rulers/strikethrough.mjs +38 -0
- package/es/_utils/markdown/rulers/strip-html.d.ts +2 -0
- package/es/_utils/markdown/rulers/strip-html.mjs +7 -0
- package/es/chat/src/Chat.d.ts +515 -23
- package/es/chat/src/Chat.mjs +2 -0
- package/es/chat/src/ChatListItems.d.ts +172 -4
- package/es/chat/src/ChatListItems.mjs +3 -2
- package/es/chat/src/ChatMainArea.d.ts +200 -5
- package/es/chat/src/ChatMainArea.mjs +27 -13
- package/es/chat/src/ChatMessages.d.ts +198 -3
- package/es/chat/src/ChatMessages.mjs +20 -2
- package/es/chat/src/ChatParts/Sidebar.d.ts +28 -0
- package/es/chat/src/interface.d.ts +56 -0
- package/es/chat/src/interface.mjs +8 -0
- package/es/chat/styles/dark.d.ts +14 -0
- package/es/chat/styles/light.d.ts +19 -0
- package/es/chat/styles/light.mjs +5 -0
- package/es/components.d.ts +1452 -456
- package/es/data-table/src/HeaderButton/FilterButton.d.ts +1 -1
- package/es/data-table/src/TableParts/Header.mjs +1 -1
- package/es/data-table/src/use-sorter.d.ts +2 -5
- package/es/data-table/src/use-table-data.d.ts +1 -4
- package/es/image/index.d.ts +2 -2
- package/es/image/index.mjs +2 -1
- package/es/image/src/ImagePreview.d.ts +60 -184
- package/es/image/src/ImagePreview.mjs +12 -18
- package/es/image/src/interface.d.ts +156 -3
- package/es/image/src/interface.mjs +23 -1
- package/es/image/src/public-types.d.ts +11 -5
- package/es/image/src/styles/index.cssr.mjs +11 -1
- package/es/layout/src/LayoutSider.d.ts +1 -1
- package/es/message-bubble/index.d.ts +1 -0
- package/es/message-bubble/src/MessageBubble.d.ts +78 -6
- package/es/message-bubble/src/MessageBubble.mjs +49 -7
- package/es/message-bubble/src/interface.d.ts +36 -0
- package/es/message-bubble/src/interface.mjs +8 -0
- package/es/message-bubble/src/styles/index.cssr.mjs +17 -1
- package/es/message-bubble/styles/dark.d.ts +9 -0
- package/es/message-bubble/styles/light.d.ts +18 -0
- package/es/message-bubble/styles/light.mjs +10 -1
- package/es/version.d.ts +1 -1
- package/es/version.mjs +1 -1
- package/lib/_utils/markdown/constants.d.ts +27 -0
- package/lib/_utils/markdown/constants.js +55 -0
- package/lib/_utils/markdown/create-markdown-renderer.d.ts +3 -0
- package/lib/_utils/markdown/create-markdown-renderer.js +84 -0
- package/lib/_utils/markdown/index.d.ts +2 -0
- package/lib/_utils/markdown/index.js +6 -0
- package/lib/_utils/markdown/interface.d.ts +14 -0
- package/lib/_utils/markdown/interface.js +10 -0
- package/lib/_utils/markdown/render-markdown.d.ts +3 -0
- package/lib/_utils/markdown/render-markdown.js +38 -0
- package/lib/_utils/markdown/rulers/clamp-heading.d.ts +2 -0
- package/lib/_utils/markdown/rulers/clamp-heading.js +30 -0
- package/lib/_utils/markdown/rulers/equals-divider.d.ts +2 -0
- package/lib/_utils/markdown/rulers/equals-divider.js +28 -0
- package/lib/_utils/markdown/rulers/prune-empty-blocks.d.ts +2 -0
- package/lib/_utils/markdown/rulers/prune-empty-blocks.js +40 -0
- package/lib/_utils/markdown/rulers/strikethrough.d.ts +3 -0
- package/lib/_utils/markdown/rulers/strikethrough.js +43 -0
- package/lib/_utils/markdown/rulers/strip-html.d.ts +2 -0
- package/lib/_utils/markdown/rulers/strip-html.js +15 -0
- package/lib/chat/src/Chat.d.ts +515 -23
- package/lib/chat/src/Chat.js +2 -0
- package/lib/chat/src/ChatListItems.d.ts +172 -4
- package/lib/chat/src/ChatListItems.js +7 -2
- package/lib/chat/src/ChatMainArea.d.ts +200 -5
- package/lib/chat/src/ChatMainArea.js +26 -14
- package/lib/chat/src/ChatMessages.d.ts +198 -3
- package/lib/chat/src/ChatMessages.js +11 -4
- package/lib/chat/src/ChatParts/Sidebar.d.ts +28 -0
- package/lib/chat/src/interface.d.ts +56 -0
- package/lib/chat/src/interface.js +6 -0
- package/lib/chat/styles/dark.d.ts +14 -0
- package/lib/chat/styles/light.d.ts +19 -0
- package/lib/chat/styles/light.js +5 -0
- package/lib/components.d.ts +1073 -77
- package/lib/data-table/src/HeaderButton/FilterButton.d.ts +1 -1
- package/lib/data-table/src/TableParts/Header.js +1 -1
- package/lib/data-table/src/use-sorter.d.ts +2 -5
- package/lib/data-table/src/use-table-data.d.ts +1 -4
- package/lib/image/index.d.ts +2 -2
- package/lib/image/index.js +3 -2
- package/lib/image/src/ImagePreview.d.ts +60 -184
- package/lib/image/src/ImagePreview.js +18 -17
- package/lib/image/src/interface.d.ts +156 -3
- package/lib/image/src/interface.js +12 -1
- package/lib/image/src/public-types.d.ts +11 -5
- package/lib/image/src/styles/index.cssr.js +11 -1
- package/lib/layout/src/LayoutSider.d.ts +1 -1
- package/lib/message-bubble/index.d.ts +1 -0
- package/lib/message-bubble/src/MessageBubble.d.ts +78 -6
- package/lib/message-bubble/src/MessageBubble.js +39 -7
- package/lib/message-bubble/src/interface.d.ts +36 -0
- package/lib/message-bubble/src/interface.js +6 -0
- package/lib/message-bubble/src/styles/index.cssr.js +17 -1
- package/lib/message-bubble/styles/dark.d.ts +9 -0
- package/lib/message-bubble/styles/light.d.ts +18 -0
- package/lib/message-bubble/styles/light.js +10 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -1
- package/web-types.json +75 -2
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MarkdownFeature } from '@uzum-tech/ui';
|
|
2
|
+
export declare const HTML_COMMENT_REGEX: RegExp;
|
|
3
|
+
export declare const HTML_CDATA_REGEX: RegExp;
|
|
4
|
+
export declare const HTML_RAW_BLOCK_REGEX: RegExp;
|
|
5
|
+
export declare const HTML_DECLARATION_REGEX: RegExp;
|
|
6
|
+
export declare const HTML_TAG_REGEX: RegExp;
|
|
7
|
+
export declare const ANY_HTML_TAG_REGEX: RegExp;
|
|
8
|
+
export declare const WHITESPACE_REGEX: RegExp;
|
|
9
|
+
export declare const MAX_HEADING_LEVEL = 3;
|
|
10
|
+
export declare const MAX_DIVIDER_INDENT = 4;
|
|
11
|
+
export declare const MIN_DIVIDER_MARKERS = 3;
|
|
12
|
+
export declare const EMPTY_BLOCK_TOKEN_COUNT = 3;
|
|
13
|
+
export declare const CHAR_CODES: {
|
|
14
|
+
TILDE: number;
|
|
15
|
+
EQUALS: number;
|
|
16
|
+
SPACE: number;
|
|
17
|
+
TAB: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const HTML_ENTITY_REPLACEMENTS: Array<[RegExp, string]>;
|
|
20
|
+
export declare const ALL_MARKDOWN_FEATURES: MarkdownFeature[];
|
|
21
|
+
export declare const INVISIBLE_INLINE_TOKEN_TYPES: string[];
|
|
22
|
+
export declare const MARKDOWN_SYMBOL: {
|
|
23
|
+
TILDE: string;
|
|
24
|
+
STRIKETHROUGH_TAG: string;
|
|
25
|
+
PARAGRAPH_TAG: string;
|
|
26
|
+
NEWLINE: string;
|
|
27
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const HTML_COMMENT_REGEX = /<!--[\s\S]*?-->/g;
|
|
2
|
+
export const HTML_CDATA_REGEX = /<!\[CDATA\[[\s\S]*?\]\]>/g;
|
|
3
|
+
export const HTML_RAW_BLOCK_REGEX = /<(script|style|iframe|object|embed|template|svg|math|noscript)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
4
|
+
export const HTML_DECLARATION_REGEX = /<[!?][^>]*>/g;
|
|
5
|
+
export const HTML_TAG_REGEX = /<\/?[a-z][\w:-]*(?:\s[^<>]*)?\/?>/gi;
|
|
6
|
+
export const ANY_HTML_TAG_REGEX = /<[^>]*>/g;
|
|
7
|
+
export const WHITESPACE_REGEX = /\s+/g;
|
|
8
|
+
export const MAX_HEADING_LEVEL = 3;
|
|
9
|
+
export const MAX_DIVIDER_INDENT = 4;
|
|
10
|
+
export const MIN_DIVIDER_MARKERS = 3;
|
|
11
|
+
export const EMPTY_BLOCK_TOKEN_COUNT = 3;
|
|
12
|
+
export const CHAR_CODES = {
|
|
13
|
+
TILDE: 0x7E,
|
|
14
|
+
EQUALS: 0x3D,
|
|
15
|
+
SPACE: 0x20,
|
|
16
|
+
TAB: 0x09
|
|
17
|
+
};
|
|
18
|
+
export const HTML_ENTITY_REPLACEMENTS = [[/</g, '<'], [/>/g, '>'], [/"/g, '"'], [/&/g, '&']];
|
|
19
|
+
export const ALL_MARKDOWN_FEATURES = ['bold', 'italic', 'strikethrough', 'heading', 'orderedList', 'bulletList', 'blockquote', 'divider'];
|
|
20
|
+
export const INVISIBLE_INLINE_TOKEN_TYPES = ['softbreak', 'hardbreak', 'image', 'link_open', 'link_close', 'strong_open', 'strong_close', 'em_open', 'em_close', 's_open', 's_close'];
|
|
21
|
+
export const MARKDOWN_SYMBOL = {
|
|
22
|
+
TILDE: '~',
|
|
23
|
+
STRIKETHROUGH_TAG: 's',
|
|
24
|
+
PARAGRAPH_TAG: 'p',
|
|
25
|
+
NEWLINE: '\n'
|
|
26
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import createClampHeadingRule from "./rulers/clamp-heading.mjs";
|
|
3
|
+
import equalsDivider from "./rulers/equals-divider.mjs";
|
|
4
|
+
import pruneEmptyBlocksCoreRule from "./rulers/prune-empty-blocks.mjs";
|
|
5
|
+
import strikethroughInlineRule from "./rulers/strikethrough.mjs";
|
|
6
|
+
import stripHtmlCoreRule from "./rulers/strip-html.mjs";
|
|
7
|
+
function applyFeatureRendererOverrides(md, enabled) {
|
|
8
|
+
const unwrap = () => '';
|
|
9
|
+
if (!enabled.has('bold')) {
|
|
10
|
+
md.renderer.rules.strong_open = unwrap;
|
|
11
|
+
md.renderer.rules.strong_close = unwrap;
|
|
12
|
+
}
|
|
13
|
+
if (!enabled.has('italic')) {
|
|
14
|
+
md.renderer.rules.em_open = unwrap;
|
|
15
|
+
md.renderer.rules.em_close = unwrap;
|
|
16
|
+
}
|
|
17
|
+
if (!enabled.has('strikethrough')) {
|
|
18
|
+
md.renderer.rules.s_open = unwrap;
|
|
19
|
+
md.renderer.rules.s_close = unwrap;
|
|
20
|
+
}
|
|
21
|
+
if (!enabled.has('blockquote')) {
|
|
22
|
+
md.renderer.rules.blockquote_open = unwrap;
|
|
23
|
+
md.renderer.rules.blockquote_close = unwrap;
|
|
24
|
+
}
|
|
25
|
+
if (!enabled.has('orderedList')) {
|
|
26
|
+
md.renderer.rules.ordered_list_open = unwrap;
|
|
27
|
+
md.renderer.rules.ordered_list_close = unwrap;
|
|
28
|
+
}
|
|
29
|
+
if (!enabled.has('bulletList')) {
|
|
30
|
+
md.renderer.rules.bullet_list_open = unwrap;
|
|
31
|
+
md.renderer.rules.bullet_list_close = unwrap;
|
|
32
|
+
}
|
|
33
|
+
if (!enabled.has('divider')) {
|
|
34
|
+
md.renderer.rules.hr = unwrap;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createMarkdownRenderer(resolved) {
|
|
38
|
+
const enabled = new Set(resolved.features);
|
|
39
|
+
const markdown = new MarkdownIt('zero', {
|
|
40
|
+
html: false,
|
|
41
|
+
linkify: false,
|
|
42
|
+
breaks: resolved.breaks,
|
|
43
|
+
typographer: false
|
|
44
|
+
});
|
|
45
|
+
markdown.enable(['emphasis', 'strikethrough', 'heading', 'list', 'blockquote', 'hr', 'newline', 'escape', 'link', 'image', 'autolink']);
|
|
46
|
+
markdown.core.ruler.before('normalize', 'u_strip_html', stripHtmlCoreRule);
|
|
47
|
+
markdown.block.ruler.before('paragraph', 'u_equals_divider', equalsDivider, {
|
|
48
|
+
alt: ['paragraph', 'reference', 'blockquote', 'list']
|
|
49
|
+
});
|
|
50
|
+
markdown.inline.ruler.before('strikethrough', 'u_strikethrough', strikethroughInlineRule);
|
|
51
|
+
if (!enabled.has('heading')) {
|
|
52
|
+
markdown.disable('heading');
|
|
53
|
+
} else {
|
|
54
|
+
markdown.core.ruler.after('block', 'u_clamp_heading', createClampHeadingRule(resolved.maxHeadingLevel));
|
|
55
|
+
}
|
|
56
|
+
markdown.core.ruler.push('u_prune_empty_blocks', pruneEmptyBlocksCoreRule);
|
|
57
|
+
markdown.validateLink = () => true;
|
|
58
|
+
markdown.renderer.rules.link_open = () => '';
|
|
59
|
+
markdown.renderer.rules.link_close = () => '';
|
|
60
|
+
markdown.renderer.rules.image = () => '';
|
|
61
|
+
markdown.renderer.rules.html_block = () => '';
|
|
62
|
+
markdown.renderer.rules.html_inline = () => '';
|
|
63
|
+
applyFeatureRendererOverrides(markdown, enabled);
|
|
64
|
+
return markdown;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderMarkdown, sanitizeMarkdown } from "./render-markdown.mjs";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum TOKEN_TYPE {
|
|
2
|
+
HEADING_OPEN = "heading_open",
|
|
3
|
+
HEADING_CLOSE = "heading_close",
|
|
4
|
+
PARAGRAPH_OPEN = "paragraph_open",
|
|
5
|
+
PARAGRAPH_CLOSE = "paragraph_close"
|
|
6
|
+
}
|
|
7
|
+
export interface MarkdownOptions {
|
|
8
|
+
features?: MarkdownFeature[];
|
|
9
|
+
maxHeadingLevel?: number;
|
|
10
|
+
breaks?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface NormalizedMarkdownOptions extends Required<MarkdownOptions> {
|
|
13
|
+
}
|
|
14
|
+
export type MarkdownFeature = 'bold' | 'italic' | 'strikethrough' | 'heading' | 'orderedList' | 'bulletList' | 'blockquote' | 'divider';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var TOKEN_TYPE;
|
|
2
|
+
(function (TOKEN_TYPE) {
|
|
3
|
+
TOKEN_TYPE["HEADING_OPEN"] = "heading_open";
|
|
4
|
+
TOKEN_TYPE["HEADING_CLOSE"] = "heading_close";
|
|
5
|
+
TOKEN_TYPE["PARAGRAPH_OPEN"] = "paragraph_open";
|
|
6
|
+
TOKEN_TYPE["PARAGRAPH_CLOSE"] = "paragraph_close";
|
|
7
|
+
})(TOKEN_TYPE || (TOKEN_TYPE = {}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ALL_MARKDOWN_FEATURES, ANY_HTML_TAG_REGEX, HTML_ENTITY_REPLACEMENTS, MAX_HEADING_LEVEL, WHITESPACE_REGEX } from "./constants.mjs";
|
|
2
|
+
import { createMarkdownRenderer } from "./create-markdown-renderer.mjs";
|
|
3
|
+
const rendererCache = new Map();
|
|
4
|
+
function normalizeOptions(options) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
return {
|
|
7
|
+
features: [...((_a = options === null || options === void 0 ? void 0 : options.features) !== null && _a !== void 0 ? _a : ALL_MARKDOWN_FEATURES)],
|
|
8
|
+
maxHeadingLevel: Math.min(MAX_HEADING_LEVEL, Math.max(1, (_b = options === null || options === void 0 ? void 0 : options.maxHeadingLevel) !== null && _b !== void 0 ? _b : MAX_HEADING_LEVEL)),
|
|
9
|
+
breaks: (_c = options === null || options === void 0 ? void 0 : options.breaks) !== null && _c !== void 0 ? _c : true
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function getMarkdownRenderer(options) {
|
|
13
|
+
const normalizedOptions = normalizeOptions(options);
|
|
14
|
+
const instance = rendererCache.get(normalizedOptions);
|
|
15
|
+
if (!instance) {
|
|
16
|
+
const renderer = createMarkdownRenderer(normalizedOptions);
|
|
17
|
+
rendererCache.set(normalizedOptions, renderer);
|
|
18
|
+
return renderer;
|
|
19
|
+
}
|
|
20
|
+
return instance;
|
|
21
|
+
}
|
|
22
|
+
export function renderMarkdown(content, options) {
|
|
23
|
+
if (!content) return '';
|
|
24
|
+
return getMarkdownRenderer(options).render(content).trim();
|
|
25
|
+
}
|
|
26
|
+
export function sanitizeMarkdown(content, options) {
|
|
27
|
+
if (!content) return '';
|
|
28
|
+
let text = renderMarkdown(content, options).replace(ANY_HTML_TAG_REGEX, ' ');
|
|
29
|
+
for (const [pattern, replacement] of HTML_ENTITY_REPLACEMENTS) text = text.replace(pattern, replacement);
|
|
30
|
+
return text.replace(WHITESPACE_REGEX, ' ').trim();
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TOKEN_TYPE } from "../interface.mjs";
|
|
2
|
+
function toParagraph(token, type) {
|
|
3
|
+
token.type = type;
|
|
4
|
+
token.tag = 'p';
|
|
5
|
+
token.markup = '';
|
|
6
|
+
}
|
|
7
|
+
export default function createClampHeadingRule(maxLevel) {
|
|
8
|
+
return state => {
|
|
9
|
+
for (let index = 0; index < state.tokens.length; index++) {
|
|
10
|
+
const openToken = state.tokens[index];
|
|
11
|
+
if (openToken.type !== TOKEN_TYPE.HEADING_OPEN) continue;
|
|
12
|
+
const level = Number(openToken.tag.slice(1));
|
|
13
|
+
if (!Number.isFinite(level) || level <= maxLevel) continue;
|
|
14
|
+
const inlineToken = state.tokens[index + 1];
|
|
15
|
+
const closeToken = state.tokens[index + 2];
|
|
16
|
+
toParagraph(openToken, TOKEN_TYPE.PARAGRAPH_OPEN);
|
|
17
|
+
if ((closeToken === null || closeToken === void 0 ? void 0 : closeToken.type) === TOKEN_TYPE.HEADING_CLOSE) {
|
|
18
|
+
toParagraph(closeToken, TOKEN_TYPE.PARAGRAPH_CLOSE);
|
|
19
|
+
}
|
|
20
|
+
if ((inlineToken === null || inlineToken === void 0 ? void 0 : inlineToken.type) === 'inline') {
|
|
21
|
+
inlineToken.content = `${'#'.repeat(level)} ${inlineToken.content}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CHAR_CODES, MAX_DIVIDER_INDENT, MIN_DIVIDER_MARKERS } from "../constants.mjs";
|
|
2
|
+
export default function equalsDivider(state, startLine, endLine, silent) {
|
|
3
|
+
if (state.sCount[startLine] - state.blkIndent >= MAX_DIVIDER_INDENT) return false;
|
|
4
|
+
let position = state.bMarks[startLine] + state.tShift[startLine];
|
|
5
|
+
const max = state.eMarks[startLine];
|
|
6
|
+
let count = 0;
|
|
7
|
+
while (position < max) {
|
|
8
|
+
const charCode = state.src.charCodeAt(position);
|
|
9
|
+
if (charCode === CHAR_CODES.EQUALS) count++;else if (charCode !== CHAR_CODES.SPACE && charCode !== CHAR_CODES.TAB) return false;
|
|
10
|
+
position++;
|
|
11
|
+
}
|
|
12
|
+
if (count < MIN_DIVIDER_MARKERS) return false;
|
|
13
|
+
if (silent) return true;
|
|
14
|
+
state.line = startLine + 1;
|
|
15
|
+
const token = state.push('hr', 'hr', 0);
|
|
16
|
+
token.map = [startLine, state.line];
|
|
17
|
+
token.markup = '='.repeat(count);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EMPTY_BLOCK_TOKEN_COUNT, INVISIBLE_INLINE_TOKEN_TYPES } from "../constants.mjs";
|
|
2
|
+
import { TOKEN_TYPE } from "../interface.mjs";
|
|
3
|
+
function inlineHasVisibleContent(children) {
|
|
4
|
+
if (!children || children.length === 0) return false;
|
|
5
|
+
for (const child of children) {
|
|
6
|
+
if (child.type === 'text') {
|
|
7
|
+
if (child.content.trim().length > 0) return true;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
if (!INVISIBLE_INLINE_TOKEN_TYPES.includes(child.type)) return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
export default function pruneEmptyBlocksCoreRule(state) {
|
|
15
|
+
const {
|
|
16
|
+
tokens
|
|
17
|
+
} = state;
|
|
18
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
19
|
+
const openToken = tokens[index];
|
|
20
|
+
const isPrunableBlock = openToken.type === TOKEN_TYPE.PARAGRAPH_OPEN || openToken.type === TOKEN_TYPE.HEADING_OPEN;
|
|
21
|
+
if (!isPrunableBlock) continue;
|
|
22
|
+
const inlineToken = tokens[index + 1];
|
|
23
|
+
const closeToken = tokens[index + 2];
|
|
24
|
+
const closeType = openToken.type === TOKEN_TYPE.PARAGRAPH_OPEN ? TOKEN_TYPE.PARAGRAPH_CLOSE : TOKEN_TYPE.HEADING_CLOSE;
|
|
25
|
+
if ((inlineToken === null || inlineToken === void 0 ? void 0 : inlineToken.type) !== 'inline' || (closeToken === null || closeToken === void 0 ? void 0 : closeToken.type) !== closeType) continue;
|
|
26
|
+
if (!inlineHasVisibleContent(inlineToken.children)) {
|
|
27
|
+
tokens.splice(index, EMPTY_BLOCK_TOKEN_COUNT);
|
|
28
|
+
index -= 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CHAR_CODES, MARKDOWN_SYMBOL } from "../constants.mjs";
|
|
2
|
+
function strikethroughInlineRule(state, silent) {
|
|
3
|
+
const max = state.posMax;
|
|
4
|
+
const start = state.pos;
|
|
5
|
+
if (state.src.charCodeAt(start) !== CHAR_CODES.TILDE) return false;
|
|
6
|
+
if (silent) return false;
|
|
7
|
+
if (start + 2 >= max) return false;
|
|
8
|
+
state.pos = start + 1;
|
|
9
|
+
let found = false;
|
|
10
|
+
while (state.pos < max) {
|
|
11
|
+
if (state.src.charCodeAt(state.pos) === CHAR_CODES.TILDE) {
|
|
12
|
+
found = true;
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
state.md.inline.skipToken(state);
|
|
16
|
+
}
|
|
17
|
+
if (!found || start + 1 === state.pos) {
|
|
18
|
+
state.pos = start;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const content = state.src.slice(start + 1, state.pos);
|
|
22
|
+
if (content.includes(MARKDOWN_SYMBOL.NEWLINE)) {
|
|
23
|
+
state.pos = start;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
state.posMax = state.pos;
|
|
27
|
+
state.pos = start + 1;
|
|
28
|
+
let token = state.push('s_open', MARKDOWN_SYMBOL.STRIKETHROUGH_TAG, 1);
|
|
29
|
+
token.markup = MARKDOWN_SYMBOL.TILDE;
|
|
30
|
+
token = state.push('text', '', 0);
|
|
31
|
+
token.content = content.replace(/\\(.)/g, '$1');
|
|
32
|
+
token = state.push('s_close', MARKDOWN_SYMBOL.STRIKETHROUGH_TAG, -1);
|
|
33
|
+
token.markup = MARKDOWN_SYMBOL.TILDE;
|
|
34
|
+
state.pos = state.posMax + 1;
|
|
35
|
+
state.posMax = max;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
export default strikethroughInlineRule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HTML_CDATA_REGEX, HTML_COMMENT_REGEX, HTML_DECLARATION_REGEX, HTML_RAW_BLOCK_REGEX, HTML_TAG_REGEX } from "../constants.mjs";
|
|
2
|
+
function stripHtml(source) {
|
|
3
|
+
return source.replace(HTML_COMMENT_REGEX, '').replace(HTML_CDATA_REGEX, '').replace(HTML_RAW_BLOCK_REGEX, '').replace(HTML_DECLARATION_REGEX, '').replace(HTML_TAG_REGEX, '');
|
|
4
|
+
}
|
|
5
|
+
export default function stripHtmlCoreRule(state) {
|
|
6
|
+
state.src = stripHtml(state.src);
|
|
7
|
+
}
|