@promptbook/markdown-utils 0.101.0-0 β†’ 0.101.0-10

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.
Files changed (61) hide show
  1. package/README.md +87 -1
  2. package/esm/index.es.js +33 -5
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/components.index.d.ts +18 -0
  5. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  6. package/esm/typings/src/_packages/types.index.d.ts +6 -0
  7. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +41 -3
  8. package/esm/typings/src/book-2.0/agent-source/parseParameters.d.ts +13 -0
  9. package/esm/typings/src/book-2.0/commitments/ACTION/ACTION.d.ts +8 -2
  10. package/esm/typings/src/book-2.0/commitments/DELETE/DELETE.d.ts +59 -0
  11. package/esm/typings/src/book-2.0/commitments/FORMAT/FORMAT.d.ts +8 -2
  12. package/esm/typings/src/book-2.0/commitments/GOAL/GOAL.d.ts +45 -0
  13. package/esm/typings/src/book-2.0/commitments/KNOWLEDGE/KNOWLEDGE.d.ts +1 -1
  14. package/esm/typings/src/book-2.0/commitments/MEMORY/MEMORY.d.ts +46 -0
  15. package/esm/typings/src/book-2.0/commitments/MESSAGE/MESSAGE.d.ts +47 -0
  16. package/esm/typings/src/book-2.0/commitments/META/META.d.ts +62 -0
  17. package/esm/typings/src/book-2.0/commitments/MODEL/MODEL.d.ts +8 -2
  18. package/esm/typings/src/book-2.0/commitments/NOTE/NOTE.d.ts +8 -2
  19. package/esm/typings/src/book-2.0/commitments/PERSONA/PERSONA.d.ts +8 -2
  20. package/esm/typings/src/book-2.0/commitments/SCENARIO/SCENARIO.d.ts +46 -0
  21. package/esm/typings/src/book-2.0/commitments/STYLE/STYLE.d.ts +8 -2
  22. package/esm/typings/src/book-2.0/commitments/index.d.ts +7 -3
  23. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/MockedChat.d.ts +46 -0
  24. package/esm/typings/src/book-components/AvatarProfile/AvatarProfile/index.d.ts +3 -0
  25. package/esm/typings/src/book-components/BookEditor/BookEditor.d.ts +10 -0
  26. package/esm/typings/src/book-components/BookEditor/BookEditorInner.d.ts +3 -0
  27. package/esm/typings/src/book-components/Chat/Chat/Chat.d.ts +0 -5
  28. package/esm/typings/src/book-components/Chat/Chat/ChatProps.d.ts +28 -2
  29. package/esm/typings/src/book-components/Chat/Chat/constants.d.ts +8 -0
  30. package/esm/typings/src/book-components/Chat/examples/ChatMarkdownDemo.d.ts +16 -0
  31. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.d.ts +21 -0
  32. package/esm/typings/src/book-components/Chat/utils/renderMarkdown.test.d.ts +1 -0
  33. package/esm/typings/src/book-components/icons/ArrowIcon.d.ts +9 -0
  34. package/esm/typings/src/book-components/icons/ResetIcon.d.ts +6 -0
  35. package/esm/typings/src/book-components/icons/SendIcon.d.ts +8 -0
  36. package/esm/typings/src/book-components/icons/TemplateIcon.d.ts +8 -0
  37. package/esm/typings/src/utils/markdown/escapeMarkdownBlock.d.ts +2 -0
  38. package/esm/typings/src/utils/markdown/humanizeAiText.d.ts +2 -0
  39. package/esm/typings/src/utils/markdown/humanizeAiTextEllipsis.d.ts +1 -0
  40. package/esm/typings/src/utils/markdown/humanizeAiTextEmdashed.d.ts +1 -0
  41. package/esm/typings/src/utils/markdown/humanizeAiTextQuotes.d.ts +1 -0
  42. package/esm/typings/src/utils/markdown/humanizeAiTextWhitespace.d.ts +1 -0
  43. package/esm/typings/src/utils/markdown/prettifyMarkdown.d.ts +8 -0
  44. package/esm/typings/src/utils/markdown/promptbookifyAiText.d.ts +1 -0
  45. package/esm/typings/src/utils/normalization/capitalize.d.ts +2 -0
  46. package/esm/typings/src/utils/normalization/decapitalize.d.ts +3 -1
  47. package/esm/typings/src/utils/normalization/normalizeTo_SCREAMING_CASE.d.ts +2 -0
  48. package/esm/typings/src/utils/normalization/normalizeTo_snake_case.d.ts +2 -0
  49. package/esm/typings/src/utils/normalization/normalizeWhitespaces.d.ts +2 -0
  50. package/esm/typings/src/utils/normalization/removeDiacritics.d.ts +2 -0
  51. package/esm/typings/src/utils/parseNumber.d.ts +1 -0
  52. package/esm/typings/src/utils/removeEmojis.d.ts +2 -0
  53. package/esm/typings/src/utils/removeQuotes.d.ts +1 -0
  54. package/esm/typings/src/utils/serialization/deepClone.d.ts +1 -0
  55. package/esm/typings/src/utils/trimCodeBlock.d.ts +1 -0
  56. package/esm/typings/src/utils/validators/url/isValidUrl.d.ts +1 -0
  57. package/esm/typings/src/utils/validators/uuid/isValidUuid.d.ts +2 -0
  58. package/esm/typings/src/version.d.ts +1 -1
  59. package/package.json +1 -1
  60. package/umd/index.umd.js +38 -9
  61. package/umd/index.umd.js.map +1 -1
package/README.md CHANGED
@@ -48,7 +48,93 @@ npm i ptbk
48
48
  npm install @promptbook/markdown-utils
49
49
  ```
50
50
 
51
- Utility functions used for processing markdown. Its part of the larger [`@promptbook/utils`](https://www.npmjs.com/package/@promptbook/utils) ecosystem.
51
+ Comprehensive markdown processing utilities for the Promptbook ecosystem, providing tools for parsing, manipulating, and extracting content from markdown documents.
52
+
53
+ ## 🎯 Purpose and Motivation
54
+
55
+ This package provides specialized markdown processing capabilities that are essential for working with promptbooks and LLM-generated content. It handles markdown parsing, content extraction, text humanization, and various markdown transformations that are commonly needed when processing AI-generated text and promptbook documentation.
56
+
57
+ ## πŸ”§ High-Level Functionality
58
+
59
+ The package offers comprehensive markdown processing capabilities:
60
+
61
+ - **Content Extraction**: Extract code blocks, lists, and sections from markdown
62
+ - **Text Processing**: Parse and manipulate markdown sections and content
63
+ - **AI Text Humanization**: Transform AI-generated text to be more human-readable
64
+ - **Markdown Manipulation**: Add, remove, and modify markdown formatting
65
+ - **Table and Chart Creation**: Generate markdown tables and charts
66
+ - **Scraping Integration**: Markdown-specific content scraping capabilities
67
+
68
+ ## ✨ Key Features
69
+
70
+ - πŸ“ **Content Extraction** - Extract blocks, lists, and sections from markdown documents
71
+ - 🎨 **Text Humanization** - Transform AI text with proper quotes, ellipsis, and formatting
72
+ - πŸ”§ **Markdown Manipulation** - Add, remove, and modify markdown formatting
73
+ - πŸ“Š **Table Generation** - Create formatted markdown tables and charts
74
+ - 🧹 **Content Cleaning** - Remove comments, links, and unwanted formatting
75
+ - πŸ“– **Section Parsing** - Parse and split markdown into structured sections
76
+ - πŸ” **Block Processing** - Extract and process code blocks and content blocks
77
+ - πŸ€– **AI Integration** - Specialized tools for processing LLM-generated markdown
78
+
79
+ ## πŸ“¦ Exported Entities
80
+
81
+ ### Version Information
82
+
83
+ - `BOOK_LANGUAGE_VERSION` - Current book language version
84
+ - `PROMPTBOOK_ENGINE_VERSION` - Current engine version
85
+
86
+ ### Content Extraction
87
+
88
+ - `extractBlock` - Extract specific blocks from content
89
+ - `extractJsonBlock` - Extract JSON blocks from content
90
+ - `extractAllBlocksFromMarkdown` - Extract all code blocks from markdown
91
+ - `extractAllListItemsFromMarkdown` - Extract all list items from markdown
92
+ - `extractOneBlockFromMarkdown` - Extract single code block from markdown
93
+
94
+ ### Markdown Scraping
95
+
96
+ - `createMarkdownScraper` - Create markdown content scraper
97
+ - `MarkdownScraper` - Markdown scraper class
98
+ - `_MarkdownScraperRegistration` - Markdown scraper registration
99
+
100
+ ### Type Definitions
101
+
102
+ - `string_markdown` - Markdown string type (type)
103
+ - `string_markdown_section` - Markdown section string type (type)
104
+ - `string_markdown_section_content` - Markdown section content type (type)
105
+ - `string_markdown_text` - Markdown text string type (type)
106
+ - `string_markdown_codeblock_language` - Markdown code block language type (type)
107
+ - `MarkdownSection` - Markdown section structure (type)
108
+
109
+ ### Content Generation
110
+
111
+ - `addAutoGeneratedSection` - Add auto-generated sections to markdown
112
+ - `createMarkdownChart` - Create markdown charts and diagrams
113
+ - `createMarkdownTable` - Create formatted markdown tables
114
+
115
+ ### Text Processing
116
+
117
+ - `escapeMarkdownBlock` - Escape markdown block content
118
+ - `flattenMarkdown` - Flatten markdown structure
119
+ - `parseMarkdownSection` - Parse markdown into sections
120
+ - `splitMarkdownIntoSections` - Split markdown into structured sections
121
+
122
+ ### AI Text Humanization
123
+
124
+ - `humanizeAiText` - Comprehensive AI text humanization
125
+ - `humanizeAiTextEllipsis` - Fix ellipsis formatting in AI text
126
+ - `humanizeAiTextEmdashed` - Fix em-dash formatting in AI text
127
+ - `humanizeAiTextQuotes` - Fix quote formatting in AI text
128
+ - `humanizeAiTextWhitespace` - Fix whitespace in AI text
129
+ - `promptbookifyAiText` - Transform AI text for promptbook format
130
+
131
+ ### Content Cleaning
132
+
133
+ - `removeMarkdownComments` - Remove comments from markdown
134
+ - `removeMarkdownFormatting` - Remove markdown formatting
135
+ - `removeMarkdownLinks` - Remove links from markdown
136
+
137
+ > πŸ’‘ This package provides markdown processing utilities for promptbook applications. For the core functionality, see [@promptbook/core](#-packages) or install all packages with `npm i ptbk`
52
138
 
53
139
 
54
140
  ---
package/esm/index.es.js CHANGED
@@ -1,7 +1,4 @@
1
1
  import spaceTrim, { spaceTrim as spaceTrim$1 } from 'spacetrim';
2
- import parserHtml from 'prettier/parser-html';
3
- import parserMarkdown from 'prettier/parser-markdown';
4
- import { format } from 'prettier/standalone';
5
2
  import { randomBytes } from 'crypto';
6
3
  import { Subject } from 'rxjs';
7
4
  import { forTime } from 'waitasecond';
@@ -26,7 +23,7 @@ const BOOK_LANGUAGE_VERSION = '1.0.0';
26
23
  * @generated
27
24
  * @see https://github.com/webgptorg/promptbook
28
25
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.101.0-0';
26
+ const PROMPTBOOK_ENGINE_VERSION = '0.101.0-10';
30
27
  /**
31
28
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
29
  * Note: [πŸ’ž] Ignore a discrepancy between file name and entity name
@@ -51,6 +48,8 @@ class ParseError extends Error {
51
48
  /**
52
49
  * Makes first letter of a string uppercase
53
50
  *
51
+ * Note: [πŸ”‚] This function is idempotent.
52
+ *
54
53
  * @public exported from `@promptbook/utils`
55
54
  */
56
55
  function capitalize(word) {
@@ -642,6 +641,7 @@ function isValidFilePath(filename) {
642
641
  /**
643
642
  * Tests if given string is valid URL.
644
643
  *
644
+ * Note: [πŸ”‚] This function is idempotent.
645
645
  * Note: Dataurl are considered perfectly valid.
646
646
  * Note: There are two similar functions:
647
647
  * - `isValidUrl` which tests any URL
@@ -705,8 +705,18 @@ function validatePipelineString(pipelineString) {
705
705
  * @private withing the package because of HUGE size of prettier dependency
706
706
  */
707
707
  function prettifyMarkdown(content) {
708
+ // In browser/Next.js environments, just return the original content
709
+ // since prettier parsers are not available and would cause bundling issues
710
+ if (typeof window !== 'undefined') {
711
+ return content;
712
+ }
708
713
  try {
709
- return format(content, {
714
+ // Use dynamic require to avoid static imports that cause bundling issues
715
+ // This will only work in Node.js environments
716
+ const prettierStandalone = eval('require')('prettier/standalone');
717
+ const parserMarkdown = eval('require')('prettier/parser-markdown');
718
+ const parserHtml = eval('require')('prettier/parser-html');
719
+ return prettierStandalone.format(content, {
710
720
  parser: 'markdown',
711
721
  plugins: [parserMarkdown, parserHtml],
712
722
  // TODO: DRY - make some import or auto-copy of .prettierrc
@@ -1054,6 +1064,7 @@ function checkSerializableAsJson(options) {
1054
1064
  /**
1055
1065
  * Creates a deep clone of the given object
1056
1066
  *
1067
+ * Note: [πŸ”‚] This function is idempotent.
1057
1068
  * Note: This method only works for objects that are fully serializable to JSON and do not contain functions, Dates, or special types.
1058
1069
  *
1059
1070
  * @param objectValue The object to clone.
@@ -2989,6 +3000,8 @@ function $getGlobalScope() {
2989
3000
  /**
2990
3001
  * Normalizes a text string to SCREAMING_CASE (all uppercase with underscores).
2991
3002
  *
3003
+ * Note: [πŸ”‚] This function is idempotent.
3004
+ *
2992
3005
  * @param text The text string to be converted to SCREAMING_CASE format.
2993
3006
  * @returns The normalized text in SCREAMING_CASE format.
2994
3007
  * @example 'HELLO_WORLD'
@@ -3044,6 +3057,8 @@ function normalizeTo_SCREAMING_CASE(text) {
3044
3057
  /**
3045
3058
  * Normalizes a text string to snake_case format.
3046
3059
  *
3060
+ * Note: [πŸ”‚] This function is idempotent.
3061
+ *
3047
3062
  * @param text The text string to be converted to snake_case format.
3048
3063
  * @returns The normalized text in snake_case format.
3049
3064
  * @example 'hello_world'
@@ -3461,6 +3476,8 @@ for (let i = 0; i < defaultDiacriticsRemovalMap.length; i++) {
3461
3476
  /**
3462
3477
  * Removes diacritic marks (accents) from characters in a string.
3463
3478
  *
3479
+ * Note: [πŸ”‚] This function is idempotent.
3480
+ *
3464
3481
  * @param input The string containing diacritics to be normalized.
3465
3482
  * @returns The string with diacritics removed or normalized.
3466
3483
  * @public exported from `@promptbook/utils`
@@ -3615,6 +3632,8 @@ function mimeTypeToExtension(value) {
3615
3632
  /**
3616
3633
  * Removes emojis from a string and fix whitespaces
3617
3634
  *
3635
+ * Note: [πŸ”‚] This function is idempotent.
3636
+ *
3618
3637
  * @param text with emojis
3619
3638
  * @returns text without emojis
3620
3639
  * @public exported from `@promptbook/utils`
@@ -6616,6 +6635,8 @@ function createMarkdownChart(options) {
6616
6635
  * Function escapeMarkdownBlock will escape markdown block if needed
6617
6636
  * It is useful when you want have block in block
6618
6637
  *
6638
+ * Note: [πŸ”‚] This function is idempotent.
6639
+ *
6619
6640
  * @public exported from `@promptbook/markdown-utils`
6620
6641
  */
6621
6642
  function escapeMarkdownBlock(value) {
@@ -6783,6 +6804,7 @@ function flattenMarkdown(markdown) {
6783
6804
  /**
6784
6805
  * Change ellipsis character to three dots `…` -> `...`
6785
6806
  *
6807
+ * Note: [πŸ”‚] This function is idempotent.
6786
6808
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6787
6809
  *
6788
6810
  * @public exported from `@promptbook/markdown-utils`
@@ -6797,6 +6819,7 @@ function humanizeAiTextEllipsis(aiText) {
6797
6819
  /**
6798
6820
  * Change em-dashes to regular dashes `β€”` -> `-`
6799
6821
  *
6822
+ * Note: [πŸ”‚] This function is idempotent.
6800
6823
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6801
6824
  *
6802
6825
  * @public exported from `@promptbook/markdown-utils`
@@ -6811,6 +6834,7 @@ function humanizeAiTextEmdashed(aiText) {
6811
6834
  /**
6812
6835
  * Change smart quotes to regular quotes
6813
6836
  *
6837
+ * Note: [πŸ”‚] This function is idempotent.
6814
6838
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6815
6839
  *
6816
6840
  * @public exported from `@promptbook/markdown-utils`
@@ -6832,6 +6856,7 @@ function humanizeAiTextQuotes(aiText) {
6832
6856
  /**
6833
6857
  * Change unprintable hard spaces to regular spaces
6834
6858
  *
6859
+ * Note: [πŸ”‚] This function is idempotent.
6835
6860
  * Tip: If you want to do the full cleanup, look for `humanizeAiText` exported `@promptbook/markdown-utils`
6836
6861
  *
6837
6862
  * @public exported from `@promptbook/markdown-utils`
@@ -6846,6 +6871,7 @@ function humanizeAiTextWhitespace(aiText) {
6846
6871
  /**
6847
6872
  * Function `humanizeAiText` will remove traces of AI text generation artifacts
6848
6873
  *
6874
+ * Note: [πŸ”‚] This function is idempotent.
6849
6875
  * Tip: If you want more control, look for other functions for example `humanizeAiTextEmdashed` exported `@promptbook/markdown-utils`
6850
6876
  *
6851
6877
  * @public exported from `@promptbook/markdown-utils`
@@ -6859,6 +6885,7 @@ function humanizeAiText(aiText) {
6859
6885
  return cleanedText;
6860
6886
  }
6861
6887
  /**
6888
+ * TODO: [🧠] Maybe this should be exported from `@promptbook/utils` not `@promptbook/markdown-utils`
6862
6889
  * TODO: [πŸ…ΎοΈ] !!! Use this across the project where AI text is involved
6863
6890
  */
6864
6891
 
@@ -6878,6 +6905,7 @@ function promptbookifyAiText(text) {
6878
6905
  return promptbookifiedText;
6879
6906
  }
6880
6907
  /**
6908
+ * TODO: !!!!! Make the function idempotent and add "Note: [πŸ”‚] This function is idempotent."
6881
6909
  * TODO: [πŸ…ΎοΈ]!!! Use this across the project where AI text is involved
6882
6910
  * TODO: [🧠][✌️] Make some Promptbook-native token system
6883
6911
  */