-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Markdown: Added support for code blocks #1562
Markdown: Added support for code blocks #1562
Conversation
How I use this for Objective-C? What I should write after "```"? |
@ripperhe |
But it not works for me. When I use it for ruby or bash is OK, only use it for Objective-C is not available. I have add this to index.html <script src="//unpkg.com/prismjs/components/prism-objectivec.min.js"></script> But it not works for me . This is the final result. https://ripperhe.com/ZYDebugo/#/Guide/quick-login This is GitHub link https://github.com/ripperhe/ZYDebugo/blob/master/docs/Guide/quick-login.md I had add |
@ripperhe That's because you are using https://unpkg.com/prismjs@1.15.0/ which does not include this PR. |
@RunDevelopment So, how can I get the latest prism code for Objective-C? What should I write in index.html? Please tell the solution, thank you! 🙏 |
@ripperhe I highly suggest you wait until this PR is reviewed and (hopefully) included in the latest release (which might take a few weeks). If you really need this feature for your website right now, you can do the following:
|
@RunDevelopment OK, I see. Thank you very much. 🙏 |
This reverts commit 2d622f1.
Looks like there are some conflicts here to resolve. |
|
||
Prism.hooks.add('after-tokenize', function (env) { | ||
if (env.language !== 'markdown') | ||
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'm not sure what our style policy is on this, but I generally prefer {}
around if
blocks like this.
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, looks like core uses {}
with if
blocks. Otherwise, code looks good. Love this improvement.
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.
You're right!
Thought for the future: can we integrate w/ the autoloader so you can write Markdown & it'll autoload the languages you need? |
I also thought about but for that would we need the Autoloader itself to expose the API and find a clever way to highlight the code asynchronously after the markdown pass. |
It also supports syntax highlighting! The highlighting is done in two steps: 1. Add an alias `language-****` containing the given language to the `code-block` token. This happens in the `after-tokenize` hook. 2. Highlight the code with the `wrap` hook. This is to get around the encoding (`util.encode`) of tokens in `Prism.highlight`. By using this procedure we get the correct execution of the `before-tokenize`, `after-tokenize`, and `wrap` hook for all included languages.
This PR adds support for markdown backtick code blocks.
The new code is intentionally written so that we can easily write a plugin which highlights the code block with the given language.I actually intended that the language does that itself, but that turned out to be really difficult and it lacks certain features, so a plugin it is then.It now also supports syntax highlighting!
The highlighting is done in two steps:
language-****
containing the given language to thecode-block
token.This happens in the
after-tokenize
hook.wrap
hook.This is to get around the encoding (
util.encode
) of tokens inPrism.highlight
.By using this procedure we get the correct execution of the
before-tokenize
,after-tokenize
, andwrap
hook for all included languages.Btw: This implementation would have benefitted from #1524.
Example