initial commit
This commit is contained in:
commit
577a2e8520
15 changed files with 7194 additions and 0 deletions
28
.eleventy.js
Normal file
28
.eleventy.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import pkg from "./package.json" with { type: "json" };
|
||||
import markdownHighlighter from "./src/giallo-markdown.js";
|
||||
|
||||
/**
|
||||
* Giallo syntax highlighting plugin for Eleventy. Logic distilled from
|
||||
* https://github.com/11ty/eleventy-plugin-syntaxhighlight. Currently supports
|
||||
* markdown blocks only.
|
||||
*/
|
||||
export default function (eleventyConfig, options) {
|
||||
try {
|
||||
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (hasTemplateFormat(options.templateFormats, "md")) {
|
||||
eleventyConfig.addMarkdownHighlighter(markdownHighlighter(options));
|
||||
}
|
||||
}
|
||||
|
||||
function hasTemplateFormat(templateFormats = ["*"], format = false) {
|
||||
const formatsArr = Array.isArray(templateFormats)
|
||||
? templateFormats
|
||||
: [templateFormats];
|
||||
return formatsArr.indexOf("*") > -1 || formatsArr.indexOf(format) > -1;
|
||||
}
|
||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
.helix
|
||||
/giallo-js/build
|
||||
/giallo-js/transpiled
|
||||
/giallo-js/target
|
||||
node_modules
|
||||
8
.npmignore
Normal file
8
.npmignore
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/giallo-js/build
|
||||
/giallo-js/Cargo.lock
|
||||
/giallo-js/Cargo.toml
|
||||
/giallo-js/src
|
||||
/giallo-js/target
|
||||
/mise.toml
|
||||
/node_modules
|
||||
/test
|
||||
287
LICENSE
Normal file
287
LICENSE
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
||||
EUPL © the European Union 2007, 2016
|
||||
|
||||
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
||||
below) which is provided under the terms of this Licence. Any use of the Work,
|
||||
other than as authorised under this Licence is prohibited (to the extent such
|
||||
use is covered by a right of the copyright holder of the Work).
|
||||
|
||||
The Work is provided under the terms of this Licence when the Licensor (as
|
||||
defined below) has placed the following notice immediately following the
|
||||
copyright notice for the Work:
|
||||
|
||||
Licensed under the EUPL
|
||||
|
||||
or has expressed by any other means his willingness to license under the EUPL.
|
||||
|
||||
1. Definitions
|
||||
|
||||
In this Licence, the following terms have the following meaning:
|
||||
|
||||
- ‘The Licence’: this Licence.
|
||||
|
||||
- ‘The Original Work’: the work or software distributed or communicated by the
|
||||
Licensor under this Licence, available as Source Code and also as Executable
|
||||
Code as the case may be.
|
||||
|
||||
- ‘Derivative Works’: the works or software that could be created by the
|
||||
Licensee, based upon the Original Work or modifications thereof. This Licence
|
||||
does not define the extent of modification or dependence on the Original Work
|
||||
required in order to classify a work as a Derivative Work; this extent is
|
||||
determined by copyright law applicable in the country mentioned in Article 15.
|
||||
|
||||
- ‘The Work’: the Original Work or its Derivative Works.
|
||||
|
||||
- ‘The Source Code’: the human-readable form of the Work which is the most
|
||||
convenient for people to study and modify.
|
||||
|
||||
- ‘The Executable Code’: any code which has generally been compiled and which is
|
||||
meant to be interpreted by a computer as a program.
|
||||
|
||||
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
||||
the Work under the Licence.
|
||||
|
||||
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
||||
Licence, or otherwise contributes to the creation of a Derivative Work.
|
||||
|
||||
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
||||
the Work under the terms of the Licence.
|
||||
|
||||
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
||||
renting, distributing, communicating, transmitting, or otherwise making
|
||||
available, online or offline, copies of the Work or providing access to its
|
||||
essential functionalities at the disposal of any other natural or legal
|
||||
person.
|
||||
|
||||
2. Scope of the rights granted by the Licence
|
||||
|
||||
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
||||
sublicensable licence to do the following, for the duration of copyright vested
|
||||
in the Original Work:
|
||||
|
||||
- use the Work in any circumstance and for all usage,
|
||||
- reproduce the Work,
|
||||
- modify the Work, and make Derivative Works based upon the Work,
|
||||
- communicate to the public, including the right to make available or display
|
||||
the Work or copies thereof to the public and perform publicly, as the case may
|
||||
be, the Work,
|
||||
- distribute the Work or copies thereof,
|
||||
- lend and rent the Work or copies thereof,
|
||||
- sublicense rights in the Work or copies thereof.
|
||||
|
||||
Those rights can be exercised on any media, supports and formats, whether now
|
||||
known or later invented, as far as the applicable law permits so.
|
||||
|
||||
In the countries where moral rights apply, the Licensor waives his right to
|
||||
exercise his moral right to the extent allowed by law in order to make effective
|
||||
the licence of the economic rights here above listed.
|
||||
|
||||
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
||||
any patents held by the Licensor, to the extent necessary to make use of the
|
||||
rights granted on the Work under this Licence.
|
||||
|
||||
3. Communication of the Source Code
|
||||
|
||||
The Licensor may provide the Work either in its Source Code form, or as
|
||||
Executable Code. If the Work is provided as Executable Code, the Licensor
|
||||
provides in addition a machine-readable copy of the Source Code of the Work
|
||||
along with each copy of the Work that the Licensor distributes or indicates, in
|
||||
a notice following the copyright notice attached to the Work, a repository where
|
||||
the Source Code is easily and freely accessible for as long as the Licensor
|
||||
continues to distribute or communicate the Work.
|
||||
|
||||
4. Limitations on copyright
|
||||
|
||||
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
||||
any exception or limitation to the exclusive rights of the rights owners in the
|
||||
Work, of the exhaustion of those rights or of other applicable limitations
|
||||
thereto.
|
||||
|
||||
5. Obligations of the Licensee
|
||||
|
||||
The grant of the rights mentioned above is subject to some restrictions and
|
||||
obligations imposed on the Licensee. Those obligations are the following:
|
||||
|
||||
Attribution right: The Licensee shall keep intact all copyright, patent or
|
||||
trademarks notices and all notices that refer to the Licence and to the
|
||||
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
||||
copy of the Licence with every copy of the Work he/she distributes or
|
||||
communicates. The Licensee must cause any Derivative Work to carry prominent
|
||||
notices stating that the Work has been modified and the date of modification.
|
||||
|
||||
Copyleft clause: If the Licensee distributes or communicates copies of the
|
||||
Original Works or Derivative Works, this Distribution or Communication will be
|
||||
done under the terms of this Licence or of a later version of this Licence
|
||||
unless the Original Work is expressly distributed only under this version of the
|
||||
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
||||
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
||||
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
||||
|
||||
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
||||
Works or copies thereof based upon both the Work and another work licensed under
|
||||
a Compatible Licence, this Distribution or Communication can be done under the
|
||||
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
||||
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
||||
Should the Licensee's obligations under the Compatible Licence conflict with
|
||||
his/her obligations under this Licence, the obligations of the Compatible
|
||||
Licence shall prevail.
|
||||
|
||||
Provision of Source Code: When distributing or communicating copies of the Work,
|
||||
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
||||
a repository where this Source will be easily and freely available for as long
|
||||
as the Licensee continues to distribute or communicate the Work.
|
||||
|
||||
Legal Protection: This Licence does not grant permission to use the trade names,
|
||||
trademarks, service marks, or names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the copyright notice.
|
||||
|
||||
6. Chain of Authorship
|
||||
|
||||
The original Licensor warrants that the copyright in the Original Work granted
|
||||
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each Contributor warrants that the copyright in the modifications he/she brings
|
||||
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
||||
power and authority to grant the Licence.
|
||||
|
||||
Each time You accept the Licence, the original Licensor and subsequent
|
||||
Contributors grant You a licence to their contributions to the Work, under the
|
||||
terms of this Licence.
|
||||
|
||||
7. Disclaimer of Warranty
|
||||
|
||||
The Work is a work in progress, which is continuously improved by numerous
|
||||
Contributors. It is not a finished work and may therefore contain defects or
|
||||
‘bugs’ inherent to this type of development.
|
||||
|
||||
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
||||
and without warranties of any kind concerning the Work, including without
|
||||
limitation merchantability, fitness for a particular purpose, absence of defects
|
||||
or errors, accuracy, non-infringement of intellectual property rights other than
|
||||
copyright as stated in Article 6 of this Licence.
|
||||
|
||||
This disclaimer of warranty is an essential part of the Licence and a condition
|
||||
for the grant of any rights to the Work.
|
||||
|
||||
8. Disclaimer of Liability
|
||||
|
||||
Except in the cases of wilful misconduct or damages directly caused to natural
|
||||
persons, the Licensor will in no event be liable for any direct or indirect,
|
||||
material or moral, damages of any kind, arising out of the Licence or of the use
|
||||
of the Work, including without limitation, damages for loss of goodwill, work
|
||||
stoppage, computer failure or malfunction, loss of data or any commercial
|
||||
damage, even if the Licensor has been advised of the possibility of such damage.
|
||||
However, the Licensor will be liable under statutory product liability laws as
|
||||
far such laws apply to the Work.
|
||||
|
||||
9. Additional agreements
|
||||
|
||||
While distributing the Work, You may choose to conclude an additional agreement,
|
||||
defining obligations or services consistent with this Licence. However, if
|
||||
accepting obligations, You may act only on your own behalf and on your sole
|
||||
responsibility, not on behalf of the original Licensor or any other Contributor,
|
||||
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
||||
for any liability incurred by, or claims asserted against such Contributor by
|
||||
the fact You have accepted any warranty or additional liability.
|
||||
|
||||
10. Acceptance of the Licence
|
||||
|
||||
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
||||
placed under the bottom of a window displaying the text of this Licence or by
|
||||
affirming consent in any other similar way, in accordance with the rules of
|
||||
applicable law. Clicking on that icon indicates your clear and irrevocable
|
||||
acceptance of this Licence and all of its terms and conditions.
|
||||
|
||||
Similarly, you irrevocably accept this Licence and all of its terms and
|
||||
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
||||
such as the use of the Work, the creation by You of a Derivative Work or the
|
||||
Distribution or Communication by You of the Work or copies thereof.
|
||||
|
||||
11. Information to the public
|
||||
|
||||
In case of any Distribution or Communication of the Work by means of electronic
|
||||
communication by You (for example, by offering to download the Work from a
|
||||
remote location) the distribution channel or media (for example, a website) must
|
||||
at least provide to the public the information requested by the applicable law
|
||||
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
||||
stored and reproduced by the Licensee.
|
||||
|
||||
12. Termination of the Licence
|
||||
|
||||
The Licence and the rights granted hereunder will terminate automatically upon
|
||||
any breach by the Licensee of the terms of the Licence.
|
||||
|
||||
Such a termination will not terminate the licences of any person who has
|
||||
received the Work from the Licensee under the Licence, provided such persons
|
||||
remain in full compliance with the Licence.
|
||||
|
||||
13. Miscellaneous
|
||||
|
||||
Without prejudice of Article 9 above, the Licence represents the complete
|
||||
agreement between the Parties as to the Work.
|
||||
|
||||
If any provision of the Licence is invalid or unenforceable under applicable
|
||||
law, this will not affect the validity or enforceability of the Licence as a
|
||||
whole. Such provision will be construed or reformed so as necessary to make it
|
||||
valid and enforceable.
|
||||
|
||||
The European Commission may publish other linguistic versions or new versions of
|
||||
this Licence or updated versions of the Appendix, so far this is required and
|
||||
reasonable, without reducing the scope of the rights granted by the Licence. New
|
||||
versions of the Licence will be published with a unique version number.
|
||||
|
||||
All linguistic versions of this Licence, approved by the European Commission,
|
||||
have identical value. Parties can take advantage of the linguistic version of
|
||||
their choice.
|
||||
|
||||
14. Jurisdiction
|
||||
|
||||
Without prejudice to specific agreement between parties,
|
||||
|
||||
- any litigation resulting from the interpretation of this License, arising
|
||||
between the European Union institutions, bodies, offices or agencies, as a
|
||||
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
||||
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
||||
the Functioning of the European Union,
|
||||
|
||||
- any litigation arising between other parties and resulting from the
|
||||
interpretation of this License, will be subject to the exclusive jurisdiction
|
||||
of the competent court where the Licensor resides or conducts its primary
|
||||
business.
|
||||
|
||||
15. Applicable Law
|
||||
|
||||
Without prejudice to specific agreement between parties,
|
||||
|
||||
- this Licence shall be governed by the law of the European Union Member State
|
||||
where the Licensor has his seat, resides or has his registered office,
|
||||
|
||||
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
||||
residence or registered office inside a European Union Member State.
|
||||
|
||||
Appendix
|
||||
|
||||
‘Compatible Licences’ according to Article 5 EUPL are:
|
||||
|
||||
- GNU General Public License (GPL) v. 2, v. 3
|
||||
- GNU Affero General Public License (AGPL) v. 3
|
||||
- Open Software License (OSL) v. 2.1, v. 3.0
|
||||
- Eclipse Public License (EPL) v. 1.0
|
||||
- CeCILL v. 2.0, v. 2.1
|
||||
- Mozilla Public Licence (MPL) v. 2
|
||||
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
||||
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
||||
works other than software
|
||||
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
||||
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
||||
Reciprocity (LiLiQ-R+).
|
||||
|
||||
The European Commission may update this Appendix to later versions of the above
|
||||
licences without producing a new version of the EUPL, as long as they provide
|
||||
the rights granted in Article 2 of this Licence and protect the covered Source
|
||||
Code from exclusive appropriation.
|
||||
|
||||
All other changes or additions to this Appendix require the production of a new
|
||||
EUPL version.
|
||||
50
README.md
Normal file
50
README.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# 11ty-plugin-giallo
|
||||
|
||||
Eleventy plugin to support TextMate-style syntax highlighting via the
|
||||
[Giallo Rust crate](https://github.com/getzola/giallo).
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
// eleventy.config.js
|
||||
|
||||
import syntaxHighlight from "11ty-plugin-giallo";
|
||||
|
||||
export default function (eleventyConfig) {
|
||||
eleventyConfig.addPlugin(syntaxHighlight, {
|
||||
themeLight: "github-light",
|
||||
themeDark: "github-dark",
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Themes
|
||||
|
||||
[Themes included with Giallo](https://github.com/getzola/giallo/blob/master/README.md#themes)
|
||||
|
||||
## Development Quickstart
|
||||
|
||||
[Mise-en-place](https://mise.jdx.dev/) manages dev dependencies and scripts.
|
||||
|
||||
```sh
|
||||
# Installs dev tools (Rust, Node) and automatically downloads WASI-SDK for the
|
||||
# host architecture.
|
||||
mise install
|
||||
|
||||
# Installs Node dependencies.
|
||||
npm install
|
||||
|
||||
# Compiles Rust code into a Wasm component and generates Javascript bindings.
|
||||
mise run build
|
||||
|
||||
# Runs unit tests.
|
||||
mise run test
|
||||
```
|
||||
|
||||
## Limitations
|
||||
|
||||
- Support is currently limited to markdown code blocks. The official Eleventy
|
||||
syntax highlighting plugin also provides Liquid and Nunjucks tags as well as a
|
||||
global Javascript function.
|
||||
- Line highlights and numbers are not yet supported.
|
||||
- Giallo does not support Prism-style diff format.
|
||||
588
giallo-js/Cargo.lock
generated
Normal file
588
giallo-js/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,588 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "giallo"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64ba13360df2c7495bdbd41b74bebcd8dd7f47ccebfbd7c0d5b098187d5ceece"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"onig-regset",
|
||||
"papaya",
|
||||
"rmp-serde",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "giallo-js"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"giallo",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.16.1",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "leb128fmt"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.180"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "onig-regset"
|
||||
version = "6.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "080c4eeac92e475efa2893e52522ee3de48086cdad5fb5f36631a7fcb5293c81"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"onig_sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "onig_sys"
|
||||
version = "69.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7f86c6eef3d6df15f23bcfb6af487cbd2fed4e5581d58d5bf1f5f8b7f6727dc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "papaya"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f92dd0b07c53a0a0c764db2ace8c541dc47320dad97c2200c2a637ab9dd2328f"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"seize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "prettyplease"
|
||||
version = "0.2.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp"
|
||||
version = "0.8.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ba8be72d372b2c9b35542551678538b562e7cf86c3315773cae48dfbfe7790c"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72f81bee8c8ef9b577d1681a70ebbc962c232461e397b22c208c43c04b67a155"
|
||||
dependencies = [
|
||||
"rmp",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "seize"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b55fb86dfd3a2f5f76ea78310a88f96c4ea21a3031f8d212443d56123fd0521"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-encoder"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"
|
||||
dependencies = [
|
||||
"leb128fmt",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-metadata"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"hashbrown 0.15.5",
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wit-bindgen-rust-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-core"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"indexmap",
|
||||
"prettyplease",
|
||||
"syn",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rust-macro"
|
||||
version = "0.51.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-component"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"wasm-encoder",
|
||||
"wasm-metadata",
|
||||
"wasmparser",
|
||||
"wit-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-parser"
|
||||
version = "0.244.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"unicode-xid",
|
||||
"wasmparser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"
|
||||
24
giallo-js/Cargo.toml
Normal file
24
giallo-js/Cargo.toml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[package]
|
||||
name = "giallo-js"
|
||||
version = "0.0.1"
|
||||
edition = "2024"
|
||||
# The EU Public License follows from Giallo, of which a WASM version is bundled
|
||||
# with the library.
|
||||
license = "EUPL-1.2"
|
||||
description = ""
|
||||
|
||||
include = [
|
||||
"src/**/*.rs",
|
||||
"Cargo.toml",
|
||||
"/LICENSE",
|
||||
"/README.md",
|
||||
]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
giallo = { version = "0.2.2", features = ["dump"] }
|
||||
js-sys = "0.3.85"
|
||||
wasm-bindgen = "0.2.108"
|
||||
wit-bindgen = "0.51.0"
|
||||
41
giallo-js/src/lib.rs
Normal file
41
giallo-js/src/lib.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use giallo::{HighlightOptions, HtmlRenderer, Registry, RenderOptions, ThemeVariant};
|
||||
|
||||
mod bindings {
|
||||
//! Generated code derived from the Giallo-JS `world.wit` definition.
|
||||
|
||||
wit_bindgen::generate!({
|
||||
path: "wit/world.wit",
|
||||
});
|
||||
|
||||
use super::GialloJsComponent;
|
||||
export!(GialloJsComponent);
|
||||
}
|
||||
|
||||
struct GialloJsComponent;
|
||||
|
||||
impl bindings::exports::docs::giallo_js::syntax_highlighter::Guest for GialloJsComponent {
|
||||
/// Rudimentary Wasm adapter around the basic
|
||||
/// [Giallo usage example](https://github.com/getzola/giallo/blob/a86755836dc4387056432f63f0b37b2c04b52711/examples/basic.rs).
|
||||
fn render_highlighted(
|
||||
code: String,
|
||||
language: String,
|
||||
theme_light: String,
|
||||
theme_dark: String,
|
||||
) -> Result<String, String> {
|
||||
let mut registry = Registry::builtin().map_err(|err| err.to_string())?;
|
||||
registry.link_grammars();
|
||||
|
||||
let options = HighlightOptions::new(
|
||||
language,
|
||||
ThemeVariant::Dual {
|
||||
light: &theme_light,
|
||||
dark: &theme_dark,
|
||||
},
|
||||
);
|
||||
let highlighted = registry
|
||||
.highlight(&code, &options)
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
Ok(HtmlRenderer::default().render(&highlighted, &RenderOptions::default()))
|
||||
}
|
||||
}
|
||||
14
giallo-js/wit/world.wit
Normal file
14
giallo-js/wit/world.wit
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package docs:giallo-js@0.0.1;
|
||||
|
||||
interface syntax-highlighter {
|
||||
render-highlighted: func(
|
||||
code: string,
|
||||
language: string,
|
||||
theme-light: string,
|
||||
theme-dark: string,
|
||||
) -> result<string, string>;
|
||||
}
|
||||
|
||||
world giallo-js {
|
||||
export syntax-highlighter;
|
||||
}
|
||||
50
mise.toml
Normal file
50
mise.toml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
[tools.node]
|
||||
version = "24.13"
|
||||
|
||||
[tools.rust]
|
||||
version = "1.93"
|
||||
components = "rust-analyzer,rust-docs,rustfmt,clippy"
|
||||
targets = "wasm32-wasip2"
|
||||
|
||||
[tools."github:WebAssembly/wasi-sdk"]
|
||||
version_prefix = "wasi-sdk-"
|
||||
version = "29"
|
||||
postinstall = 'mise run link-wasi "$MISE_TOOL_INSTALL_PATH"'
|
||||
|
||||
[tasks.clean]
|
||||
run = """
|
||||
rm -r ./target || 0
|
||||
rm -r ./transpiled || 0
|
||||
"""
|
||||
dir = "giallo-js"
|
||||
|
||||
[tasks.link-wasi]
|
||||
hide = true
|
||||
description = "[INTERNAL] Symlink the WASI artifacts installed by mise into the project directory."
|
||||
usage = 'arg "<wasi_install_path>"'
|
||||
run = """
|
||||
mkdir -p ./build
|
||||
ln -sf "${usage_wasi_install_path?}" ./build/wasi-sdk
|
||||
"""
|
||||
dir = "giallo-js"
|
||||
|
||||
[tasks.compile]
|
||||
description = "Compile Rust code to wasm component."
|
||||
run = """
|
||||
RUSTFLAGS="-L $(pwd)/build/wasi-sdk/share/wasi-sysroot/lib/wasm32-wasi -lstatic=c++ -lstatic=c++abi" \
|
||||
CC="$(pwd)/build/wasi-sdk/bin/clang" \
|
||||
cargo build --target=wasm32-wasip2
|
||||
"""
|
||||
dir = "giallo-js"
|
||||
|
||||
[tasks.transpile]
|
||||
alias = "build"
|
||||
description = "Generate Javascript bindings for compiled wasm component."
|
||||
depends = [{ task = "compile", args = ["--profile=release"] }]
|
||||
run = "npx @bytecodealliance/jco transpile target/wasm32-wasip2/release/giallo_js.wasm -I sync -o transpiled"
|
||||
dir = "giallo-js"
|
||||
|
||||
[tasks.test]
|
||||
description = "Run Jest tests."
|
||||
depends = [{ task = "transpile" }]
|
||||
run = 'NODE_OPTIONS="$NODE_OPTIONS --experimental-vm-modules" npx jest'
|
||||
5928
package-lock.json
generated
Normal file
5928
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
26
package.json
Normal file
26
package.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "11ty-plugin-giallo",
|
||||
"version": "0.1.0-beta.0",
|
||||
"description": "Eleventy plugin to support TextMate-style syntax highlighting via the Giallo Rust crate.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://forge.secondsystemtech.com/brent/11ty-plugin-giallo"
|
||||
},
|
||||
"license": "EUPL-1.2",
|
||||
"author": "Brent Schroeter (https://brentsch.com)",
|
||||
"type": "module",
|
||||
"main": ".eleventy.js",
|
||||
"scripts": {
|
||||
"test": "mise run test"
|
||||
},
|
||||
"11ty": {
|
||||
"compatibility": ">=3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bytecodealliance/preview2-shim": "^0.17.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bytecodealliance/jco": "^1.15.4",
|
||||
"jest": "^30.2.0"
|
||||
}
|
||||
}
|
||||
26
src/giallo-js.js
Normal file
26
src/giallo-js.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Exports an instance of the transpiled GialloJS `syntaxHighlighter` interface.
|
||||
*
|
||||
* Explicit instantiation can be avoided by transpiling with
|
||||
* `jco --instantiation=async`, but that uses top-level awaits, which can
|
||||
* cause problems for the Eleventy dev server.
|
||||
*/
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname } from "node:path";
|
||||
|
||||
import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation";
|
||||
|
||||
import { instantiate } from "../giallo-js/transpiled/giallo_js.js";
|
||||
|
||||
const { syntaxHighlighter } = instantiate(
|
||||
(path) =>
|
||||
new WebAssembly.Module(
|
||||
readFileSync(
|
||||
`${dirname(import.meta.dirname)}/giallo-js/transpiled/${path}`,
|
||||
),
|
||||
),
|
||||
new WASIShim().getImportObject(),
|
||||
);
|
||||
|
||||
export { syntaxHighlighter };
|
||||
53
src/giallo-markdown.js
Normal file
53
src/giallo-markdown.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { syntaxHighlighter } from "./giallo-js.js";
|
||||
|
||||
export default function (options = {}) {
|
||||
return function (str, language) {
|
||||
// Parse language from code block fence.
|
||||
const split = language.split("/");
|
||||
if (split.length) {
|
||||
language = split.shift();
|
||||
}
|
||||
|
||||
// Attempt to render faithfully to provided options.
|
||||
try {
|
||||
return syntaxHighlighter.renderHighlighted(
|
||||
str,
|
||||
language || "plain",
|
||||
options.themeLight ?? "github-light",
|
||||
options.themeDark ?? "github-dark",
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("Error highlighting syntax with 11ty-plugin-giallo:", err);
|
||||
}
|
||||
|
||||
// Try again, with `language` forced to "plain". This will gracefully handle
|
||||
// errors due to missing grammars.
|
||||
try {
|
||||
return syntaxHighlighter.renderHighlighted(
|
||||
str,
|
||||
"plain",
|
||||
options.themeLight ?? "github-light",
|
||||
options.themeDark ?? "github-dark",
|
||||
);
|
||||
} catch {
|
||||
// no-op: We've already printed the most relevant error message.
|
||||
}
|
||||
|
||||
// Try again, with themes set to known good values. This will gracefully
|
||||
// handle errors due to missing themes.
|
||||
try {
|
||||
return syntaxHighlighter.renderHighlighted(
|
||||
str,
|
||||
"plain",
|
||||
"github-light",
|
||||
"github-dark",
|
||||
);
|
||||
} catch {
|
||||
// no-op: We've already printed the most relevant error message.
|
||||
}
|
||||
|
||||
// If all else fails, rendering nothing is better than rendering potentially
|
||||
// unescaped HTML.
|
||||
return "";
|
||||
};
|
||||
}
|
||||
66
test/giallo-js.test.js
Normal file
66
test/giallo-js.test.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import markdownHighlighter from "../src/giallo-markdown.js";
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
themeLight: "github-light",
|
||||
themeDark: "github-dark",
|
||||
};
|
||||
|
||||
const SNIPPET_JS = `
|
||||
import { readFile } from "node:fs";
|
||||
|
||||
/**
|
||||
* Print contents of a file.
|
||||
*/
|
||||
export default async function printFile(path) {
|
||||
const text = await readFile(path, "utf-8");
|
||||
console.log(text);
|
||||
}
|
||||
`;
|
||||
const RENDERED_JS =
|
||||
`<pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);"><code data-lang="javascript"><span class="giallo-l"></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#D73A49, #F97583);">import</span><span> {</span><span> readFile</span><span> }</span><span style="color: light-dark(#D73A49, #F97583);"> from</span><span style="color: light-dark(#032F62, #9ECBFF);"> "</span><span style="color: light-dark(#032F62, #9ECBFF);">node:fs</span><span style="color: light-dark(#032F62, #9ECBFF);">"</span><span>;</span></span>
|
||||
<span class="giallo-l"></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#6A737D, #6A737D);">/**</span></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#6A737D, #6A737D);"> * Print contents of a file.</span></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#6A737D, #6A737D);"> */</span></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#D73A49, #F97583);">export</span><span style="color: light-dark(#D73A49, #F97583);"> default</span><span style="color: light-dark(#D73A49, #F97583);"> async</span><span style="color: light-dark(#D73A49, #F97583);"> function</span><span style="color: light-dark(#6F42C1, #B392F0);"> printFile</span><span>(</span><span style="color: light-dark(#E36209, #FFAB70);">path</span><span>)</span><span> {</span></span>
|
||||
<span class="giallo-l"><span style="color: light-dark(#D73A49, #F97583);"> const</span><span style="color: light-dark(#005CC5, #79B8FF);"> text</span><span style="color: light-dark(#D73A49, #F97583);"> =</span><span style="color: light-dark(#D73A49, #F97583);"> await</span><span style="color: light-dark(#6F42C1, #B392F0);"> readFile</span><span>(</span><span>path</span><span>,</span><span style="color: light-dark(#032F62, #9ECBFF);"> "</span><span style="color: light-dark(#032F62, #9ECBFF);">utf-8</span><span style="color: light-dark(#032F62, #9ECBFF);">"</span><span>)</span><span>;</span></span>
|
||||
<span class="giallo-l"><span> console</span><span>.</span><span style="color: light-dark(#6F42C1, #B392F0);">log</span><span>(</span><span>text</span><span>)</span><span>;</span></span>
|
||||
<span class="giallo-l"><span>}</span></span></code></pre>`;
|
||||
const RENDERED_JS_PLAIN =
|
||||
`<pre class="giallo" style="color-scheme: light dark; color: light-dark(#24292E, #E1E4E8); background-color: light-dark(#FFFFFF, #24292E);"><code data-lang="plain"><span class="giallo-l"></span>
|
||||
<span class="giallo-l"><span>import { readFile } from "node:fs";</span></span>
|
||||
<span class="giallo-l"></span>
|
||||
<span class="giallo-l"><span>/**</span></span>
|
||||
<span class="giallo-l"><span> * Print contents of a file.</span></span>
|
||||
<span class="giallo-l"><span> */</span></span>
|
||||
<span class="giallo-l"><span>export default async function printFile(path) {</span></span>
|
||||
<span class="giallo-l"><span> const text = await readFile(path, "utf-8");</span></span>
|
||||
<span class="giallo-l"><span> console.log(text);</span></span>
|
||||
<span class="giallo-l"><span>}</span></span></code></pre>`;
|
||||
|
||||
const SNIPPET_PY = `print(f"<a>{my_fn('')}</a>")`;
|
||||
|
||||
test("renders Javascript code as arbitrary HTML", () => {
|
||||
const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS);
|
||||
const rendered = configuredHighlighter(SNIPPET_JS, "javascript");
|
||||
expect(rendered).toContain("<");
|
||||
});
|
||||
|
||||
test("renders Javascript code as expected HTML", () => {
|
||||
const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS);
|
||||
const rendered = configuredHighlighter(SNIPPET_JS, "javascript");
|
||||
expect(rendered).toEqual(RENDERED_JS);
|
||||
});
|
||||
|
||||
test("treats unknown language as plain", () => {
|
||||
const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS);
|
||||
const rendered = configuredHighlighter(SNIPPET_JS, "piedpiperscript");
|
||||
expect(rendered).toEqual(RENDERED_JS_PLAIN);
|
||||
});
|
||||
|
||||
test("escapes embedded HTML", () => {
|
||||
const configuredHighlighter = markdownHighlighter(DEFAULT_OPTIONS);
|
||||
const rendered = configuredHighlighter(SNIPPET_PY, "python");
|
||||
expect(rendered).toContain("<a>");
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue