github-markdown-adf 1.1.0 → 1.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.
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/github-markdown-adf)](https://www.npmjs.com/package/github-markdown-adf)
4
4
  [![CI](https://github.com/joroden/github-markdown-adf/actions/workflows/ci.yml/badge.svg)](https://github.com/joroden/github-markdown-adf/actions)
5
+ [![Socket Badge](https://badge.socket.dev/npm/package/github-markdown-adf)](https://badge.socket.dev/npm/package/github-markdown-adf)
5
6
  [![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue.svg)](https://unlicense.org)
6
7
 
7
8
  Bidirectional **GitHub Flavored Markdown (GFM) to / from Atlassian Document Format (ADF)** converter.
@@ -106,6 +107,7 @@ A self-contained browser bundle with all dependencies inlined is available via C
106
107
  | Task lists | `- [ ] todo` / `- [x] done` |
107
108
  | Code blocks | ` ```lang ` fenced blocks |
108
109
  | Tables | GFM pipe tables |
110
+ | Mentions | Plain `@username` text → ADF mention nodes when `mdToAdf` mentions option is enabled |
109
111
  | GitHub Alerts | `> [!NOTE]`, `> [!WARNING]`, `> [!TIP]`, `> [!IMPORTANT]`, `> [!CAUTION]` → ADF Panels |
110
112
  | Expandable sections | `<details><summary>…</summary>…</details>` → ADF Expand nodes |
111
113
 
@@ -137,7 +139,11 @@ import { mdToAdf, adfToMd } from 'github-markdown-adf';
137
139
 
138
140
  ### `mdToAdf(markdown: string): AdfDoc`
139
141
 
140
- Converts a GFM string to an ADF document object. Parses using [remark](https://github.com/remarkjs/remark) / [unified](https://github.com/unifiedjs/unified) with full GFM extensions: tables, task lists, strikethrough, and GitHub Alert syntax (`> [!NOTE]`, `> [!WARNING]`, etc.).
142
+ Converts a GFM string to an ADF document object. Parses using mdast and micromark GFM extensions, with support for tables, task lists, strikethrough, and GitHub Alert syntax (`> [!NOTE]`, `> [!WARNING]`, etc.).
143
+
144
+ ### `mdToAdf(markdown: string, options?: MdToAdfOptions): AdfDoc`
145
+
146
+ Converts a GFM string to an ADF document object, with optional parsing controls such as custom mention mapping.
141
147
 
142
148
  ### `adfToMd(adf: AdfDoc, options?: AdfToMdOptions): string`
143
149
 
@@ -145,19 +151,38 @@ Converts an ADF document object to a GFM string. Handles all standard ADF node a
145
151
 
146
152
  ## Options
147
153
 
148
- `adfToMd` accepts an optional second argument to control rendering behaviour.
154
+ `mdToAdf` and `adfToMd` accept an optional second argument to control mention handling and rendering behaviour.
155
+
156
+ ### `MdToAdfOptions`
157
+
158
+ | Option | Type | Default | Description |
159
+ |---|---|---|---|
160
+ | `mentions` | `boolean \| ((username: string) => MentionNode['attrs'] \| null \| undefined)` | `false` | When omitted or `false`, plain `@username` text stays unchanged. When `true`, plain `@alice` text becomes `{ type: 'mention', attrs: { id: 'alice', text: '@alice' } }`. When a function is provided, it receives the username without the `@` prefix and should return mention attrs. Returning `null` or `undefined` leaves the original markdown text unchanged. |
149
161
 
150
162
  ### `AdfToMdOptions`
151
163
 
152
164
  | Option | Type | Default | Description |
153
165
  |---|---|---|---|
154
- | `mentions` | `boolean` | `true` | When `true`, renders mention nodes as the display text if available, otherwise as `@{id}`. When `false`, renders as plain text: display text if available, otherwise just the bare `{id}` without an `@` prefix. |
166
+ | `mentions` | `boolean \| ((attrs: MentionNode['attrs']) => string)` | `true` | When `true`, renders mention nodes as the display text if available, otherwise as `@{id}`. When `false`, renders as plain text: display text if available, otherwise just the bare `{id}` without an `@` prefix. When a function is provided, it receives the mention attrs and its return value is used as-is. |
155
167
 
156
168
  ### Usage example
157
169
 
158
170
  ```typescript
171
+ // Convert plain @mentions into ADF mention nodes
172
+ const adfDoc = mdToAdf('Assigned to @some-user', {
173
+ mentions: (username) => ({
174
+ id: 'jira-account-id',
175
+ text: username === 'some-user' ? '@Some User' : `@${username}`,
176
+ }),
177
+ });
178
+
159
179
  // Render mentions as plain text instead of @-tagged references
160
180
  const md = adfToMd(adfDoc, { mentions: false });
181
+
182
+ // Render mentions with a custom formatter
183
+ const mdWithCustomMentions = adfToMd(adfDoc, {
184
+ mentions: (attrs) => `[@${attrs.text ?? attrs.id}](https://example.com/users/${attrs.id})`,
185
+ });
161
186
  ```
162
187
 
163
188
  ## TypeScript Types
@@ -169,7 +194,7 @@ import type { AdfDoc, AdfNode, AdfMark, AdfInlineNode, AdfTopLevelBlockNode } fr
169
194
  // Also available: ParagraphNode, HeadingNode, TableNode, PanelNode, CodeBlockNode,
170
195
  // BulletListNode, OrderedListNode, TaskListNode, TextNode, MentionNode, ...and more
171
196
 
172
- import type { AdfToMdOptions } from 'github-markdown-adf';
197
+ import type { AdfToMdOptions, MdToAdfOptions } from 'github-markdown-adf';
173
198
  ```
174
199
 
175
200
  ## Requirements