MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.45k stars 1.09k forks source link

How to use command line (terminal shell) syntax highlight? #1039

Closed sgon00 closed 5 years ago

sgon00 commented 5 years ago

My Workaround Solution

Complete Code at https://gist.github.com/sgon00/836386ba8b16e95297e4e5aa0a7089ae Hopefully, this may help others who want to use terminal shell instead of bash.

Old Story and Question

Hi, I found out prismjs does support command line syntax highlight with this link: https://prismjs.com/plugins/command-line/.

I also found out the file /Applications/MacDown.app/Contents/Resources/Prism/components.js has the line "command-line": {.

But I failed to figure out how to use it? I tried

```command-line
$ ls
```command
$ ls
```shell
$ ls

None of them works. Thanks.

PS:

I also tried

```powershell
$ ls

even if it's not powershell, but it still does not work.

MacOS is Unix-like system. I use command line and terminal everyday. I just want the $ sign to be greyed out and not selectable. Thanks.

FranklinYu commented 5 years ago

command-line is a plugin, not a language. You can’t specify a plugin in block quote.

I understand your need, but specifying Prism plugin in Markdown won’t be portable at all. I don’t think @uranusjr is interested in “inventing our own Markdown”. If you want to suggest new Markdown syntax, you may want to discuss in CommonMark community.

sgon00 commented 5 years ago

@FranklinYu thanks a lot for the quick reply. If that is the case, is that possible to use https://github.com/highlightjs/highlight.js instead of Prismjs somehow? Something like putting it at /Applications/MacDown.app/Contents/Resources/ and modifying some config files etc.. highlight.js has much better syntax support than Prismjs. Thank you very much.

FranklinYu commented 5 years ago

Typically we cannot make every component swappable, but if Prism is seriously broken we may consider switching to other libraries. For example the MathJax v.s. KaTeX case (although at last we decided not to switch).

highlight.js has much better syntax support than Prismjs

Care to elaborate? Prism works for me except that some rare language is not supported. In addition the author is pretty famous in front-end community.

sgon00 commented 5 years ago

@FranklinYu thank you very much for your reply. Can I ask another question here? I am trying to make a new shell language js file. I added the following to /Applications/MacDown.app/Contents/Resources/Prism/components.js:

"shell": {
    "title": "Shell",
    "owner": "abc"
},

and then created the files prism-shell.min.js and prism-shell.js at /Applications/MacDown.app/Contents/Resources/Prism/components. Quit and Restart MacDown.app. But after this, I still can NOT use

```shell

What else should I modify to add this new syntax? Thank you very much for your help.

sgon00 commented 5 years ago

@FranklinYu OK, I finally figured out why. Please ignore my last question. Other than changing the filename, I also need to change Prism.languages.bash to Prism.languages.shell in the file prism-shell.min.js.