Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 27, 2025. It is now read-only.
/jquery-syntaxPublic archive

jQuery.Syntax is a light-weight client-side syntax highlighter.

NotificationsYou must be signed in to change notification settings

ioquatix/jquery-syntax

Repository files navigation

⚠️ ARCHIVED: This project has been superseded bysyntax-js (npm:@socketry/syntax). The new version is a modern, zero-dependency ES module implementation without jQuery. Please use the new package for new projects.

jQuery.Syntax is a light-weight client-side syntax highlighter, which dynamically loads external dependencies (JavaScript & CSS) when required. It uses jQuery to make it cross-browser compatible and to simplify integration and integration with other systems.

Motivation

jQuery.Syntax was built at a time when syntax highlighting on the web was a bit of a mess - browser incompatibilities and limitations made it hard to do the right thing consistently. Rather than a single definition of "good", presenting code nicely in a browser was dictated by a set of trade-offs.

At the time, syntax highlighters were often all-or-nothing - this made it cumbersome for sites that only had a few pages with code on them. jQuery.Syntax was designed from the ground up to use dynamic loading of assets when required. On top of that, the implementation was built using a profiler and is fairly efficient.

It's a good library and it's fast, that's why I continue to maintain and develop it.

Isn't jQuery big?

Your right, small is pretty subjective.

jQuery as a dependency is based on a design from 2012. When browsers were a bit less "compatible", this was a good trade-off. These days, it could probably be removed, but it isn't worth the effort and for me personally it's a zero-cost dependency since I use it anyway on most of my sites.

The library is modular and only loads exactly the CSS and JS required. The minimised and gzipped library is 1.6Kbytes, this provide the top-level API and the dynamic loading functionality.

To highlight anything, you need to load the core parser and renderer code. It's 4.1Kbytes minified and gzipped. The CSS and Script files are tiny, most less < 1Kbyte, per language.

Compared to xyz?

All syntax highlighters are pretty good these days. But, there are some key differences worth considering:

  • How much does it load by default, even when not highlighting anything?
  • How efficient/fast is it when highlighting code?
  • How does line wrapping work?
  • Can you embed<span> and<a> elements?
  • Can it handle embedded code (e.g. JavaScript inside HTML)?
  • Is it easy to install?
  • Is it easy to customize?

Installation

jQuery.Syntax is easily installed usingnpm.

$ npm install jquery-syntax

It has adist/ directory which follows standard conventions.

Advanced Configuration

jQuery.Syntax compiles and minifies it's code using usesbake (Ruby) andSass. Please review the includedbake.rb andinstall.yaml for more details.

Usage

jQuery.Syntax is typically used to highlight both block code elements and inline code elements. To highlight code, you first need to include several scripts in the<head> of your page:

<!-- Put in your head tag --><script src="jquery.min.js"></script><script src="jquery.syntax.min.js"></script><script type="text/javascript">// This function is executed when the page has finished loading.jQuery(function($) {$.syntax({theme: 'bright'});});</script><!-- Your code to highlight --><pre><code>puts "Hello World"</code></pre>

Stylesheet Compatibility

The following stylesheet sets some useful defaults and enables responsive tab-size indentation.

html {font-size:16px;/* Fix odd text-size in `display: flex` elements on Safari iOS */text-size-adjust:100%;-webkit-text-size-adjust:100%;}@media (min-width:40em) {html {font-size:18px;--tab-size:4;}}@media (min-width:80em) {html {font-size:20px;--tab-size:4;}}pre {/* -moz-tab-size is still required by Firefox */--tab-size:2;tab-size:var(--tab-size);-moz-tab-size:var(--tab-size);}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Released under the MIT license.

Copyright, 2011-2020, bySamuel G. D. Williams.

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.

About

jQuery.Syntax is a light-weight client-side syntax highlighter.

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp