@uniweb/content-reader 1.0.7 → 1.1.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.
- package/package.json +1 -1
- package/src/parser/inline.js +33 -6
package/package.json
CHANGED
package/src/parser/inline.js
CHANGED
|
@@ -106,6 +106,7 @@ function parseInline(token, schema, removeNewLine = false) {
|
|
|
106
106
|
|
|
107
107
|
// Extract known link/button attributes from curly brace attrs
|
|
108
108
|
const {
|
|
109
|
+
role, // Optional hint for components (e.g., "button", "nav")
|
|
109
110
|
variant = "primary",
|
|
110
111
|
download,
|
|
111
112
|
target,
|
|
@@ -130,6 +131,7 @@ function parseInline(token, schema, removeNewLine = false) {
|
|
|
130
131
|
attrs: {
|
|
131
132
|
href,
|
|
132
133
|
title: token.title || null,
|
|
134
|
+
...(role && { role }),
|
|
133
135
|
...(isButton && { variant }),
|
|
134
136
|
...(download !== undefined && { download }),
|
|
135
137
|
...(target && { target }),
|
|
@@ -148,14 +150,39 @@ function parseInline(token, schema, removeNewLine = false) {
|
|
|
148
150
|
if (token.type === "image") {
|
|
149
151
|
let role, src, iconLibrary, iconName;
|
|
150
152
|
|
|
151
|
-
//
|
|
153
|
+
// Supported icon families - friendly names and direct react-icons codes
|
|
154
|
+
// The runtime maps friendly names to CDN paths
|
|
155
|
+
const ICON_FAMILIES_FRIENDLY = [
|
|
156
|
+
'lucide', 'heroicons', 'heroicons2', 'phosphor', 'tabler', 'feather',
|
|
157
|
+
'fa', 'fa6', 'bootstrap', 'material-design', 'ant-design', 'remix',
|
|
158
|
+
'simple-icons', 'vscode', 'weather', 'game'
|
|
159
|
+
];
|
|
160
|
+
const ICON_FAMILIES_SHORT = [
|
|
161
|
+
'lu', 'hi', 'hi2', 'pi', 'tb', 'fi', 'bs', 'md', 'ai',
|
|
162
|
+
'ri', 'si', 'vsc', 'wi', 'gi', 'fa', 'fa6'
|
|
163
|
+
];
|
|
164
|
+
const allFamilies = [...ICON_FAMILIES_FRIENDLY, ...ICON_FAMILIES_SHORT];
|
|
165
|
+
const iconFamilyPattern = allFamilies.join('|');
|
|
166
|
+
const shortCodePattern = ICON_FAMILIES_SHORT.join('|');
|
|
167
|
+
|
|
168
|
+
// Check for colon format: lucide:house, lu:house
|
|
152
169
|
// Note: 'icon:' is NOT included here - it's a role prefix, not a library
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
const colonMatch = token.href.match(new RegExp(`^(${iconFamilyPattern}):(.+)$`));
|
|
171
|
+
|
|
172
|
+
// Check for dash format with short codes: lu-house, hi-arrow-right
|
|
173
|
+
// Only short codes (2-3 chars) to avoid ambiguity with regular paths
|
|
174
|
+
const dashMatch = !colonMatch && token.href.match(new RegExp(`^(${shortCodePattern})-(.+)$`));
|
|
175
|
+
|
|
176
|
+
if (colonMatch) {
|
|
177
|
+
iconLibrary = colonMatch[1];
|
|
178
|
+
iconName = colonMatch[2];
|
|
179
|
+
role = "icon";
|
|
180
|
+
src = null;
|
|
181
|
+
} else if (dashMatch) {
|
|
182
|
+
iconLibrary = dashMatch[1];
|
|
183
|
+
iconName = dashMatch[2];
|
|
157
184
|
role = "icon";
|
|
158
|
-
src = null;
|
|
185
|
+
src = null;
|
|
159
186
|
}
|
|
160
187
|
// Find the first colon to handle role:url format correctly (e.g., icon:path/to/file.svg)
|
|
161
188
|
else if (token.href.includes(":") && !token.href.startsWith("http")) {
|