Giter Site home page Giter Site logo

ioquatix / jquery-syntax Goto Github PK

View Code? Open in Web Editor NEW
129.0 12.0 27.0 6.26 MB

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

License: MIT License

Ruby 5.67% JavaScript 87.23% CSS 7.10%
syntax-highlighting jquery-syntax jquery javascript

jquery-syntax's Introduction

jQuery.Syntax

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 using bower.

$ bower install jquery-syntax

It has a dist/ directory which follows standard conventions.

Advanced Configuration

jQuery.Syntax compiles and minifies it's code using uses Rake (Ruby) and Sass. Please review the included Rakefile and install.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 class="language-ruby">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, by Samuel G. D. Williams.

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 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 IN THE SOFTWARE.

jquery-syntax's People

Contributors

ioquatix 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

jquery-syntax's Issues

Could not load resource named core

Hi, a javascript returns error
'could not load resource named core' in some occasions. I have tried it with both v1.8 and v1.9.1 (downloaded 4.6.2010).

I have installed script like that:

<script src="../scripts/JQuery/_plugins/jquery-syntax/jquery.syntax.js" type="text/javascript"></script>
<script src="../scripts/JQuery/_plugins/jquery-syntax/jquery.syntax.cache.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" >
    jQuery(function ($) { 

        //syntax
        $.syntax({ root: '../scripts/JQuery/_plugins/jquery-syntax/' });

    });
</script>

in the head section of html.

The code is inside the:

tag.

I get the error either when code tag is present, and when code tag is not present.

If you want more information, contact me to [email protected]

Compatibility fix needed for Angua (workaround provided)

jquery-syntax breaks the dynamic input handling during page edit (resizing the textarea, auto-continuing lists, etc.). I can't figure out why, but the following hack will at least disable jquery-syntax while editing documents:

insert in jquerysyntax/action.php before line 30:
if($_REQUEST['do'] == 'edit' || $_REQUEST['do']['preview']) return;

Naturally, I'd far rather see a proper compatibility fix. But if this is abandonware, at least someone can use this hack to make the problem bearable.

Can't cleanly copy source

This is actually an enhancement request. I'm still on the lookout for a syntax highlighter that doesn't emit the line numbers when the source snippet is copied. GitHub's own syntax highlighter meets this requirement but very few others do. Perhaps GitHub's HTML source can be used as a guideline.

$('#codefile-pre').syntax() doesn't work

Only $.syntax() worked, however with selected jquery object, it doesn't work, even through it's exampled, such as:
$('div.java').syntax({
brush: 'java',
layout: 'fixed',
tabWidth: 8,
replace: true
});

Cannot do advanced installation

This is source just cloned from github.

$ rake install
Using configuration /home/local/ANT/shida/src/git/jquery-syntax/install.yaml
Working in /home/local/ANT/shida/src/git/jquery-syntax/public...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/base...
Copying /home/local/ANT/shida/src/git/jquery-syntax/themes/base/* to "./base"
WARNING on line 14 of /home/local/ANT/shida/src/git/jquery-syntax/public/base/jquery.syntax.brush.css.sass:
This selector doesn't have any properties and will not be rendered.
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/grey...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/base...
Copying /home/local/ANT/shida/src/git/jquery-syntax/themes/grey/* to "./grey"
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/modern...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/base...
Copying /home/local/ANT/shida/src/git/jquery-syntax/themes/modern/* to "./modern"
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/bright...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/grey...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/base...
Copying /home/local/ANT/shida/src/git/jquery-syntax/themes/bright/* to "./bright"
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/paper...
Loading theme from /home/local/ANT/shida/src/git/jquery-syntax/themes/base...
Copying /home/local/ANT/shida/src/git/jquery-syntax/themes/paper/* to "./paper"
WARNING on line 22 of /home/local/ANT/shida/src/git/jquery-syntax/public/paper/jquery.syntax.layout.fixed.sass:
This selector doesn't have any properties and will not be rendered.
WARNING on line 23 of /home/local/ANT/shida/src/git/jquery-syntax/public/paper/jquery.syntax.layout.fixed.sass:
This selector doesn't have any properties and will not be rendered.
*** Written updated cache file jquery.syntax.cache.js ***
/home/local/ANT/shida/src/git/jquery-syntax/ext/jsmin.rb:44:in `>': comparison of String with 126 failed (ArgumentError)
    from /home/local/ANT/shida/src/git/jquery-syntax/ext/jsmin.rb:44:in `isAlphanum'
    from /home/local/ANT/shida/src/git/jquery-syntax/ext/jsmin.rb:169:in `jsmin'
    from /home/local/ANT/shida/src/git/jquery-syntax/ext/jsmin.rb:205:in `<main>'
Install into /home/local/ANT/shida/src/git/jquery-syntax/public finished.

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.