Skip to content

Commit 29d564f

Browse files
committed
feat: allow line highlighting accepts extract options
1 parent 2c84c7e commit 29d564f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/client/builtin/CodeHighlightController.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const props = defineProps({
2121
ranges: {
2222
default: () => [],
2323
},
24+
at: {
25+
default: undefined,
26+
},
2427
})
2528
2629
const clicks = inject(injectionClicks)!
@@ -40,7 +43,7 @@ const el = ref<HTMLDivElement>()
4043
const vm = getCurrentInstance()
4144
4245
onMounted(() => {
43-
const prev = elements.value.length
46+
const prev = props.at == null ? elements.value.length : props.at
4447
const index = computed(() => {
4548
if (disabled.value)
4649
return props.ranges.length - 1

packages/slidev/node/plugins/markdown.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ export function truncateMancoMark(code: string) {
101101
* Transform Monaco code block to component
102102
*/
103103
export function transformHighlighter(md: string) {
104-
return md.replace(/^```(\w+?)\s*{([\d\w*,\|-]+)}[\s\n]*([\s\S]+?)^```/mg, (full, lang = '', rangeStr: string, code: string) => {
104+
return md.replace(/^```(\w+?)\s*{([\d\w*,\|-]+)}\s*({.*?})[\s\n]*([\s\S]+?)^```/mg, (full, lang = '', rangeStr: string, options = '', code: string) => {
105105
const ranges = rangeStr.split(/\|/g).map(i => i.trim())
106-
return `\n<CodeHighlightController :ranges='${JSON.stringify(ranges)}'>\n\n\`\`\`${lang}\n${code}\n\`\`\`\n\n</CodeHighlightController>`
106+
options = options.trim() || '{}'
107+
return `\n<CodeHighlightController v-bind="${options}" :ranges='${JSON.stringify(ranges)}'>\n\n\`\`\`${lang}\n${code}\n\`\`\`\n\n</CodeHighlightController>`
107108
})
108109
}
109110

0 commit comments

Comments
 (0)