Skip to content

Commit 47db586

Browse files
committed
2 parents 5e9f7b2 + 4205d55 commit 47db586

File tree

5 files changed

+144
-10
lines changed

5 files changed

+144
-10
lines changed

61131example.png

21.1 KB
Loading

LICENSE

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2006, Ivan Sagalaev.
3+
Copyright (c) 2006, Ivan Sagalaev
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without
77
modification, are permitted provided that the following conditions are met:
88

9-
* Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
1111

12-
* Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
1515

16-
* Neither the name of the copyright holder nor the names of its
17-
contributors may be used to endorse or promote products derived from
18-
this software without specific prior written permission.
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
1919

2020
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2121
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ hljs.registerLanguage('iecst', hljsDefineIECST);
3838
hljs.initHighlightingOnLoad();
3939
```
4040

41+
<<<<<<< HEAD
4142
Mark the code you want to highlight with the ST class:
43+
=======
44+
Mark the code you want to highlight with the iecst class:
45+
>>>>>>> 4205d554c722c25964b06bb888ca83de43f425b0
4246
4347
```html
4448
<pre><code class="iecst">...</code></pre>
@@ -87,3 +91,26 @@ class Highlighter extends Component
8791

8892
export default Highlighter;
8993
```
94+
95+
## Example in Markdown-Generated Presentation
96+
#### (using [marp](https://marp.app/))
97+
98+
Craft the IEC 61131 code that is desired and wrap it in a code-block defined with the tripple-backtick (`` ``` ``) and language as `iecst`.
99+
100+
````markdown
101+
```iecst
102+
VAR
103+
test : BOOL := TRUE ;
104+
x : REAL := 5.23;
105+
lx : LREAL;
106+
myString : STRING(255) := 'this is a test string';
107+
END_VAR
108+
IF test THEN
109+
lx := REAL_TO_LREAL( COS(x) );
110+
END_IF
111+
```
112+
````
113+
114+
This will thus render as:
115+
116+
![IEC 61131-3 Example](./61131example.png)

iecst.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* highlight.js Structured Text syntax highlighting definition
3+
*
4+
* @see https://github.com/highlightjs/highlight.js
5+
*
6+
* @package: highlightjs-iecst
7+
* @author: Sergey Romanov <[email protected]>
8+
* @since: 2019-08-02
9+
*
10+
* Description: Structured Text is one of the 6 languages of IEC 61131-3
11+
* standard, for developing PLC programs.
12+
* Category: scripting
13+
*/
14+
15+
var module = module ? module : {}; // shim for browser use
16+
17+
function hljsDefineIECST(hljs) {
18+
return {
19+
aliases: ["iecst", "scl", "stl", "structured-text"],
20+
name: "Structured Text",
21+
case_insensitive: true,
22+
keywords: {
23+
keyword:
24+
"if then end_if elsif else case of end_case " +
25+
"to do by while repeat end_while end_repeat for end_for from " +
26+
"public private protected " +
27+
"or and not xor le ge eq ne ge lt constant return exit at retain non_retain task with until using extend",
28+
title:
29+
"program end_program function end_function function_block end_function_block configuration " +
30+
"end_configuration action end_action transition end_transition type end_type struct end_struct step " +
31+
"end_step initial_step namespace end_namespace channel end_channel library end_library folder end_folder resource end_resource " +
32+
"var var_global end_var var_input VAR_EXTERNAL var_out var_output var_in_out var_temp var_interval var_access var_config method end_method property end_property interface end_interface",
33+
literal: "false true null ",
34+
built_in:
35+
"array pointer int sint dint lint usint uint udint ulint real lreal time date time_of_day date_and_time dt tod wstring string bool byte word dword lword ref_to any_num any_int any_string",
36+
function:
37+
"mod abs acos asin atan cos exp expt ln log sin sqrt tan sel max min limit mux shl shr rol ror indexof sizeof adr ref adrinst bitadr add mul div sub trunc move"
38+
},
39+
contains: [
40+
{
41+
className: "string",
42+
begin: "'",
43+
end: "'",
44+
contains: [hljs.BACKSLASH_ESCAPE, { begin: "''" }],
45+
relevance: 0
46+
},
47+
{
48+
className: "string",
49+
begin: '"',
50+
end: '"',
51+
contains: [hljs.BACKSLASH_ESCAPE, { begin: '""' }],
52+
relevance: 0
53+
},
54+
{
55+
// Conversion Functions *_TO_**
56+
className: "built_in",
57+
begin: "(ANY|BOOL|BYTE|D?L?WORD|L?TIME|DATE|DT|TOD|W?CHAR|W?STRING|U?S?D?L?INT|L?REAL)_TO_(BOOL|BYTE|D?L?WORD|L?TIME|DATE|DT|TOD|W?CHAR|W?STRING|U?S?D?L?INT|L?REAL)"
58+
},
59+
{
60+
// Conversion Functions TO_**
61+
className: "built_in",
62+
begin: "TO_(BOOL|BYTE|D?L?WORD|L?TIME|DATE|DT|TOD|W?CHAR|W?STRING|U?S?D?L?INT|L?REAL)"
63+
},
64+
{
65+
className: "symbol",
66+
begin: "(D|T|DT|TOD)#[0-9:\\-_shmyd]*"
67+
},
68+
{
69+
className: "symbol",
70+
begin: "[a-zA-Z_]+#[a-zA-Z]*"
71+
},
72+
{
73+
className: "symbol",
74+
begin: "[A-Za-z]{1,6}#[0-9_\\.e\\-]*",
75+
relevance: 0
76+
},
77+
{
78+
className: "number",
79+
begin: "[0-9]+#\\-?[0-9_]*",
80+
relevance: 0
81+
},
82+
{
83+
className: "number",
84+
begin: "[a-zA-Z_]+#\\-?[0-9_]*",
85+
relevance: 0
86+
},
87+
{
88+
className: "symbol",
89+
begin: "%(I|Q|M)(X|B|W|D|L)[0-9.]*"
90+
},
91+
{
92+
className: "symbol",
93+
begin: "%(I|Q|M)[0-9.]*"
94+
},
95+
hljs.C_NUMBER_MODE,
96+
hljs.COMMENT("//", "$"),
97+
hljs.C_BLOCK_COMMENT_MODE,
98+
hljs.COMMENT("\\(\\*", "\\*\\)")
99+
]
100+
}
101+
}
102+
103+
module.exports = function(hljs) {
104+
hljs.registerLanguage("iecst", hljsDefineIECST);
105+
};
106+
107+
module.exports.definer = hljsDefineIECST;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"homepage": "https://github.com/highlightjs/highlightjs-structured-text#readme",
3434
"devDependencies": {
35-
"highlight.js": "^10.0.2",
35+
"highlight.js": "^10.4.1",
3636
"jasmine": "^3.5.0"
3737
}
3838
}

0 commit comments

Comments
 (0)