Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deleterium/smartc-assembly-highlight
Module to highlight SmartC assembly text into html with highlight
https://github.com/deleterium/smartc-assembly-highlight
Last synced: 23 days ago
JSON representation
Module to highlight SmartC assembly text into html with highlight
- Host: GitHub
- URL: https://github.com/deleterium/smartc-assembly-highlight
- Owner: deleterium
- License: bsd-3-clause
- Created: 2022-05-12T19:02:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-18T15:39:42.000Z (9 months ago)
- Last Synced: 2024-10-01T15:28:17.375Z (about 1 month ago)
- Language: TypeScript
- Size: 380 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SmartC Assembly Highlight
Converts SmartC assembly source code into HTML with syntax highlighting# Setup
This library can be obtained through npm:
```
npm install smartc-assembly-highlight
```# Usage
Import the library
```
import sah from 'smartc-assembly-highlight';
```Choose the text to be prepended in all output (preAll), prepended in each line (preLine), appended in each line (postLine) and appended in all output (postAll).
In preLine and postLine it is possible to add the string `%line%` that will be replaced for the line number.
Add pad string to indent the lines that are instructions (preInstruction).
You can choose to change the class name for each type of attribute.
This is the default value:
```js
const Config = {
preAll: '',
preLine: '',
preInstruction: '',
postAll: '',
postLine: '
',
spanErrorClass: 'asmError',
spanLabelClass: 'asmLabel',
spanNumberClass: 'asmNumber',
spanCommentClass: 'asmComment',
spanBuiltinClass: 'asmBuiltin',
spanVariableClass: 'asmVariable',
spanDirectiveClass: 'asmDirective',
spanInstructionClass: 'asmInstruction'
}
```To color a entire text use the function `colorText(multiLineText)`. This function will use values set on Config.
To color only one line, use the function `colorLine(justOneLine)`. This function will NOT use values on Config and can be used if you plan to do your own process for each line.
# Example
The following example will create a table and show lines number:```js
import sah from 'smartc-assembly-highlight'const sourceCode = `^declare a
SET @a #0000000000000001
INC @a
FIN
`sah.Config.preAll = '';
sah.Config.preLine = 'Line: %line%';
sah.Config.postLine = '';
sah.Config.postAll = '';const highlighted = sah.colorText(sourceCode);
```
The following stylesheet is recomended:
```css
.asmInstruction { color: mediumblue; }
.asmBuiltin { color: teal; }
.asmVariable { color: purple; }
.asmComment { color: darkgreen; }
.asmLabel { color: sienna; }
.asmNumber { color: red; }
.asmError { background-color: pink; }
.asmDirective {
color: brown;
font-weight: bold;
}
```# Browser usage
You can use jsdelivr.net and import `sah` as global:```html
```
Then, just use the global variable in your script:
```js
const highlighted = sah.colorText(sourceCode);
```