smartc-assembly-highlight
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

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:

const Config = {
    preAll: '',
    preLine: '',
    preInstruction: '',
    postAll: '',
    postLine: '<br>',
    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:

import sah from 'smartc-assembly-highlight'

const sourceCode = `^declare a

SET @a #0000000000000001
INC @a
FIN
`

sah.Config.preAll = '<table><tbody>';
sah.Config.preLine = '<tr><td>Line: %line%</td><td>';
sah.Config.postLine = '</td></tr>';
sah.Config.postAll = '</tbody></table>';

const highlighted = sah.colorText(sourceCode);

The following stylesheet is recomended:

.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:

<script src='https://cdn.jsdelivr.net/npm/smartc-assembly-highlight/dist/index-min.js'></script>

Then, just use the global variable in your script:

const highlighted = sah.colorText(sourceCode);

Package Sidebar

Install

npm i smartc-assembly-highlight

Weekly Downloads

8

Version

1.1.2

License

BSD-3-Clause

Unpacked Size

37.9 kB

Total Files

6

Last publish

Collaborators

  • deleterium