-
-
Notifications
You must be signed in to change notification settings - Fork 661
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(code-block): meta property #2067
Conversation
β Deploy Preview for nuxt-content canceled.
|
const highlightTokens = lang.match(/{([^}]+)}/) | ||
const filenameTokens = lang.match(/\[(.+)\]/) | ||
const meta = lang.replace(/^\w+\s*(\[[^\]]+\])?\s*(\{[^}]+\})?\s*/g, '') |
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.
Previous comment:
A problem is, that the meta
regex has a fixed order for lang [β¦] {β¦} meta
It is not replaced if we write lang {β¦} [β¦] meta
, even though L21-22 allow different ordering.
Also, if we want to use {β¦}
or [β¦]
in the meta
block, but not provide highlights
or a filename
, it will be matched (by L21-22).
Maybe, the user could provide an empty []
or {}
block before the meta
to prevent it from reading those parts in the meta.
Something like: lang [] meta=['not', 'a', 'filename']
would be possible then
In my opinion, we should also trim
the lang
property before checking if it is empty (adding it in L11)
lang = lang.trim()
Also return undefined
(or an empty string ''
) for the meta
if lang
is empty (adding in L17)
{
// ...
meta: undefined
}
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.
Looks good to me.
But I don't know if it's good to return empty strings on empty filename
, or if we should return undefined
instead... π€
What do you think?
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.
This would be my change, if we don't want to return empty strings.
Co-authored-by: nobkd <[email protected]>
π Linked issue
resolves #2059
β Type of change
π Description
π Checklist