-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Update language-highlight.md #1251
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/fvu66nrrm |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9f3cf1e:
|
@@ -8,4 +8,25 @@ | |||
<script src="//cdn.jsdelivr.net/npm/prismjs/components/prism-php.min.js"></script> | |||
``` | |||
|
|||
To use the new languages, make sure the code block label matches the part after `prism-` in the file name. FOr example, for `prism-bash.js` write a code block labeled with `bash` 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.
Minor typo: "FOr" should be "For" (lower-case "O").
``` | ||
```` | ||
|
||
?> Note that with GitHub-flavored markdown, `sh` and `bash` are effectively aliases of each other, but this is not the case with Prism. So using `sh` will not enable `bash` syntax in this case. |
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 is confusing for a few reasons:
- GitHub-flavored markdown doesn't handle syntax highlighting (see spec). I think you're referring to how GitHub handles markdown.
- Docsify supports GitHub-flavored markdown (see the Supported Markdown specifications for marked)
- Prism's source lists
sh
as an alias forbash
. - Prism's docs list
shell
as an alias forbash
(andsh
is an alias forshell
).
I suggest we just delete the ?> Note...
section.
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.
GitHub-flavored markdown doesn't handle syntax highlighting
Maybe I should say "Markdown on GitHub".
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.
Prism's source lists sh as an alias for bash.
When I add prism-bash.js
and use sh
as the syntax it doesn't highlight. Same with shell
. bash
works though. Is it new? Does it work for you? Maybe I need an update.
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 was incorrect about sh
being an alias for shell
and bash
in the Prism source (it was late 🤷 ). Prism simply associates sh
as a file extension for bash scripts.
The difference between GitHub and Prism highlighting is:
-
Prism requires using the alias(es) listed in their docs. For Bash, Prism lists only
bash
andshell
. I can confirm bothbash
andshell
work as expected in docsify-themeable, whilesh
does not work: -
GitHub (it appears) uses file extensions (like
sh
) in addition to the usual aliases. Notice how the same markdown from the screenshot above renders here on GitHub (specifically, the propersh
highlighting):# bash echo "hello"
# shell echo "hello"
# sh echo "hello"
To confirm this, I tried to find another file type that Prism associates an extension with but does not list as an alias. Batch has a file extension of
bat
in the source but only listsbatch
as an alias in the docs so this is a good match. Here's howbatch
andbat
render on docsify-themeable:And here's how that above markdown renders here on GitHub:
:: batch @ECHO "HELLO"
:: bat @ECHO "HELLO"
Summary: Docsify uses Prism aliases only, GitHub uses language aliases and extensions.
|
||
?> Note that with GitHub-flavored markdown, `sh` and `bash` are effectively aliases of each other, but this is not the case with Prism. So using `sh` will not enable `bash` syntax in this case. | ||
|
||
For `prism-php.js`, it would be: |
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 we need two examples? If we want two, why not use one of the built-in languages (css
, html
, or js
) and one that requires loading an additional language?
@sy-records I realize this has already been merged, but there are a few tweaks in here worth making. Also, the "At least 2 approving reviews are required to merge this pull request" rule generally means "two reviews not including your own if you are the person who submitted the PR". |
Sorry, This was PR by @trusktr submitted, I modified a PHP syntax error. I reviewed it with @Koooooo-7 ...😅 @trusktr Can you resubmit a PR to fix these problems? |
Oh no, why is it submitted to the master branch? ? ?😱 |
Ahh. Sorry, @sy-records. I saw your edit and thought it was your PR. |
@jhildenbiddle sorry for missing checking the details of documentation. @sy-records , we need revert this PR from |
Let's submit another PR. @Koooooo-7 @trusktr |
@Koooooo-7 -- No worries at all. That's what multiple reviewers are for. 😄 |
Whoops, I didn't check what branch it merged to when I opened it. I think by default GitHub sets the target branch to whatever the default branch is (should be develop). I'm not on the comp, I'll check later. Sure, I can also submit updates. |
A general rule that I believe we should follow: Unless the PR author is unresponsive, let's let the PR author merge the PR after it is approved, and not the reviewers. The author might have ideas or want to change something, or similar. |
@trusktr -- How about something like this: Language highlightingDocsify uses Prism to highlight code blocks in your pages. Prism supports the following languages by default:
Support for additional languages is available by loading the language-specific grammar files via CDN: <script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-php.min.js"></script> To enable syntax highlighting, wrap each code block in triple backticks with the language specified on the first line:
The above markdown will be rendered as: <p>This is a paragraph</p>
<a href="//docsify.js.org/">Docsify</a> echo "hello" function getAdder(int $x): int
{
return 123;
} |
That sounds great! I will hit accept if you copy/paste it to a PR. |
@trusktr -- Will do. 😄 |
Proposed changes described in comment from #1251
* Update language-highlight.md * Update language-highlight.md Co-authored-by: 沈唁 <52o@qq52o.cn>
Proposed changes described in comment from docsifyjs#1251
Summary
Add some details regarding syntax highlight.
What kind of change does this PR introduce? (check at least one)