-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Rebuild Custom code blocks languages #2338
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
Conversation
|
||
module.exports = jslinks; | ||
|
||
jslinks.displayName = 'jslinks'; |
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.
It seems this property should be the same as the code snippet language.
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.
Should we keep all the commented code?
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.
From the original PR text:
File js-with-links.js will be moved to https://github.com/montogeek/remark-refractor as well.
It means commented code will be deleted, as it is right now: https://github.com/montogeek/remark-refractor/blob/master/src/index.js
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.
Need cleanup.
@@ -41,11 +41,6 @@ | |||
"serve": "npm run build && sirv start ./dist --port 4000", | |||
"deploy": "gh-pages -d dist" | |||
}, | |||
"husky": { |
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.
Will revert
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.
👍
try { | ||
data.hChildren = refractor.highlight(node.value, lang); | ||
|
||
for (let index = 0; index < data.hChildren.length; index++) { |
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 find all comments in the tree and update every one by inject a link element.
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.
Can we rename the hChildren
to something more meaningful. It can be just hastChildren
or children
, or hastNodes
.
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.
It can't, otherwise other libraries won't read it.
That is how it works: https://github.com/syntax-tree/mdast-util-to-hast/
} | ||
|
||
try { | ||
data.hChildren = refractor.highlight(node.value, lang); |
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.
refractor
returns a hast tree.
if (element.properties && element.properties.className.includes('comment')) { | ||
const { value } = element.children[0]; | ||
|
||
let match = /\[([^[\]]+?)\]\((.+?)\)/.exec(value); |
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 Regex find all comments, it is from markdown.js
file.
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.
Can we place a comment for this then?
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.
Yeah
if (match !== null) { | ||
const [, text, url] = match; | ||
|
||
element.children = [ |
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.
Node children are:
//
- An empty space
- Link
} | ||
} | ||
|
||
node.children = [node.data.hChildren]; |
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.
Will removed this line, it is not necessary.
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.
👍
.replace(/<!--[\s\S]*?-->/g, ''); | ||
.replace(/<!--[\s\S]*?-->/g, '') | ||
// Replace code | ||
.replace(/```console/g, '```bash') |
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 new 2 lines save a lot of Prism warnings.
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.
do you think its worth it replacing content on the fly? i would suggest find replace console ->
bash, or is this issue coming from external readme files we fetch?
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 kinda have the feeling that we should open a PR in projects using console
and change it instead of this because it is not a valid language option in markdown regarding highlighting.
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.
@EugeneHlushko Yes, it is from external readmes.
@jeremenichelli Yep :D, will revert
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.
We can keep this, until we replace it in all READMEs.
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 already talked to @shellscape, console is better because GitHub support is richer than bash
.
This is easily fixed with a plugin, just registering it using Prism:
Prism.languages['console'] = Prism.languages.extend('sh', {})
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.
Great job man, just some minor comments to address.
|
||
module.exports = jslinks; | ||
|
||
jslinks.displayName = 'jslinks'; |
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.
Should we keep all the commented code?
@@ -41,11 +41,6 @@ | |||
"serve": "npm run build && sirv start ./dist --port 4000", | |||
"deploy": "gh-pages -d dist" | |||
}, | |||
"husky": { |
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.
👍
try { | ||
data.hChildren = refractor.highlight(node.value, lang); | ||
|
||
for (let index = 0; index < data.hChildren.length; index++) { |
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.
Can we rename the hChildren
to something more meaningful. It can be just hastChildren
or children
, or hastNodes
.
if (element.properties && element.properties.className.includes('comment')) { | ||
const { value } = element.children[0]; | ||
|
||
let match = /\[([^[\]]+?)\]\((.+?)\)/.exec(value); |
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.
Can we place a comment for this then?
} | ||
} | ||
|
||
node.children = [node.data.hChildren]; |
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.
👍
} | ||
|
||
data.hProperties = data.hProperties || {}; | ||
data.hProperties.className = ['hljs', ...(data.hProperties.className || []), `language-${lang}`]; |
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.
Same as above, can we rename the hProperties
to something more readable?
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.
We can't, same reason as hChildren
, that is how unified ecosystem works.
.replace(/<!--[\s\S]*?-->/g, ''); | ||
.replace(/<!--[\s\S]*?-->/g, '') | ||
// Replace code | ||
.replace(/```console/g, '```bash') |
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.
We can keep this, until we replace it in all READMEs.
I will revamp this PR, after working a bit more with |
Closing in favour of #2564 |
After 4 hours doing this I finally managed to solve it.
This PR introduces support for custom
js-with-links
code blocks.File
prism-links.js
is a copy of https://github.com/montogeek/remark-refractor, once this PR is merged I will update the dependency.File
js-with-links.js
will be moved to https://github.com/montogeek/remark-refractor as well.One changed is necessary, update
js-with-links
tojslinks
, I am not 100% sure, but it seems Prism doesn't like composed names.Also updated our process readme script to replace weird code examples (
console
,sh
) tobash
.Update our content removing wrong and unnecessary code languages.