@rt-tools/ui-kit-v2 0.20.0 → 0.21.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.
@@ -2074,6 +2074,48 @@ function parseMarkdown(source) {
2074
2074
  return blocks;
2075
2075
  }
2076
2076
 
2077
+ /** Между блоками — пустая строка, как между абзацами на экране. */
2078
+ const BLOCK_SEPARATOR = '\n\n';
2079
+ /** Между ячейками строки таблицы — табуляция: так таблицу понимают редакторы и таблицы при вставке. */
2080
+ const CELL_SEPARATOR = '\t';
2081
+ function inlineText(nodes) {
2082
+ return nodes
2083
+ .map((node) => {
2084
+ if (node.kind === ERtMarkdownInline.Break) {
2085
+ return '\n';
2086
+ }
2087
+ return node.children.length > 0 ? inlineText(node.children) : node.text;
2088
+ })
2089
+ .join('');
2090
+ }
2091
+ function tableRow(cells) {
2092
+ return cells.map((cell) => inlineText(cell)).join(CELL_SEPARATOR);
2093
+ }
2094
+ function blockText(block) {
2095
+ switch (block.kind) {
2096
+ case ERtMarkdownBlock.List:
2097
+ return block.items.map((item) => inlineText(item.content)).join('\n');
2098
+ case ERtMarkdownBlock.Code:
2099
+ return block.code;
2100
+ case ERtMarkdownBlock.Table:
2101
+ return [block.head, ...block.rows].map(tableRow).join('\n');
2102
+ default:
2103
+ return inlineText(block.content);
2104
+ }
2105
+ }
2106
+ /**
2107
+ * Видимый текст разметки без её знаков: то, что `rt-markdown-text` показывает читателю.
2108
+ *
2109
+ * Строится по тому же дереву узлов, что рисует компонент, поэтому `##`, `**`, маркеры списков и
2110
+ * черта таблицы в вывод не попадают, а то, что разборщик оставил текстом, остаётся текстом.
2111
+ *
2112
+ * @param source Текст в разметке. Пустота и отсутствие значения дают пустую строку.
2113
+ * @returns Блоки через пустую строку, пункты списка и строки таблицы — построчно, ячейки — через табуляцию.
2114
+ */
2115
+ function markdownToPlainText(source) {
2116
+ return parseMarkdown(source).map(blockText).join(BLOCK_SEPARATOR);
2117
+ }
2118
+
2077
2119
  /** Значение — ровно `true` (флаговые атрибуты). */
2078
2120
  function isTrue(value) {
2079
2121
  return value === true;
@@ -2702,5 +2744,5 @@ const iconsName = [
2702
2744
  * Generated bundle index. Do not edit.
2703
2745
  */
2704
2746
 
2705
- export { BreakpointsService, ERtDataTableCellColor, ERtDataTableColumnType, ERtDataTableFilterType, ERtMarkdownBlock, ERtMarkdownInline, ERtStorageKeys, MessageBus, NotificationBus, RT_CONSUMER_HANDLE_NAMES, RT_DATA_TABLE_PRESET_FROM_HOST, RT_DESIGN_TOKEN_NAMES, RT_KIT_CONFIG, RT_KIT_LABELS, RT_KIT_LABELS_EN, RT_KIT_LOCALE, RT_KIT_TRANSLATOR, RT_MATERIAL_PRESET_CLASS, RT_MATERIAL_PRESET_SELECTOR, RT_PRESET_MATERIAL_CLASS, RT_RADIUS_DEFAULT, RT_RADIUS_STEPS, RT_THEME_SCOPE_ATTRIBUTE, RtDayStampPipe, RtInfiniteScrollDirective, RtKitLabelPipe, RtThemeScopeDirective, SEARCH_DEBOUNCE_MS, ThemeService, breakNode, carryThemeScope, carryThemeScopeOfFocus, coerceQuillDeltaOutput, fileNameFromUrl, formatFileSize, iconsName, materialPresetClassesOf, materialPresetClassesOfFocus, normalizeQuillDelta, parseInline, parseMarkdown, provideRtKit, provideRtKitLabels, rtKitDefault, rtKitLabel, searchDebounce, themeScopeOf, themeScopeOfFocus };
2747
+ export { BreakpointsService, ERtDataTableCellColor, ERtDataTableColumnType, ERtDataTableFilterType, ERtMarkdownBlock, ERtMarkdownInline, ERtStorageKeys, MessageBus, NotificationBus, RT_CONSUMER_HANDLE_NAMES, RT_DATA_TABLE_PRESET_FROM_HOST, RT_DESIGN_TOKEN_NAMES, RT_KIT_CONFIG, RT_KIT_LABELS, RT_KIT_LABELS_EN, RT_KIT_LOCALE, RT_KIT_TRANSLATOR, RT_MATERIAL_PRESET_CLASS, RT_MATERIAL_PRESET_SELECTOR, RT_PRESET_MATERIAL_CLASS, RT_RADIUS_DEFAULT, RT_RADIUS_STEPS, RT_THEME_SCOPE_ATTRIBUTE, RtDayStampPipe, RtInfiniteScrollDirective, RtKitLabelPipe, RtThemeScopeDirective, SEARCH_DEBOUNCE_MS, ThemeService, breakNode, carryThemeScope, carryThemeScopeOfFocus, coerceQuillDeltaOutput, fileNameFromUrl, formatFileSize, iconsName, markdownToPlainText, materialPresetClassesOf, materialPresetClassesOfFocus, normalizeQuillDelta, parseInline, parseMarkdown, provideRtKit, provideRtKitLabels, rtKitDefault, rtKitLabel, searchDebounce, themeScopeOf, themeScopeOfFocus };
2706
2748
  //# sourceMappingURL=rt-tools-ui-kit-v2-core.mjs.map