Code Monkey home page Code Monkey logo

shiki's Introduction

shiki's People

Contributors

antfu avatar banga avatar blake-mealey avatar bluwy avatar codepunkt avatar dependabot[bot] avatar enter-tainer avatar fengzilong avatar fredkschott avatar gerrit0 avatar ije avatar jadhielv avatar jonaskruckenberg avatar jxom avatar kevinbatdorf avatar leodog896 avatar mariusschulz avatar mashehu avatar muenzpraeger avatar nullvoxpopuli avatar oblongmana avatar octref avatar orta avatar oskargroth avatar sachinraja avatar stonecypher avatar uncenter avatar vap0r1ze avatar vladimirmikulic avatar ydcjeff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shiki's Issues

Wrong HTML escape sequences in demo

image

It seems that the implementation of html escape is wrong.

function escapeHtml(html: string) {
  return html
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/&/g, '&amp;')
    .replace(/'/g, '&apos;')
}

It firstly converts > to &gt, then converts &gt to &ampgt, which is not what we expected.

I suggest checking out the implementation of lodash.

Next.js example

Hello, I would like to use Shiki in one my Next.js project, and I'm not sure how to set up Shiki properly (e.g. the best way)

Any recommendations / examples please?

I also use MDX if it helps

Line numbers

Would it be possible to add support for line numbers?

Bonus points for not restricting you to auto-generate them either. For example, when showing a Git diff, the line numbers will change.

Java - strictfp modifier

From the Java Language Specification:

8.1.1.3 strictfp Classes
The effect of the strictfp modifier is to make all float or double expressions
within  the  class  declaration  (including  within  variable  initializers,  instance
initializers, static initializers, and constructors) be explicitly FP-strict (§15.4).
This implies that all methods declared in the class, and all nested types declared in
the class, are implicitly strictfp.

This modifier doesn't exist in the java.json file. So the syntax highlighting can't work for that.

PHP highlighting not working

Hey 👋

It seems that PHP code blocks without a <?php opening tag don't get colorised correctly.

I've tested and if you add a <?php tag, everything starts working correctly.

I guess this is probably an upstream issue?

Accept plaintext

If the language is undefined - there's an error

highlighter.codeToHtml('', undefined);

TypeError: Cannot read property 'tokenizeLine' of undefined

But I just want to have a simple block (just like GFM):

no highlighting

Using plaintext, txt, text doesn't work

highlighter.codeToHtml('', 'plaintext');

shiki-languages seems to be missing plaintext too.

export declare type TCommonLang = 'clojure' | 'c' | 'cpp' | 'css' | 'go' | 'html' | 'jade' | 'java' | 'jsx' | 'javascript' | 'json' | 'less' | 'lua' | 'makefile' | 'markdown' | 'objective-c' | 'perl6' | 'php' | 'python' | 'r' | 'ruby' | 'rust' | 'scss' | 'shellscript' | 'sql' | 'swift' | 'typescript' | 'tsx' | 'xml' | 'yaml'
/**
 * Extra grammars
 */
 | 'haml' | 'graphql' | 'postcss' | 'sass' | 'stylus' | 'vue' | 'vue-html' | 'latex';
export declare type TCommonLangAlias = 'clj' | 'c++' | 'htm' | 'xhtml' | 'js' | 'objc' | 'py' | 'rb' | 'shell' | 'bash' | 'sh' | 'ts'
/**
 * Extra grammars
 */
 | 'styl' | 'tex';
export declare type TOtherLang = 'bat' | 'coffeescript' | 'diff' | 'dockerfile' | 'fsharp' | 'git-commit' | 'git-rebase' | 'groovy' | 'handlebars' | 'ini' | 'properties' | 'perl' | 'powershell' | 'razor' | 'shaderlab' | 'vb' | 'xsl';
export declare type TLang = TCommonLang | TCommonLangAlias | TOtherLang;

& instead of &amp;

const main = async () => {
  const shiki = require('shiki')
  const highlighter = await shiki.getHighlighter({ theme: 'monokai' })
  const code = 'a & b > c'
  const lang = 'js'
  console.log(highlighter.codeToHtml(code, lang))
}

main()

generates

<pre class="shiki" style="background-color: #272822"><code><span style="color: #F8F8F2">a </span><span style="color: #F92672">&</span><span style="color: #F8F8F2"> b </span><span style="color: #F92672">&gt;</span><span style="color: #F8F8F2"> c</span></code></pre>

instead of

<pre class="shiki" style="background-color: #272822"><code><span style="color: #F8F8F2">a </span><span style="color: #F92672">&amp;</span><span style="color: #F8F8F2"> b </span><span style="color: #F92672">&gt;</span><span style="color: #F8F8F2"> c</span></code></pre>

language grammer cannot be symlinks

I am currently tuning my c++ grammar heavily, so I moved it out of the directory and created a symlink inside. This makes running the shiki process fail.

Some VSCode themes are not proprely configured

Problem: Trying to use solarized_dark, solarized_light, or monokai_dimmed themes doesn't work.

Solution: The names of the themes does not match the name of the theme file, and so Shiki can't find the theme. Since the file names are set by VSCode, the names in the code should be changed to match the file names.

  • solarized_dark → solarized-dark
  • solarized_light → solarized-light
  • monokai_dimmed → dimmed-monokai

Automate the language updating

The languages package shares a lot in common with tsconfig/bases - I think I can port over some of that code (from deno (unless you'd prefer to have some deno scripting?)) to automate the acquisition of the tmlanaguges, check if they're updated and then publish a new copy of the languages package.

How to use tmLanguage files by path?

How do I use a custom grammar, in the form of a string of it's path for the syntax highlighting in shiki?
I want to do this in the function shiki.codeToHtml().

[feature request] import syntaxes and themes from dependency

Hi there! shiki is really awesome and thanks for your effort.

I hope syntaxes and themes will be available from dependency so we can make the most of the vast ecosystem of vscode.

Example:

// package.json
{
  "dependencies": {
    "vscode-night-owl": "https://github.com/sdras/night-owl-vscode-theme",
    "vscode-rainbow-csv": "https://github.com/mechatroner/vscode_rainbow_csv"
  }
}
shiki.use('vscode-night-owl')
shiki.use('vscode-rainbow-csv')

shiki.getHighlighter({
  theme: 'night-owl'
}).then(highlighter => {
  return highlighter.codeToHtml('foo,bar,baz', 'csv')
})

SVG renderer

This would make it easy to:

  • Export to Sketch
  • Capture screenshot in Puppeteer

C# language support

I was looking through the packages\languages\src\lang.ts for c# or csharp, but couldn't find it. Can support be added or should I use a similar language like java? If support can be added, how would I go about that?

I noticed .tmLanguage files are being used, could something from this repo dotnet/csharp-tmlanguage be used?

Is it possible to keep font-weight?

Sample from custom theme for CSS language:

{
	"scope": "keyword.other.important",
	"settings": {
		"fontStyle": "bold",
		"foreground": "#dd4a68"
	}
},

The color #dd4a68 is applied properly, but not the font-weight.

Adobe Illustrator cannot import svg correctly

Notice these black parts, this is because Adobe Illustrator(2020) cannot handle colors with alpha.

style="fill: #D8DEE9FF" must be written as style="fill: #D8DEE9; opacity:1;" or just trim FF.


Adobe XD(2020) also has this problem.

Use theme foreground color when color of token is `undefined`

const main = async () => {
  const shiki = require('shiki')
  const highlighter = await shiki.getHighlighter({ theme: 'monokai' })
  const code = 'whatever'
  const lang = 'txt'
  console.log(highlighter.codeToHtml(code, lang))
}

main()

generates

<pre class="shiki" style="background-color: #272822"><code><span style="color: undefined">whatever</span></code></pre>

TOtherLang not Registering

Getting this error when trying to use any of the following syntax:
| 'bat'
| 'coffeescript'
| 'diff'
| 'dockerfile'
| 'fsharp'
| 'git-commit'
| 'git-rebase'
| 'groovy'
| 'handlebars'
| 'ini'
| 'properties'
| 'perl'
| 'powershell'
| 'razor'
| 'shaderlab'
| 'vb'
| 'cmd'
| 'xsl'

UnhandledPromiseRejectionWarning: Error: No language registration for handlebars

Question: Recommendations on how to handle dark mode

👋 I'm thinking about how to handle dark and light themes, microsoft/TypeScript-Website#342 eventually I'm going to need to figure out how to make a dark mode which uses css classes because these poor dark mode folks have the same code color schema:

Screen Shot 2020-04-09 at 9 39 25 PM

Screen Shot 2020-04-09 at 9 39 17 PM

So, I'm wondering what you think might be the best way to do it (and whether it's something I should do upstream back here)

I have two ideas:

  • Have a single theme, convert the colors hex to css classes
  • Try match two separate themes together

Semantic Highlighter

This one is a bit complicated. Currently I can think of two approaches:

  1. With microsoft/vscode#91375, get semantic highlighting results by running an e2e test that interacts with a real instance of VS Code (and its language servers).
  2. Run VS Code in browser context: https://github.com/Microsoft/vscode/wiki/How-to-Contribute#run and use puppeteer to extract colors. This is kinda far-fetched, but this would mean we neither need to maintain an integration with vscode-textmate nor with the semantic highlighters.

Colors don’t match VS Code

Consider the following:

const shiki = require('shiki')

shiki.getHighlighter({
  theme: 'light_plus'
}).then(highlighter => {
  console.log(highlighter.codeToHtml(`return 'shiki';`, 'js'))
})

This is the result I’m getting:

<pre class="shiki" style="background-color: #fff"><code><span style="color: #0000FF">return</span><span style="color: #000000"> </span><span style="color: #A31515">'shiki'</span><span style="color: #000000">;</span></code></pre>

Screen Shot 2020-03-10 at 12 02 12 AM

But this is what I see in VS Code using the same theme:

Screen Shot 2020-03-10 at 12 03 10 AM

(Note the color of the return keyword.)

Decoration API

Offer a decoration API that allows marking specific ranges with:

  • bg color
  • font settings
  • text decorations
  • links

This is easy to use programmatically.
The hard problem is how should the original Markdown look like.

bundle to a pack

  1. publish to CDN
  2. bundle to a pack
  3. compile with multi module. e.g es6, commonjs, umd, amd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.