@uniweb/content-reader 1.1.0 → 1.1.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/content-reader",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Markdown to ProseMirror document structure converter",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -111,8 +111,10 @@ function parseBlock(token, schema) {
111
111
  let currentParagraph = null;
112
112
 
113
113
  content.forEach((element) => {
114
- if (element.type === "image") {
115
- // If there's an open paragraph, push it to the result before the image
114
+ if (element.type === "image" && element.attrs?.role !== "icon") {
115
+ // Extract non-icon images to root level so they become
116
+ // block-level elements. Icons stay inline so the semantic
117
+ // parser can associate them with adjacent links.
116
118
  if (currentParagraph) {
117
119
  result.push({
118
120
  type: "paragraph",
@@ -155,11 +155,11 @@ function parseInline(token, schema, removeNewLine = false) {
155
155
  const ICON_FAMILIES_FRIENDLY = [
156
156
  'lucide', 'heroicons', 'heroicons2', 'phosphor', 'tabler', 'feather',
157
157
  'fa', 'fa6', 'bootstrap', 'material-design', 'ant-design', 'remix',
158
- 'simple-icons', 'vscode', 'weather', 'game'
158
+ 'simple-icons', 'ionicons', 'boxicons', 'vscode', 'weather', 'game'
159
159
  ];
160
160
  const ICON_FAMILIES_SHORT = [
161
161
  'lu', 'hi', 'hi2', 'pi', 'tb', 'fi', 'bs', 'md', 'ai',
162
- 'ri', 'si', 'vsc', 'wi', 'gi', 'fa', 'fa6'
162
+ 'ri', 'si', 'io5', 'bi', 'vsc', 'wi', 'gi', 'fa', 'fa6'
163
163
  ];
164
164
  const allFamilies = [...ICON_FAMILIES_FRIENDLY, ...ICON_FAMILIES_SHORT];
165
165
  const iconFamilyPattern = allFamilies.join('|');
@@ -200,7 +200,9 @@ describe("Extended Syntax", () => {
200
200
  });
201
201
 
202
202
  test("parses images with roles", () => {
203
- // Images are extracted from paragraphs to root level for component rendering
203
+ // Icons stay inline (inside paragraphs) so the semantic parser can
204
+ // associate them with adjacent links. Non-icon images are extracted
205
+ // to root level.
204
206
  const markdown = '![Alt Text](icon:path/to/image.svg "Caption text")';
205
207
  const result = markdownToProseMirror(markdown);
206
208
 
@@ -208,13 +210,58 @@ describe("Extended Syntax", () => {
208
210
  type: "doc",
209
211
  content: [
210
212
  {
211
- type: "image",
212
- attrs: {
213
- src: "path/to/image.svg",
214
- caption: "Caption text",
215
- alt: "Alt Text",
216
- role: "icon",
217
- },
213
+ type: "paragraph",
214
+ content: [
215
+ {
216
+ type: "image",
217
+ attrs: {
218
+ src: "path/to/image.svg",
219
+ caption: "Caption text",
220
+ alt: "Alt Text",
221
+ role: "icon",
222
+ },
223
+ },
224
+ ],
225
+ },
226
+ ],
227
+ });
228
+ });
229
+
230
+ test("keeps icon inline with adjacent link for icon-link association", () => {
231
+ // Icons must stay inline so the semantic parser can associate them
232
+ // with adjacent links (iconBefore / iconAfter)
233
+ const markdown = "![](lu-home) [Sports](/sports)";
234
+ const result = markdownToProseMirror(markdown);
235
+
236
+ expect(result).toEqual({
237
+ type: "doc",
238
+ content: [
239
+ {
240
+ type: "paragraph",
241
+ content: [
242
+ {
243
+ type: "image",
244
+ attrs: {
245
+ src: null,
246
+ caption: null,
247
+ alt: null,
248
+ role: "icon",
249
+ library: "lu",
250
+ name: "home",
251
+ },
252
+ },
253
+ { type: "text", text: " " },
254
+ {
255
+ type: "text",
256
+ text: "Sports",
257
+ marks: [
258
+ {
259
+ type: "link",
260
+ attrs: { href: "/sports", title: null },
261
+ },
262
+ ],
263
+ },
264
+ ],
218
265
  },
219
266
  ],
220
267
  });