@@ -4,4 +4,199 @@ Transform Markdown to JSON-LD with Advanced Table & Annotation Support
44
55This is the npm package for the [ json-ld-markdown] ( https://github.com/iunera/json-ld-markdown ) project.
66
7- For full documentation, please see the [ main repository README] ( https://github.com/iunera/json-ld-markdown ) .
7+ ## Installation
8+
9+ ``` bash
10+ npm install markdown-to-json-ld
11+ ```
12+
13+ ## Usage
14+
15+ The library provides two main classes:
16+ - ` EnhancedMarkdownParser ` : Parses Markdown content and extracts various components
17+ - ` JsonLDTransformer ` : Transforms the parsed Markdown data into JSON-LD
18+
19+ ### Basic Usage
20+
21+ ``` javascript
22+ import { JsonLDTransformer } from ' markdown-to-json-ld' ;
23+
24+ // Your Markdown content
25+ const markdownContent = ` ---
26+ title: My Article
27+ type: Article
28+ schema: https://schema.org
29+ date: 2023-08-15
30+ author: John Doe
31+ ---
32+
33+ # My Article
34+
35+ This is the content of my article.` ;
36+
37+ // Configuration options
38+ const config = {
39+ baseUrl: ' https://example.com' ,
40+ slug: ' my-article' ,
41+ descriptionLength: 200 ,
42+ type: ' Article' ,
43+ date: ' 2023-08-15' ,
44+ author: [' John Doe' ],
45+ publisher: {
46+ name: ' Example Publisher' ,
47+ url: ' https://example.com'
48+ },
49+ keywords: [' example' , ' article' ],
50+ categories: [' Technology' ]
51+ };
52+
53+ // Transform Markdown to JSON-LD
54+ const jsonLd = JsonLDTransformer .transform (markdownContent, config);
55+
56+ // Output the JSON-LD
57+ console .log (JSON .stringify (jsonLd, null , 2 ));
58+ ```
59+
60+ ### Configuration Options
61+
62+ The ` transform ` method accepts the following configuration options:
63+
64+ | Option | Type | Description | Default |
65+ | --------| ------| -------------| ---------|
66+ | ` baseUrl ` | string | Base URL for the article | ` 'https://example.com' ` |
67+ | ` slug ` | string | Slug for the article URL | ` '' ` |
68+ | ` descriptionLength ` | number | Maximum length for the description | ` 200 ` |
69+ | ` type ` | string | Type of the article (e.g., 'Article', 'NewsArticle') | ` 'Article' ` |
70+ | ` date ` | string | Publication date in ISO format | Current date |
71+ | ` author ` | array | Array of author names | ` [] ` |
72+ | ` publisher ` | object | Publisher information | ` {} ` |
73+ | ` keywords ` | array | Keywords for the article | ` [] ` |
74+ | ` categories ` | array | Categories for the article | ` [] ` |
75+
76+ ### Advanced Features
77+
78+ #### YAML Front Matter
79+
80+ The library supports YAML front matter for defining metadata:
81+
82+ ``` markdown
83+ ---
84+ title: My Article
85+ type: Article
86+ schema: https://schema.org
87+ date: 2023-08-15
88+ author: John Doe
89+ publisher.name: Example Publisher
90+ publisher.url: https://example.com
91+ slug: my-article
92+ keywords: [ example, article]
93+ categories: [ Technology]
94+ ---
95+
96+ # My Article
97+
98+ Content here...
99+ ```
100+
101+ #### FAQ Sections
102+
103+ FAQ sections are automatically detected and transformed into a separate ` FAQPage ` JSON-LD object:
104+
105+ ``` markdown
106+ ## Frequently Asked Questions
107+
108+ ### What is this?
109+ This is an example.
110+
111+ ### How does it work?
112+ It works like this...
113+ ```
114+
115+ #### Tables
116+
117+ Markdown tables are automatically detected and transformed into ` Table ` or ` Dataset ` JSON-LD objects:
118+
119+ ``` markdown
120+ | Name | Price | Description |
121+ | ------| -------| -------------|
122+ | Item 1 | $10 | Description 1 |
123+ | Item 2 | $20 | Description 2 |
124+ ```
125+
126+ #### Lists
127+
128+ Ordered and unordered lists are transformed into ` ItemList ` JSON-LD objects:
129+
130+ ``` markdown
131+ - Item 1
132+ - Item 2
133+ - Item 3
134+ ```
135+
136+ #### Links
137+
138+ Links are transformed into appropriate JSON-LD objects based on their URL:
139+
140+ ``` markdown
141+ [ Example] ( https://example.com )
142+ [ GitHub Repository] ( https://github.com/example/repo )
143+ [ YouTube Video] ( https://youtube.com/watch?v=123456 )
144+ ```
145+
146+ #### Multiple Types
147+
148+ You can define multiple JSON-LD types in a single Markdown file using the ` --- ` separator:
149+
150+ ``` markdown
151+ ---
152+ type: Article
153+ schema: https://schema.org
154+ ---
155+
156+ # My Article
157+
158+ Content here...
159+
160+ ---
161+ type: Document
162+ schema: http://purl.org/dc/terms/
163+ ---
164+
165+ # Metadata
166+
167+ Additional metadata here...
168+ ```
169+
170+ ## Examples
171+
172+ For more examples, see the [ example-articles] ( https://github.com/iunera/json-ld-markdown/tree/main/example-articles ) directory in the main repository.
173+
174+ ## API Reference
175+
176+ ### EnhancedMarkdownParser
177+
178+ The ` EnhancedMarkdownParser ` class provides methods for parsing Markdown content:
179+
180+ - ` extractMetadata(content) ` : Extracts metadata from YAML front matter
181+ - ` extractContext(content) ` : Extracts the JSON-LD context
182+ - ` extractTables(content) ` : Extracts tables from the content
183+ - ` extractLists(content) ` : Extracts lists from the content
184+ - ` extractLinks(content, articleUrl) ` : Extracts links from the content
185+ - ` extractAnnotations(content) ` : Extracts annotations from the content
186+ - ` extractTitle(content) ` : Extracts the title from the content
187+ - ` extractDescription(content, maxLength) ` : Extracts the description from the content
188+ - ` extractArticleBody(content) ` : Extracts the article body from the content
189+ - ` extractSections(content) ` : Extracts sections from the content
190+ - ` extractFaqQuestions(content) ` : Extracts FAQ questions from the content
191+
192+ ### JsonLDTransformer
193+
194+ The ` JsonLDTransformer ` class provides methods for transforming Markdown to JSON-LD:
195+
196+ - ` transform(markdownContent, config) ` : Transforms Markdown content to JSON-LD
197+ - ` processAuthors(authors, articleUrl) ` : Processes author information
198+ - ` processPublisher(publisher) ` : Processes publisher information
199+
200+ ## For more information
201+
202+ For full documentation, please see the [ main repository README] ( https://github.com/iunera/json-ld-markdown ) .
0 commit comments