Skip to content

Commit

Permalink
added sh,zsh as shell alias; language aliases defined via static meth…
Browse files Browse the repository at this point in the history
…od within support files
  • Loading branch information
AndiDittrich committed Aug 14, 2019
1 parent d63b6c5 commit 8917577
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 47 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

* Added: additional css classes can be added to the outer container
* Added: css classes of the origin element can be copied to the outer container (disabled by default)
* Added: additional shell script aliases `sh` and `zsh` - feature requested [on GitHub](https://github.com/EnlighterJS/Plugin.WordPress/issues/183)
* Changed: language aliases moved into language support files as static method
* Changed: language instances are initialized via factory
* Bugfix: rawcode on doubleclick doesn't work - event handler name typo
* Bugfix: removed invalid c# annoation symbol #76

Expand Down
2 changes: 1 addition & 1 deletion dist/enlighterjs.min.js

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions src/engine/alias.js

This file was deleted.

23 changes: 7 additions & 16 deletions src/engine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@
import {getOption} from '../engine/options';

// Container of Language Engines
import * as _languages from '../lang/index';
//import * as _languages from '../lang/index';

// Languages aliases
import _languageAliases from './alias';
import {getInstance} from './language-resolver';

// Container of Views/Layouts
import * as _views from '../ui/views/index';

// helper function to process aliases
function getLanguage(lang){
// transform to lowercase
lang = (lang || '').toLowerCase();

// alias used ?
lang = _languageAliases[lang] || lang;

// language available ?
return (_languages[lang] ? lang : null);
}

// helper funtion
function getLayout(name){
// transform to lowercase
Expand All @@ -53,10 +41,13 @@ export function render(dataset){
}

// use given language - including generic fallback
const languageIdentifier = getLanguage(params.language) || getLanguage(getOption('language')) || 'generic';
//const languageIdentifier = getLanguage(params.language) || getLanguage(getOption('language')) || 'generic';

// create language engine instance
//const languageProcessor = new _languages[languageIdentifier];

// create language engine instance
const languageProcessor = new _languages[languageIdentifier];
const languageProcessor = getInstance(params.language, getOption('language'));

// apply language processor
return {
Expand Down
68 changes: 68 additions & 0 deletions src/engine/language-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2019 Andi Dittrich <https://andidittrich.de>
// ----------------------------------------------------------------------

// Container of Language Engines
import * as _languages from '../lang/index';

// internal alias list with default mappings
const _aliasList = {
'standard': 'generic'
};

// flag
let _aliasListGenerated = false;

// helper function to process aliases
function resolveAlias(lang){
// alias list generated ?
if (!_aliasListGenerated){
// set flag
_aliasListGenerated = true;

// process each language support file
for (const name in _languages){
// alias available ?
if (typeof _languages[name].alias !== 'function'){
continue;
}

// get available aliases
const aliases = _languages[name].alias();

// process
for (const alias of aliases){
// assign alias to language filename
_aliasList[alias] = name;
}
}
}

// resolve
return _aliasList[lang];
}

// lookup alias
export function getLanguage(lang){
// transform to lowercase
lang = (lang || '').toLowerCase();

// alias used ?
lang = resolveAlias(lang) || lang;

// language available ?
return (_languages[lang] ? lang : null);
}

// create new instance
export function getInstance(name1, name2){
// use given language - including generic fallback
const languageIdentifier = getLanguage(name1) || getLanguage(name2) || 'generic';

// create language engine instance
return new _languages[languageIdentifier];
}
7 changes: 6 additions & 1 deletion src/lang/assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import {generic} from './generic';
// Author: [Andi Dittrich]
// --
export class assembly extends generic {


// language aliases
static alias(){
return ['asm'];
}

setupLanguage(){

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/avr-assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class avrassembly extends generic{

// language aliases
static alias(){
return ['avrasm'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class cpp extends generic {

// language aliases
static alias(){
return ['c++', 'c'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/csharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import _microTokenizer from '../engine/micro-tokenizer';
// --
export class csharp extends generic {

// language aliases
static alias(){
return ['c#'];
}

setupLanguage() {

// template strings. Stage-2 Analyzing
Expand Down
5 changes: 5 additions & 0 deletions src/lang/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class css extends generic {

// language aliases
static alias(){
return ['styles'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/dockerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class dockerfile extends generic {

// language aliases
static alias(){
return ['docker'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class go extends generic {

// language aliases
static alias(){
return ['golang'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class ini extends generic {

// language aliases
static alias(){
return ['conf', 'cnf'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import _microTokenizer from '../engine/micro-tokenizer';
// --
export class javascript extends generic{

// language aliases
static alias(){
return ['js'];
}

setupLanguage(){
// escape sequences within strings. Stage-2 Analyzing
function parseEscapeSeq(token){
Expand Down
5 changes: 5 additions & 0 deletions src/lang/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {generic} from './generic';
// --
export class markdown extends generic {

// language aliases
static alias(){
return ['md', 'gfm'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class python extends generic {

// language aliases
static alias(){
return ['py'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {css} from './css';
// --
export class scss extends css {

// language aliases
static alias(){
return ['sass'];
}

setupLanguage(){
// setup css
super.setupLanguage();
Expand Down
5 changes: 5 additions & 0 deletions src/lang/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class shell extends generic {

// language aliases
static alias(){
return ['bash', 'sh', 'zsh'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/visual-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import {generic} from './generic';
// --
export class visualbasic extends generic {

// language aliases
static alias(){
return ['vb'];
}

setupLanguage() {

this.rules = [
Expand Down
5 changes: 5 additions & 0 deletions src/lang/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import _microTokenizer from '../engine/micro-tokenizer';
// --
export class xml extends generic {

// language aliases
static alias(){
return ['html'];
}

setupLanguage(){

// xml attributes. Stage-2 Analyzing
Expand Down

0 comments on commit 8917577

Please sign in to comment.