
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
liburno_elang
Advanced tools
Questa libreria permette ti trasformare il codice sorgente javascript
, sql
,json
, bash
e html
, portando in output codice HTML che con le opportuni css puĂł essere renderizzato da un browser con colori.
Per installare:
npm i liburno_elang
per l'utilizzo, all'interno di un progetto gestito da un package manager
import {elang,controls} from 'liburno_elang'
// id dove inserire l'elemento formattato
var myid="someid"
// codice sorgente da formattare
var src=`
... some code script ....
`
// formattazione
var res=elang(src,"js",true);
// scrittura nel DOM
document.getElementById(myid).innerHTML=res;
L'utilizzo di questo modulo richede la personalizzazione del css: le classi create iniziano sempre con il prefisso elang_
, e ne riporto un esempio.
.elang {
background: none;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.3;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
padding: 0 0;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
padding:8px;
}
.elang_rowid {
font-size: .75rem;
color: #cbd5e0;
margin-right: .75rem
}
.elang_string {
color:red;
}
.elang_json_string1 {
color:blue;
}
.elang_comment {
color:green;
}
.elang_punc {
color: darkcyan;
}
.elang_punc2 {
color: darkslategray;
}
.elang_number {
color: darkgoldenrod;
}
.elang_tag,
.elang_word {
color:purple;
}
.elang_keys {
color:blue;
}
.elang_intag,
.elang_keys2 {
color:darkblue;
}
.elang_sql_keys2 {
color:darkcyan;
text-transform: uppercase;
}
.elang_sql_keys1 {
text-transform: lowercase;
}
.elang_regex {
color:violet;
}
.elang_bash_keys1 {
color: purple;
}
ovviamente, i colori sono arbitrari, ma le classi assegnate ai vari elementi sono arbitrarie, ma per ogni oggetto sono assegnate piĂą classi, ad esempio per una keyword di tipo 2 di javascript le classi saranno:
elang_js_keys2 elang_keys2 elang_js_keys elang_keys
in questo modo basta attivare un CSS a livello specifico per esempio su elang_js_keys2
o generico e indipendente da linguaggio su elang_keys
. La prioritĂ varia con l'ordine di scrittura nel file css.
L'oggetto controls
è una varibile che contiene all'interno le espressioni regolari per la ricerca e sostituzione dei colori. La metodologia utilizzata prevede la ricerca per un linguaggio specifico e in sua assenza per le dichiarazioni generiche.
Riporto per esteso la definizione di controls
:
{
string: /(".*?[^\\]"|'.*?[^\\]'|`[^]*?[^\\]`)/m,
puntuaction: /(-[-=]?|,|;|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3})/g,
parentesis: /(\(|\)|\[|\]|\{|\})/g,
ingraffe: /([^$])(\{)(.*?)(\})/g,
regex: /\/.*?[^\\]\/[gimu]/m,
numbers: /\b((?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?)/gi,
js: {
comments: /(?:(?:^|[^\\:])(\/\/.*)|(?:^|[^\\])(\/\*[\s\S]*?(?:\*\/)))/m,
keyword: /(\b)(as|true|false|async|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)(\b)/g,
keyword2: /(\.\w+|\w+\:)/g
},
json: {
string: /(".*?[^\\]")/m,
string1: /(".*?[^\\]"\s*:)/m,
},
html: {
script: /(<script[\s\S]*?>)([^]*?)(<\/script>)/im,
tag: /\<(!DOCTYPE|\/?\w+)([^]*?)(\/?\>)/im,
intag: /(\b)([\w-]+)(=)/g,
comments: /\<\!--[^]*?--\>/im
},
bash: {
comments: /# .*/,
keyword1: /(^ *|\; *)(\w+)(\b)/g,
keyword: /(\b)(sudo *[\w-]+)(\b)/g
},
python: {
},
sql: {
keyword: '.',
keyword2: /(\b)(FROM|USING|FTS5|NVARCHAR|INTEGER|REAL|BLOB|DELETE|UPDATE|BEGIN|END|ADD|CREATE|CONSTRAINT|ALTER|COLUMN|TABLE|ALL|ASC|BETWEEN|CASE|CHECK|COLUMN|INDEX|VIEW|PROCEDURE|DESC|DISTINTC|DROP|OUTER|INNER|LEFT|JOIN|INSERT|INTO|[NOT ]*NULL|LIMIT|SELECT|ORDER BY|UNION|WHERE)(\b)/gi,
keyword1: /(\b)(COLLATE|NOCASE|DEFAULT|IF [NOT ]*EXISTS|PRIMARY KEY|VALUES|AS)(\b)/gi,
comments: /(?:(?:^|[^\\:])(\/\/.*)|(?:^|[^\\])(\/\*[\s\S]*?(?:\*\/))|(--\s.*))/m
}
}
come si vede, c'è una sezione generica e una specifica per ogni linguaggio. gli oggetti valutati sono nell'ordine di priorità :
l'idea del progetto nasce da voler un evidenziatore di sintassi molto compatto e facilemente estendibile.
Avevo usato prism, che funziona molto bene, ma volevo capire meglio l'evidenziazione di sintassi e cosĂ ho ricostruito questo progetto.
Si è fatto largo uso di ricerca e sostituzione con le espressioni regolari; il progetto non ha dipendenze.
FAQs
language syntax styling lightweight
The npm package liburno_elang receives a total of 3 weekly downloads. As such, liburno_elang popularity was classified as not popular.
We found that liburno_elang demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.