mark-deco 0.2.0 → 0.3.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.
Files changed (3) hide show
  1. package/README-package.md +120 -0
  2. package/README.md +14 -1301
  3. package/package.json +8 -2
@@ -0,0 +1,120 @@
1
+ # MarkDeco
2
+
3
+ A high-performance Markdown to HTML conversion library written in TypeScript.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/mark-deco.svg)](https://www.npmjs.com/package/mark-deco)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ ## What is this?
9
+
10
+ A high-performance Markdown to HTML conversion library written in TypeScript.
11
+ It interprets GitHub Flavored Markdown (GFM) and outputs HTML.
12
+ Supports frontmatter parsing, heading analysis, source code formatting, oEmbed/card/Mermaid graph rendering, and custom code block processing through plugin extensions.
13
+
14
+ * Can be used to render HTML from Markdown input.
15
+ * Simple interface makes it very easy to use.
16
+ * Highly independent with minimal runtime requirements. Works in both Node.js and browser environments.
17
+ * Built-in plugins support oEmbed, cards, and Mermaid.js.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install mark-deco
23
+ ```
24
+
25
+ ## Basic Usage
26
+
27
+ Here's the simplest usage example:
28
+
29
+ ```typescript
30
+ import { createMarkdownProcessor, createCachedFetcher } from 'mark-deco';
31
+
32
+ // Create a memory-cached fetcher
33
+ const fetcher = createCachedFetcher('MyApp/1.0');
34
+
35
+ // Create MarkDeco processor
36
+ const processor = createMarkdownProcessor({
37
+ fetcher
38
+ });
39
+
40
+ // Markdown to convert
41
+ const markdown = `---
42
+ title: Sample Article
43
+ author: John Doe
44
+ ---
45
+
46
+ # Hello World
47
+
48
+ This is a test article.`;
49
+
50
+ // Render HTML from Markdown input
51
+ const result = await processor.process(
52
+ markdown,
53
+ "id"); // ID prefix for HTML elements (described later)
54
+
55
+ // Generated HTML
56
+ console.log(result.html);
57
+ // Extracted frontmatter information (described later)
58
+ console.log(result.frontmatter);
59
+ // Extracted heading information (described later)
60
+ console.log(result.headingTree);
61
+ ```
62
+
63
+ This will render HTML like this:
64
+
65
+ ```html
66
+ <h1 id="id-1">Hello World</h1>
67
+ <p>This is a test article.</p>
68
+ ```
69
+
70
+ A "fetcher" is an abstraction for external server access. It's primarily used by oEmbed and card plugins for external API calls and page scraping.
71
+ The argument passed to the fetcher is a user agent string, which is applied to HTTP request headers when accessing external servers.
72
+
73
+ HTML converted by the MarkDeco processor is formatted in a readable manner. Advanced options allow fine-tuning of formatting conditions.
74
+
75
+ ### Aborting Processor Operations
76
+
77
+ While the MarkDeco processor engine itself doesn't access external servers, plugins may access external servers as needed (e.g., when using oEmbed APIs or performing page scraping).
78
+
79
+ To enable operation cancellation in such cases, pass an ECMAScript standard `AbortSignal` instance to notify cancellation signals:
80
+
81
+ ```typescript
82
+ // Abort controller
83
+ const abortController = new AbortController();
84
+
85
+ // ...
86
+
87
+ // Convert Markdown to HTML
88
+ const result = await processor.process(
89
+ markdown, "id",
90
+ { // Specify processor options
91
+ signal: abortController.signal, // Cancellation support
92
+ });
93
+ ```
94
+
95
+ For usage of `AbortController` and `AbortSignal`, refer to ECMAScript documentation.
96
+
97
+ ### CLI Interface
98
+
99
+ Although MarkDeco is a library, a CLI interface is also available in the package that allows you to easily try out MarkDeco. This allows you to try out conversions without having to write code in TypeScript, or call it as an independent application from another code.
100
+
101
+ ```bash
102
+ # Take Markdown from standard input and output HTML
103
+ echo "# Hello World" | mark-deco-cli
104
+ ```
105
+
106
+ ## Documentation
107
+
108
+ For detailed documentation and advanced features, please visit our [GitHub repository](https://github.com/kekyo/mark-deco).
109
+
110
+ Key features include:
111
+ - Frontmatter Information Extraction - Parse YAML frontmatter from Markdown files
112
+ - Heading ID Generation and Heading Information Extraction - Automatically generate unique IDs for headings
113
+ - Fetcher and Cache System - External HTTP request management with configurable caching
114
+ - Built-in Plugins - oEmbed, card, and Mermaid plugins for rich content embedding
115
+ - Creating Custom Plugins - Develop custom plugins to extend Markdown processing
116
+ - CLI Application - Command-line interface for batch processing
117
+
118
+ ## License
119
+
120
+ Under MIT.