-
-
Notifications
You must be signed in to change notification settings - Fork 605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow ] in filename code block #2169
Changes from 1 commit
d8e8c93
3a69417
07a4296
8d110cb
28707f5
aae3254
a9b8afb
bd4fcfa
3d8b2cb
c51b08e
a536c58
e0ff29c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts" setup> | ||
defineProps<{ | ||
code: string, | ||
language?: string, | ||
filename?: string, | ||
highlights: number[], | ||
meta?: string | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<span v-if="filename"> {{ filename }} </span> | ||
<slot /> | ||
</template> | ||
|
||
<style> | ||
pre code .line { | ||
display: block; | ||
min-height: 1rem; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```vue [[...page].vue] | ||
<template> | ||
<div> | ||
<h1>Custom Prose</h1> | ||
</div> | ||
</template> | ||
``` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ export function parseThematicBlock (lang: string) { | |||||
|
||||||
const language = lang.replace(/[{|[](.+)/, '').match(/^[^ \t]+(?=[ \t]|$)/) | ||||||
const highlightTokens = lang.match(/{([^}]*)}/) | ||||||
const filenameTokens = lang.match(/\[([^\]]*)\]/) | ||||||
const filenameTokens = lang.match(/\[(.*)\]/) /** Allow ']' in filename. @see https://regex101.com/r/Hm0t5m/1 */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And because of GitHub, I'm not allowed to suggest changes out of some range: Change for L29: - filename: Array.isArray(filenameTokens) && filenameTokens[1] ? filenameTokens[1] : undefined,
+ filename: Array.isArray(filenameTokens) && filenameTokens[1] ? filenameTokens[1].replace(/\\]/g, ']') : undefined, To remove the now redundant backslashes. |
||||||
const meta = lang.replace(/^\w*\s*(\[[^\]]*\]|\{[^}]*\})?\s*(\[[^\]]*\]|\{[^}]*\})?\s*/, '') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
To replace the correct part, to have the meta left. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I refactor this to be more understandable and to reuse previous regex. |
||||||
|
||||||
return { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we used
[^\]]
to allow using lists in the meta part.Here's an example what would not work anymore if we match the longest string.
It would match this content
filename]{hightlights} meta=[...
as the filenameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we could use something like
\]
in the markdown and prevent matching those somehowThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh I understand. I do it too quickly!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, that this might work:
/\[((\\]|[^\]])*)\]/
This part
(\\]|[^\]])*
matches zero or one or a sequence of:\]
or characters that are not]
Only if our string has no more
]
after a\]
it terminates the match at a\]
.So this works:
=>
[...slug\].vue
as the first group match.Then we only have to replace
\]
which in reality is\\]
with]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but if there is no meta, this regex is not working.
https://regex101.com/r/bG0Net/1
EDIT: User must set a , I understand.