@mrsf/markdown-it-mrsf 0.1.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.
- package/README.md +14 -4
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +366 -35
- package/dist/browser.js.map +7 -0
- package/dist/controller.d.ts +31 -11
- package/dist/controller.js +320 -38
- package/dist/controller.js.map +7 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +392 -75
- package/dist/index.js.map +7 -0
- package/dist/shared.d.ts +2 -16
- package/dist/style.css +85 -0
- package/dist/types.d.ts +6 -2
- package/package.json +14 -7
- package/dist/rules/core.js +0 -149
- package/dist/rules/renderer.js +0 -159
- package/dist/shared.js +0 -86
- package/dist/types.js +0 -5
package/dist/style.css
CHANGED
|
@@ -108,6 +108,48 @@
|
|
|
108
108
|
vertical-align: baseline;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
.mrsf-gutter-add {
|
|
112
|
+
position: absolute;
|
|
113
|
+
right: -18px;
|
|
114
|
+
top: 50%;
|
|
115
|
+
transform: translateY(-50%);
|
|
116
|
+
opacity: 0;
|
|
117
|
+
pointer-events: none;
|
|
118
|
+
border: 1px solid var(--mrsf-tooltip-border);
|
|
119
|
+
background: var(--mrsf-tooltip-bg);
|
|
120
|
+
color: var(--mrsf-tooltip-fg);
|
|
121
|
+
border-radius: 50%;
|
|
122
|
+
width: 20px;
|
|
123
|
+
height: 20px;
|
|
124
|
+
font-size: 12px;
|
|
125
|
+
line-height: 18px;
|
|
126
|
+
text-align: center;
|
|
127
|
+
cursor: pointer;
|
|
128
|
+
transition: opacity 0.12s ease, transform 0.12s ease;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.mrsf-tooltip-anchor:hover > .mrsf-gutter-add,
|
|
132
|
+
.mrsf-tooltip-anchor:focus-within > .mrsf-gutter-add {
|
|
133
|
+
opacity: 1;
|
|
134
|
+
pointer-events: auto;
|
|
135
|
+
transform: translateY(-50%) scale(1.02);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* Add-only anchors need hoverable area even without a badge */
|
|
139
|
+
.mrsf-tooltip-anchor.mrsf-gutter-add-only {
|
|
140
|
+
display: inline-block;
|
|
141
|
+
width: 24px;
|
|
142
|
+
height: 24px;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Reveal gutter add when hovering the whole line */
|
|
146
|
+
.mrsf-line-hover-target:hover .mrsf-gutter-add,
|
|
147
|
+
.mrsf-line-hover-target:focus-within .mrsf-gutter-add {
|
|
148
|
+
opacity: 1;
|
|
149
|
+
pointer-events: auto;
|
|
150
|
+
transform: translateY(-50%) scale(1.02);
|
|
151
|
+
}
|
|
152
|
+
|
|
111
153
|
/* Gutter position: right (default) — float the badge to the right */
|
|
112
154
|
.mrsf-tooltip-anchor.mrsf-gutter-right {
|
|
113
155
|
float: right;
|
|
@@ -131,6 +173,16 @@
|
|
|
131
173
|
left: 4px;
|
|
132
174
|
}
|
|
133
175
|
|
|
176
|
+
.mrsf-tooltip-anchor.mrsf-gutter-left > .mrsf-gutter-add {
|
|
177
|
+
left: -18px;
|
|
178
|
+
right: auto;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.mrsf-tooltip-anchor.mrsf-gutter-right > .mrsf-gutter-add {
|
|
182
|
+
right: -18px;
|
|
183
|
+
left: auto;
|
|
184
|
+
}
|
|
185
|
+
|
|
134
186
|
.mrsf-tooltip-anchor.mrsf-gutter-left .mrsf-badge {
|
|
135
187
|
margin-left: 0;
|
|
136
188
|
}
|
|
@@ -339,6 +391,15 @@
|
|
|
339
391
|
display: flex;
|
|
340
392
|
}
|
|
341
393
|
|
|
394
|
+
.mrsf-tooltip-actions {
|
|
395
|
+
display: flex;
|
|
396
|
+
justify-content: flex-end;
|
|
397
|
+
gap: 6px;
|
|
398
|
+
margin-top: 8px;
|
|
399
|
+
padding-top: 6px;
|
|
400
|
+
border-top: 1px solid var(--mrsf-tooltip-border);
|
|
401
|
+
}
|
|
402
|
+
|
|
342
403
|
.mrsf-action-btn {
|
|
343
404
|
font-size: 11px;
|
|
344
405
|
padding: 2px 8px;
|
|
@@ -351,6 +412,30 @@
|
|
|
351
412
|
transition: background 0.15s ease;
|
|
352
413
|
}
|
|
353
414
|
|
|
415
|
+
.mrsf-action-btn.mrsf-action-danger {
|
|
416
|
+
color: #d13438;
|
|
417
|
+
border-color: rgba(209, 52, 56, 0.7);
|
|
418
|
+
}
|
|
419
|
+
|
|
354
420
|
.mrsf-action-btn:hover {
|
|
355
421
|
background: rgba(127, 127, 127, 0.2);
|
|
356
422
|
}
|
|
423
|
+
|
|
424
|
+
.mrsf-add-inline-button {
|
|
425
|
+
position: absolute;
|
|
426
|
+
z-index: 1200;
|
|
427
|
+
display: none;
|
|
428
|
+
font-size: 12px;
|
|
429
|
+
padding: 6px 10px;
|
|
430
|
+
border-radius: 6px;
|
|
431
|
+
border: 1px solid var(--mrsf-tooltip-border);
|
|
432
|
+
background: var(--mrsf-tooltip-bg);
|
|
433
|
+
color: var(--mrsf-tooltip-fg);
|
|
434
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
|
|
435
|
+
cursor: pointer;
|
|
436
|
+
font-family: var(--mrsf-font-family);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
.mrsf-add-inline-button:hover {
|
|
440
|
+
background: rgba(127, 127, 127, 0.2);
|
|
441
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Shared type definitions for MRSF rendering plugins.
|
|
3
|
+
*
|
|
4
|
+
* These types are used by both @mrsf/markdown-it-mrsf and @mrsf/rehype-mrsf.
|
|
3
5
|
*/
|
|
4
6
|
import type { MrsfDocument } from "@mrsf/cli";
|
|
5
|
-
/**
|
|
7
|
+
/** Base options shared by all MRSF rendering plugins. */
|
|
6
8
|
export interface MrsfPluginOptions {
|
|
7
9
|
/**
|
|
8
10
|
* Path to the Markdown document on disk.
|
|
@@ -81,4 +83,6 @@ export interface CommentThread {
|
|
|
81
83
|
}
|
|
82
84
|
/** Comments grouped by their anchored source line. */
|
|
83
85
|
export type LineMap = Map<number, CommentThread[]>;
|
|
86
|
+
/** A function that loads sidecar data from plugin options. */
|
|
87
|
+
export type CommentLoader = (options: MrsfPluginOptions) => MrsfDocument | null;
|
|
84
88
|
//# sourceMappingURL=types.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrsf/markdown-it-mrsf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "markdown-it plugin for rendering Sidemark/MRSF (Markdown Review Sidecar Format) review comments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"node": ">=18"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "
|
|
31
|
+
"build": "node ../sync-types.mjs && node esbuild.config.mjs",
|
|
32
32
|
"dev": "tsc --watch",
|
|
33
33
|
"test": "vitest run",
|
|
34
34
|
"test:watch": "vitest",
|
|
35
35
|
"lint": "tsc --noEmit",
|
|
36
|
-
"prepublishOnly": "cp
|
|
36
|
+
"prepublishOnly": "cp ../../LICENSE . && npm run build && npm test",
|
|
37
37
|
"postpublish": "rm -f LICENSE"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
@@ -44,32 +44,39 @@
|
|
|
44
44
|
"sidecar",
|
|
45
45
|
"mrsf",
|
|
46
46
|
"sidemark",
|
|
47
|
-
"comments"
|
|
47
|
+
"comments",
|
|
48
|
+
"annotation",
|
|
49
|
+
"highlight",
|
|
50
|
+
"tooltip",
|
|
51
|
+
"rendering"
|
|
48
52
|
],
|
|
49
53
|
"license": "MIT",
|
|
50
54
|
"author": "Wictor Wilén (https://github.com/wictorwilen)",
|
|
51
|
-
"homepage": "https://github.com/wictorwilen/MRSF/tree/main/markdown-it#readme",
|
|
55
|
+
"homepage": "https://github.com/wictorwilen/MRSF/tree/main/plugins/markdown-it#readme",
|
|
52
56
|
"bugs": {
|
|
53
57
|
"url": "https://github.com/wictorwilen/MRSF/issues"
|
|
54
58
|
},
|
|
55
59
|
"repository": {
|
|
56
60
|
"type": "git",
|
|
57
61
|
"url": "https://github.com/wictorwilen/MRSF.git",
|
|
58
|
-
"directory": "markdown-it"
|
|
62
|
+
"directory": "plugins/markdown-it"
|
|
59
63
|
},
|
|
60
64
|
"files": [
|
|
61
65
|
"dist/**/*.js",
|
|
66
|
+
"dist/**/*.js.map",
|
|
62
67
|
"dist/**/*.d.ts",
|
|
63
68
|
"dist/style.css",
|
|
64
69
|
"README.md",
|
|
65
70
|
"LICENSE"
|
|
66
71
|
],
|
|
67
72
|
"dependencies": {
|
|
68
|
-
"@mrsf/cli": "
|
|
73
|
+
"@mrsf/cli": "^0.3.0"
|
|
69
74
|
},
|
|
70
75
|
"devDependencies": {
|
|
76
|
+
"@mrsf/plugin-shared": "file:../shared",
|
|
71
77
|
"@types/markdown-it": "^14.1.2",
|
|
72
78
|
"@types/node": "^22.13.10",
|
|
79
|
+
"esbuild": "^0.27.3",
|
|
73
80
|
"markdown-it": "^14.1.0",
|
|
74
81
|
"typescript": "^5.8.2",
|
|
75
82
|
"vitest": "^3.0.9"
|
package/dist/rules/core.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MRSF markdown-it plugin — core rule.
|
|
3
|
-
*
|
|
4
|
-
* Walks the parsed token stream and injects `mrsf_badge` tokens
|
|
5
|
-
* at lines that have comments, and wraps `selected_text` matches
|
|
6
|
-
* with `mrsf_highlight_open`/`close` tokens (with tooltip metadata).
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Find the token index for a given 1-based source line.
|
|
10
|
-
* markdown-it tokens use `token.map = [startLine, endLine]` (0-based).
|
|
11
|
-
*/
|
|
12
|
-
function findTokenIndexForLine(tokens, line) {
|
|
13
|
-
const line0 = line - 1; // convert to 0-based
|
|
14
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
15
|
-
const map = tokens[i].map;
|
|
16
|
-
if (map && map[0] <= line0 && line0 < map[1]) {
|
|
17
|
-
return i;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return -1;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Wrap occurrences of `text` inside inline token children with
|
|
24
|
-
* highlight open/close tokens. Stores thread data on the tokens
|
|
25
|
-
* so the renderer can produce an inline tooltip.
|
|
26
|
-
*/
|
|
27
|
-
function highlightInlineText(token, thread, interactive, Token) {
|
|
28
|
-
if (!token.children)
|
|
29
|
-
return false;
|
|
30
|
-
const text = thread.comment.selected_text;
|
|
31
|
-
if (!text)
|
|
32
|
-
return false;
|
|
33
|
-
const trimmed = text.trim();
|
|
34
|
-
if (!trimmed)
|
|
35
|
-
return false;
|
|
36
|
-
for (let i = 0; i < token.children.length; i++) {
|
|
37
|
-
const child = token.children[i];
|
|
38
|
-
if (child.type !== "text")
|
|
39
|
-
continue;
|
|
40
|
-
const idx = child.content.indexOf(trimmed);
|
|
41
|
-
if (idx === -1)
|
|
42
|
-
continue;
|
|
43
|
-
// Split the text token into: before + highlight_open + matched + highlight_close + after
|
|
44
|
-
const newTokens = [];
|
|
45
|
-
// Text before match
|
|
46
|
-
if (idx > 0) {
|
|
47
|
-
const before = new Token("text", "", 0);
|
|
48
|
-
before.content = child.content.slice(0, idx);
|
|
49
|
-
newTokens.push(before);
|
|
50
|
-
}
|
|
51
|
-
// Highlight open — carries thread metadata for inline tooltip
|
|
52
|
-
const open = new Token("mrsf_highlight_open", "mark", 1);
|
|
53
|
-
open.attrSet("class", "mrsf-highlight");
|
|
54
|
-
open.attrSet("data-mrsf-comment-id", thread.comment.id);
|
|
55
|
-
open.meta = { thread };
|
|
56
|
-
newTokens.push(open);
|
|
57
|
-
// Matched text
|
|
58
|
-
const matched = new Token("text", "", 0);
|
|
59
|
-
matched.content = trimmed;
|
|
60
|
-
newTokens.push(matched);
|
|
61
|
-
// Highlight close — carries thread metadata for inline tooltip
|
|
62
|
-
const close = new Token("mrsf_highlight_close", "mark", -1);
|
|
63
|
-
close.meta = { thread, interactive };
|
|
64
|
-
newTokens.push(close);
|
|
65
|
-
// Text after match
|
|
66
|
-
if (idx + trimmed.length < child.content.length) {
|
|
67
|
-
const after = new Token("text", "", 0);
|
|
68
|
-
after.content = child.content.slice(idx + trimmed.length);
|
|
69
|
-
newTokens.push(after);
|
|
70
|
-
}
|
|
71
|
-
// Replace the original child with our new tokens
|
|
72
|
-
token.children.splice(i, 1, ...newTokens);
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Install the MRSF core rule on a markdown-it instance.
|
|
79
|
-
*/
|
|
80
|
-
export function installCoreRule(md, lineMap, options) {
|
|
81
|
-
const { interactive, gutterPosition, gutterForInline, inlineHighlights } = options;
|
|
82
|
-
md.core.ruler.push("mrsf_inject", (state) => {
|
|
83
|
-
const tokens = state.tokens;
|
|
84
|
-
const TokenCtor = state.Token;
|
|
85
|
-
// Track which lines we've already processed (to avoid double-injection
|
|
86
|
-
// when multiple tokens share the same source line).
|
|
87
|
-
const processed = new Set();
|
|
88
|
-
// We iterate backwards so that inserting tokens doesn't shift indices
|
|
89
|
-
// for tokens we haven't visited yet.
|
|
90
|
-
for (let i = tokens.length - 1; i >= 0; i--) {
|
|
91
|
-
const token = tokens[i];
|
|
92
|
-
const map = token.map;
|
|
93
|
-
if (!map)
|
|
94
|
-
continue;
|
|
95
|
-
// Skip inline tokens — they share the same map as their parent block.
|
|
96
|
-
// We must process the parent block (paragraph_open, heading_open, etc.)
|
|
97
|
-
// so the badge and class land on the correct rendered element.
|
|
98
|
-
if (token.type === "inline")
|
|
99
|
-
continue;
|
|
100
|
-
// Check each line in this token's range for comments
|
|
101
|
-
for (let line0 = map[0]; line0 < map[1]; line0++) {
|
|
102
|
-
const line = line0 + 1; // 1-based
|
|
103
|
-
if (processed.has(line))
|
|
104
|
-
continue;
|
|
105
|
-
const threads = lineMap.get(line);
|
|
106
|
-
if (!threads || threads.length === 0)
|
|
107
|
-
continue;
|
|
108
|
-
processed.add(line);
|
|
109
|
-
// Add line-highlight class to the block token
|
|
110
|
-
const existingClass = token.attrGet("class") || "";
|
|
111
|
-
token.attrSet("class", existingClass
|
|
112
|
-
? `${existingClass} mrsf-line-highlight`
|
|
113
|
-
: "mrsf-line-highlight");
|
|
114
|
-
token.attrSet("data-mrsf-line", String(line));
|
|
115
|
-
// Determine whether all threads on this line have inline highlights
|
|
116
|
-
const allHaveInline = inlineHighlights &&
|
|
117
|
-
threads.every((t) => !!t.comment.selected_text);
|
|
118
|
-
// Inject badge unless gutterForInline is false AND all threads are inline-highlighted
|
|
119
|
-
const showBadge = gutterForInline || !allHaveInline || !inlineHighlights;
|
|
120
|
-
if (showBadge) {
|
|
121
|
-
const badgeToken = new TokenCtor("mrsf_badge", "", 0);
|
|
122
|
-
badgeToken.meta = { line, threads, interactive, gutterPosition };
|
|
123
|
-
tokens.splice(i + 1, 0, badgeToken);
|
|
124
|
-
}
|
|
125
|
-
// Highlight selected_text in the following inline token
|
|
126
|
-
if (inlineHighlights) {
|
|
127
|
-
const offset = showBadge ? 2 : 1;
|
|
128
|
-
const inlineAfter = tokens[i + offset];
|
|
129
|
-
if (inlineAfter && inlineAfter.type === "inline") {
|
|
130
|
-
for (const thread of threads) {
|
|
131
|
-
if (thread.comment.selected_text) {
|
|
132
|
-
highlightInlineText(inlineAfter, thread, interactive, TokenCtor);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
// Wrap the entire output in a gutter container when using left gutter
|
|
140
|
-
if (gutterPosition === "left" && processed.size > 0) {
|
|
141
|
-
const openToken = new TokenCtor("mrsf_gutter_open", "div", 1);
|
|
142
|
-
openToken.attrSet("class", "mrsf-gutter-container");
|
|
143
|
-
tokens.unshift(openToken);
|
|
144
|
-
const closeToken = new TokenCtor("mrsf_gutter_close", "div", -1);
|
|
145
|
-
tokens.push(closeToken);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
//# sourceMappingURL=core.js.map
|
package/dist/rules/renderer.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MRSF markdown-it plugin — renderer rules.
|
|
3
|
-
*
|
|
4
|
-
* Adds custom renderer rules for MRSF tokens:
|
|
5
|
-
* - mrsf_badge: renders badge + tooltip HTML (gutter)
|
|
6
|
-
* - mrsf_highlight_open/close: renders <mark> wrappers with inline tooltips
|
|
7
|
-
*/
|
|
8
|
-
function escapeHtml(str) {
|
|
9
|
-
return str
|
|
10
|
-
.replace(/&/g, "&")
|
|
11
|
-
.replace(/</g, "<")
|
|
12
|
-
.replace(/>/g, ">")
|
|
13
|
-
.replace(/"/g, """);
|
|
14
|
-
}
|
|
15
|
-
function formatTime(iso) {
|
|
16
|
-
if (!iso)
|
|
17
|
-
return "";
|
|
18
|
-
try {
|
|
19
|
-
const d = new Date(iso);
|
|
20
|
-
return d.toLocaleDateString(undefined, {
|
|
21
|
-
year: "numeric",
|
|
22
|
-
month: "short",
|
|
23
|
-
day: "numeric",
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return "";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function renderCommentHtml(comment, isReply, interactive) {
|
|
31
|
-
const resolvedClass = comment.resolved ? " mrsf-resolved" : "";
|
|
32
|
-
const replyClass = isReply ? " mrsf-reply" : "";
|
|
33
|
-
let html = `<span class="mrsf-comment${resolvedClass}${replyClass}" data-mrsf-comment-id="${escapeHtml(comment.id)}">`;
|
|
34
|
-
// Header
|
|
35
|
-
html += `<span class="mrsf-comment-header">`;
|
|
36
|
-
html += `<span class="mrsf-author">${escapeHtml(comment.author)}</span>`;
|
|
37
|
-
if (comment.timestamp) {
|
|
38
|
-
html += `<span class="mrsf-date">${escapeHtml(formatTime(comment.timestamp))}</span>`;
|
|
39
|
-
}
|
|
40
|
-
if (comment.severity) {
|
|
41
|
-
html += `<span class="mrsf-severity mrsf-severity-${escapeHtml(comment.severity)}">${escapeHtml(comment.severity)}</span>`;
|
|
42
|
-
}
|
|
43
|
-
if (comment.type) {
|
|
44
|
-
html += `<span class="mrsf-type">${escapeHtml(comment.type)}</span>`;
|
|
45
|
-
}
|
|
46
|
-
if (comment.resolved) {
|
|
47
|
-
html += `<span class="mrsf-resolved-badge">✓ resolved</span>`;
|
|
48
|
-
}
|
|
49
|
-
html += `</span>`;
|
|
50
|
-
// Selected text quote
|
|
51
|
-
if (comment.selected_text) {
|
|
52
|
-
html += `<span class="mrsf-selected-text">${escapeHtml(comment.selected_text)}</span>`;
|
|
53
|
-
}
|
|
54
|
-
// Body
|
|
55
|
-
html += `<span class="mrsf-comment-body">${escapeHtml(comment.text)}</span>`;
|
|
56
|
-
// Action buttons (interactive mode)
|
|
57
|
-
if (interactive) {
|
|
58
|
-
const line = comment.line != null ? String(comment.line) : "";
|
|
59
|
-
html += `<span class="mrsf-actions">`;
|
|
60
|
-
if (comment.resolved) {
|
|
61
|
-
html += `<button class="mrsf-action-btn" data-mrsf-action="unresolve" data-mrsf-comment-id="${escapeHtml(comment.id)}" data-mrsf-line="${line}">Unresolve</button>`;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
html += `<button class="mrsf-action-btn" data-mrsf-action="resolve" data-mrsf-comment-id="${escapeHtml(comment.id)}" data-mrsf-line="${line}">Resolve</button>`;
|
|
65
|
-
}
|
|
66
|
-
html += `<button class="mrsf-action-btn" data-mrsf-action="reply" data-mrsf-comment-id="${escapeHtml(comment.id)}" data-mrsf-line="${line}">Reply</button>`;
|
|
67
|
-
html += `<button class="mrsf-action-btn" data-mrsf-action="edit" data-mrsf-comment-id="${escapeHtml(comment.id)}" data-mrsf-line="${line}">Edit</button>`;
|
|
68
|
-
html += `</span>`;
|
|
69
|
-
}
|
|
70
|
-
html += `</span>`;
|
|
71
|
-
return html;
|
|
72
|
-
}
|
|
73
|
-
function renderThreadHtml(thread, interactive) {
|
|
74
|
-
let html = `<span class="mrsf-thread">`;
|
|
75
|
-
html += renderCommentHtml(thread.comment, false, interactive);
|
|
76
|
-
if (thread.replies.length > 0) {
|
|
77
|
-
html += `<span class="mrsf-replies">`;
|
|
78
|
-
for (const reply of thread.replies) {
|
|
79
|
-
html += renderCommentHtml(reply, true, interactive);
|
|
80
|
-
}
|
|
81
|
-
html += `</span>`;
|
|
82
|
-
}
|
|
83
|
-
html += `</span>`;
|
|
84
|
-
return html;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Install MRSF renderer rules on a markdown-it instance.
|
|
88
|
-
*/
|
|
89
|
-
export function installRendererRules(md) {
|
|
90
|
-
// Badge + tooltip (gutter)
|
|
91
|
-
md.renderer.rules["mrsf_badge"] = (tokens, idx) => {
|
|
92
|
-
const { line, threads, interactive, gutterPosition } = tokens[idx].meta;
|
|
93
|
-
const total = threads.reduce((n, t) => n + 1 + t.replies.length, 0);
|
|
94
|
-
const allResolved = threads.every((t) => t.comment.resolved);
|
|
95
|
-
const highestSeverity = threads.reduce((sev, t) => {
|
|
96
|
-
if (t.comment.severity === "high" || sev === "high")
|
|
97
|
-
return "high";
|
|
98
|
-
if (t.comment.severity === "medium" || sev === "medium")
|
|
99
|
-
return "medium";
|
|
100
|
-
if (t.comment.severity === "low" || sev === "low")
|
|
101
|
-
return "low";
|
|
102
|
-
return sev;
|
|
103
|
-
}, null);
|
|
104
|
-
const resolvedClass = allResolved ? " mrsf-badge-resolved" : "";
|
|
105
|
-
const severityClass = highestSeverity === "high" || highestSeverity === "medium"
|
|
106
|
-
? ` mrsf-badge-severity-${highestSeverity}`
|
|
107
|
-
: "";
|
|
108
|
-
const positionClass = ` mrsf-gutter-${gutterPosition}`;
|
|
109
|
-
const icon = allResolved ? "✓" : "💬";
|
|
110
|
-
let html = `<span class="mrsf-tooltip-anchor${positionClass}">`;
|
|
111
|
-
// Badge
|
|
112
|
-
html += `<span class="mrsf-badge${resolvedClass}${severityClass}" data-mrsf-line="${line}" data-mrsf-action="navigate" data-mrsf-comment-id="${escapeHtml(threads[0].comment.id)}" tabindex="0">${icon} ${total}</span>`;
|
|
113
|
-
// Tooltip
|
|
114
|
-
html += `<span class="mrsf-tooltip" data-mrsf-line="${line}">`;
|
|
115
|
-
for (const thread of threads) {
|
|
116
|
-
html += renderThreadHtml(thread, interactive);
|
|
117
|
-
}
|
|
118
|
-
html += `</span>`;
|
|
119
|
-
html += `</span>`;
|
|
120
|
-
return html;
|
|
121
|
-
};
|
|
122
|
-
// Highlight open — wraps in tooltip-anchor for inline hover (feature D)
|
|
123
|
-
md.renderer.rules["mrsf_highlight_open"] = (tokens, idx) => {
|
|
124
|
-
const token = tokens[idx];
|
|
125
|
-
const cls = token.attrGet("class") || "mrsf-highlight";
|
|
126
|
-
const commentId = token.attrGet("data-mrsf-comment-id") || "";
|
|
127
|
-
const thread = token.meta?.thread;
|
|
128
|
-
let html = "";
|
|
129
|
-
if (thread) {
|
|
130
|
-
html += `<span class="mrsf-tooltip-anchor mrsf-inline-anchor">`;
|
|
131
|
-
}
|
|
132
|
-
html += `<mark class="${escapeHtml(cls)}" data-mrsf-comment-id="${escapeHtml(commentId)}" tabindex="0">`;
|
|
133
|
-
return html;
|
|
134
|
-
};
|
|
135
|
-
// Highlight close — adds inline tooltip and closes tooltip-anchor
|
|
136
|
-
md.renderer.rules["mrsf_highlight_close"] = (tokens, idx) => {
|
|
137
|
-
const token = tokens[idx];
|
|
138
|
-
const meta = token.meta;
|
|
139
|
-
let html = "</mark>";
|
|
140
|
-
if (meta?.thread) {
|
|
141
|
-
const thread = meta.thread;
|
|
142
|
-
const interactive = meta.interactive;
|
|
143
|
-
html += `<span class="mrsf-tooltip mrsf-inline-tooltip">`;
|
|
144
|
-
html += renderThreadHtml(thread, interactive);
|
|
145
|
-
html += `</span>`;
|
|
146
|
-
html += `</span>`;
|
|
147
|
-
}
|
|
148
|
-
return html;
|
|
149
|
-
};
|
|
150
|
-
// Gutter container wrapper (left gutter mode)
|
|
151
|
-
md.renderer.rules["mrsf_gutter_open"] = (tokens, idx) => {
|
|
152
|
-
const cls = tokens[idx].attrGet("class") || "mrsf-gutter-container";
|
|
153
|
-
return `<div class="${escapeHtml(cls)}">`;
|
|
154
|
-
};
|
|
155
|
-
md.renderer.rules["mrsf_gutter_close"] = () => {
|
|
156
|
-
return `</div>`;
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=renderer.js.map
|
package/dist/shared.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared logic for @mrsf/markdown-it-mrsf.
|
|
3
|
-
*
|
|
4
|
-
* Contains the plugin factory, comment transformation, and grouping logic
|
|
5
|
-
* used by both the Node.js (index.ts) and browser (browser.ts) entry points.
|
|
6
|
-
*/
|
|
7
|
-
import { installCoreRule } from "./rules/core.js";
|
|
8
|
-
import { installRendererRules } from "./rules/renderer.js";
|
|
9
|
-
/**
|
|
10
|
-
* Convert an MrsfDocument into a slim comment array.
|
|
11
|
-
*/
|
|
12
|
-
export function toSlimComments(doc) {
|
|
13
|
-
return doc.comments.map((c) => ({
|
|
14
|
-
id: c.id,
|
|
15
|
-
author: c.author || "Unknown",
|
|
16
|
-
text: c.text || "",
|
|
17
|
-
line: c.line ?? null,
|
|
18
|
-
end_line: c.end_line ?? null,
|
|
19
|
-
start_column: c.start_column ?? null,
|
|
20
|
-
end_column: c.end_column ?? null,
|
|
21
|
-
selected_text: c.selected_text || null,
|
|
22
|
-
resolved: !!c.resolved,
|
|
23
|
-
reply_to: c.reply_to || null,
|
|
24
|
-
severity: c.severity || null,
|
|
25
|
-
type: c.type || null,
|
|
26
|
-
timestamp: c.timestamp || null,
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Group comments by line number, threading replies under parents.
|
|
31
|
-
*/
|
|
32
|
-
export function groupByLine(comments) {
|
|
33
|
-
const rootComments = comments.filter((c) => !c.reply_to && c.line != null);
|
|
34
|
-
const replies = comments.filter((c) => c.reply_to);
|
|
35
|
-
const replyMap = new Map();
|
|
36
|
-
for (const r of replies) {
|
|
37
|
-
const list = replyMap.get(r.reply_to) || [];
|
|
38
|
-
list.push(r);
|
|
39
|
-
replyMap.set(r.reply_to, list);
|
|
40
|
-
}
|
|
41
|
-
const lineMap = new Map();
|
|
42
|
-
for (const c of rootComments) {
|
|
43
|
-
const line = c.line;
|
|
44
|
-
const threads = lineMap.get(line) || [];
|
|
45
|
-
threads.push({
|
|
46
|
-
comment: c,
|
|
47
|
-
replies: replyMap.get(c.id) || [],
|
|
48
|
-
});
|
|
49
|
-
lineMap.set(line, threads);
|
|
50
|
-
}
|
|
51
|
-
return lineMap;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a markdown-it plugin function with the given comment loader.
|
|
55
|
-
*
|
|
56
|
-
* @param loader - Function that resolves sidecar data from plugin options
|
|
57
|
-
* @returns A markdown-it plugin function
|
|
58
|
-
*/
|
|
59
|
-
export function createMrsfPlugin(loader) {
|
|
60
|
-
return function mrsfPlugin(md, options = {}) {
|
|
61
|
-
const showResolved = options.showResolved ?? true;
|
|
62
|
-
const interactive = options.interactive ?? false;
|
|
63
|
-
const gutterPosition = options.gutterPosition ?? "right";
|
|
64
|
-
const gutterForInline = options.gutterForInline ?? true;
|
|
65
|
-
const inlineHighlights = options.inlineHighlights ?? true;
|
|
66
|
-
const doc = loader(options);
|
|
67
|
-
if (!doc || !doc.comments || doc.comments.length === 0) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
let comments = toSlimComments(doc);
|
|
71
|
-
if (!showResolved) {
|
|
72
|
-
comments = comments.filter((c) => !c.resolved);
|
|
73
|
-
}
|
|
74
|
-
if (comments.length === 0)
|
|
75
|
-
return;
|
|
76
|
-
const lineMap = groupByLine(comments);
|
|
77
|
-
installCoreRule(md, lineMap, {
|
|
78
|
-
interactive,
|
|
79
|
-
gutterPosition,
|
|
80
|
-
gutterForInline,
|
|
81
|
-
inlineHighlights,
|
|
82
|
-
});
|
|
83
|
-
installRendererRules(md);
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
//# sourceMappingURL=shared.js.map
|