Skip to content

Commit 56bbf95

Browse files
author
Jesse Haigh
committed
lineAnnotations replace specific options for highlight/strikeout
1 parent d1fc671 commit 56bbf95

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/components/ContentNode.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ function renderNode(createElement, references) {
276276
showLineNumbers: node.showLineNumbers,
277277
copyToClipboard: node.copyToClipboard ?? false,
278278
wrap: node.wrap ?? 0,
279-
highlightedLines: node.highlight ?? [],
280-
strikethroughLines: node.strikeout ?? [],
279+
lineAnnotations: node.lineAnnotations ?? [],
281280
};
282281
return createElement(CodeListing, { props });
283282
}

src/components/ContentNode/CodeListing.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,9 @@ export default {
114114
type: Number,
115115
default: () => 0,
116116
},
117-
highlightedLines: {
117+
lineAnnotations: {
118118
type: Array,
119119
default: () => [],
120-
validator: lines => lines.every(number => Number.isInteger(number) && number > 0),
121-
},
122-
strikethroughLines: {
123-
type: Array,
124-
default: () => [],
125-
validator: lines => lines.every(number => Number.isInteger(number) && number > 0),
126-
127120
},
128121
startLineNumber: {
129122
type: Number,
@@ -162,11 +155,23 @@ export default {
162155
isHighlighted(index) {
163156
return this.highlightedLineNumbers.has(this.lineNumberFor(index));
164157
},
158+
isLineInStyle(index, style) {
159+
const lineNumber = this.lineNumberFor(index);
160+
161+
return this.lineAnnotations
162+
.filter(a => a.style === style)
163+
.some((a) => {
164+
if (!a.range || !a.range[0] || !a.range[1]) return false;
165+
const startLine = a.range[0].line;
166+
const endLine = a.range[1].line;
167+
return lineNumber >= startLine && lineNumber <= endLine;
168+
});
169+
},
165170
isUserHighlighted(index) {
166-
return this.highlightedLines.includes(this.lineNumberFor(index));
171+
return this.isLineInStyle(index, 'highlight');
167172
},
168173
isUserStrikethrough(index) {
169-
return this.strikethroughLines.includes(this.lineNumberFor(index));
174+
return this.isLineInStyle(index, 'strikeout');
170175
},
171176
// Returns the line number for the line at the given index in `content`.
172177
lineNumberFor(index) {

0 commit comments

Comments
 (0)