Skip to content

Commit

Permalink
Merge pull request #34 from starknet-io/add_solidity_highlighting
Browse files Browse the repository at this point in the history
Added support for Solidity using highlightjs-solidity: https://www.np…
  • Loading branch information
stoobie authored Feb 29, 2024
2 parents faea657 + 5914952 commit 598d858
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
Binary file modified build/ui-bundle.zip
Binary file not shown.
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"dependencies": {
"caniuse-lite": "^1.0.30001457",
"core-js": "^3.0.0"
"core-js": "^3.0.0",
"highlightjs-solidity": "^2.0.6"
}
}
53 changes: 53 additions & 0 deletions preview-src/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Voila!

How about some code?

.Cairo code
[source,cairo]
----
#[cfg(test)]
Expand All @@ -87,6 +88,58 @@ mod tests {
}
----

.Solidity code
[source,solidity]
----
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.9.0;
library Balances {
function move(mapping(address => uint256) storage balances, address from, address to, uint amount) internal {
require(balances[from] >= amount);
require(balances[to] + amount >= balances[to]);
balances[from] -= amount;
balances[to] += amount;
}
}
contract Token {
mapping(address => uint256) balances;
using Balances for *;
mapping(address => mapping(address => uint256)) allowed;
event Transfer(address from, address to, uint amount);
event Approval(address owner, address spender, uint amount);
function transfer(address to, uint amount) external returns (bool success) {
balances.move(msg.sender, to, amount);
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint amount) external returns (bool success) {
require(allowed[from][msg.sender] >= amount);
allowed[from][msg.sender] -= amount;
balances.move(from, to, amount);
emit Transfer(from, to, amount);
return true;
}
function approve(address spender, uint tokens) external returns (bool success) {
require(allowed[msg.sender][spender] == 0, "");
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function balanceOf(address tokenOwner) external view returns (uint balance) {
return balances[tokenOwner];
}
}
----

.JavaScript code
[,js]
----
vfs
Expand Down
2 changes: 2 additions & 0 deletions src/js/vendor/highlight.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict'

const hljsDefineCairo = require('highlightjs-cairo'); // Require the highlightjs-cairo module
const hljsDefineSolidity = require('highlightjs-solidity'); // Require the highlightjs-solidity module

var hljs = require('highlight.js/lib/highlight')
hljs.registerLanguage('asciidoc', require('highlight.js/lib/languages/asciidoc'))
Expand Down Expand Up @@ -37,6 +38,7 @@
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'))
hljs.registerLanguage('yaml', require('highlight.js/lib/languages/yaml'))
hljsDefineCairo(hljs); // Use the highlightjs-cairo module to define Cairo in hljs
hljsDefineSolidity(hljs); // Use the highlightjs-solidity module to define Solidity in hljs
;[].slice.call(document.querySelectorAll('pre code.hljs[data-lang]')).forEach(function (node) {
hljs.highlightBlock(node)
})
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4085,6 +4085,11 @@
"resolved" "https://registry.npmjs.org/highlightjs-cairo/-/highlightjs-cairo-0.4.0.tgz"
"version" "0.4.0"

"highlightjs-solidity@^2.0.6":
"integrity" "sha512-DySXWfQghjm2l6a/flF+cteroJqD4gI8GSdL4PtvxZSsAHie8m3yVe2JFoRg03ROKT6hp2Lc/BxXkqerNmtQYg=="
"resolved" "https://registry.npmjs.org/highlightjs-solidity/-/highlightjs-solidity-2.0.6.tgz"
"version" "2.0.6"

"hmac-drbg@^1.0.1":
"integrity" "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE="
"resolved" "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz"
Expand Down

0 comments on commit 598d858

Please sign in to comment.