mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Support syntax highlighting for more languages (#771)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
47f81f0da5
commit
87ee97ae5e
8
NOTICE
8
NOTICE
@ -62,6 +62,14 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
Syntaxes in `assets/data/syntect.bin` are generated from syntax definitions
|
||||||
|
which can be found here:
|
||||||
|
https://github.com/sharkdp/bat/tree/master/assets/syntaxes
|
||||||
|
|
||||||
|
The syntax definitions are used under their respective licenses.
|
||||||
|
================================================================================
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
The SIL Open Font License Version 1.1 applies to:
|
The SIL Open Font License Version 1.1 applies to:
|
||||||
|
|
||||||
|
BIN
assets/data/syntect.bin
Normal file
BIN
assets/data/syntect.bin
Normal file
Binary file not shown.
@ -34,7 +34,7 @@ rustybuzz = "0.7"
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
smallvec = "1.10"
|
smallvec = "1.10"
|
||||||
syntect = { version = "5", default-features = false, features = ["default-syntaxes", "regex-fancy"] }
|
syntect = { version = "5", default-features = false, features = ["parsing", "regex-fancy"] }
|
||||||
time = { version = "0.3.20", features = ["formatting"] }
|
time = { version = "0.3.20", features = ["formatting"] }
|
||||||
toml = { version = "0.7.3", default-features = false, features = ["parse"] }
|
toml = { version = "0.7.3", default-features = false, features = ["parse"] }
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
|
@ -313,8 +313,33 @@ fn to_syn(RgbaColor { r, g, b, a }: RgbaColor) -> synt::Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The syntect syntax definitions.
|
/// The syntect syntax definitions.
|
||||||
static SYNTAXES: Lazy<syntect::parsing::SyntaxSet> =
|
///
|
||||||
Lazy::new(syntect::parsing::SyntaxSet::load_defaults_nonewlines);
|
/// Code for syntax set generation is below. The `syntaxes` directory is from
|
||||||
|
/// <https://github.com/sharkdp/bat/tree/master/assets/syntaxes>
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// fn main() {
|
||||||
|
/// let mut builder = syntect::parsing::SyntaxSet::load_defaults_nonewlines().into_builder();
|
||||||
|
/// builder.add_from_folder("syntaxes/02_Extra", false).unwrap();
|
||||||
|
/// syntect::dumps::dump_to_file(&builder.build(), "syntect.bin").unwrap();
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The following syntaxes are disabled due to compatibility issues:
|
||||||
|
/// ```text
|
||||||
|
/// syntaxes/02_Extra/Assembly (ARM).sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/Elixir/Regular Expressions (Elixir).sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/JavaScript (Babel).sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/LiveScript.sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/PowerShell.sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/SCSS_Sass/Syntaxes/Sass.sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/SLS/SLS.sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/VimHelp.sublime-syntax
|
||||||
|
/// syntaxes/02_Extra/cmd-help/syntaxes/cmd-help.sublime-syntax
|
||||||
|
/// ```
|
||||||
|
static SYNTAXES: Lazy<syntect::parsing::SyntaxSet> = Lazy::new(|| {
|
||||||
|
syntect::dumps::from_binary(include_bytes!("../../../assets/data/syntect.bin"))
|
||||||
|
});
|
||||||
|
|
||||||
/// The default theme used for syntax highlighting.
|
/// The default theme used for syntax highlighting.
|
||||||
pub static THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme {
|
pub static THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 43 KiB |
@ -3,6 +3,14 @@
|
|||||||
---
|
---
|
||||||
#set page(width: 180pt)
|
#set page(width: 180pt)
|
||||||
#set text(6pt)
|
#set text(6pt)
|
||||||
|
#show raw: it => rect(
|
||||||
|
width: 100%,
|
||||||
|
inset: (x: 4pt, y: 5pt),
|
||||||
|
radius: 4pt,
|
||||||
|
fill: rgb(239, 241, 243),
|
||||||
|
place(right, text(luma(110), it.lang)) + it,
|
||||||
|
)
|
||||||
|
|
||||||
```typ
|
```typ
|
||||||
= Chapter 1
|
= Chapter 1
|
||||||
#lorem(100)
|
#lorem(100)
|
||||||
@ -11,10 +19,6 @@
|
|||||||
#show heading: emph
|
#show heading: emph
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
#set page(width: 180pt)
|
|
||||||
#set text(6pt)
|
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
/// A carefully designed state machine.
|
/// A carefully designed state machine.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -25,10 +29,6 @@ fn advance(state: State<'_>) -> State<'_> {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
#set page(width: 180pt)
|
|
||||||
#set text(6pt)
|
|
||||||
|
|
||||||
```py
|
```py
|
||||||
import this
|
import this
|
||||||
|
|
||||||
@ -36,10 +36,6 @@ def hi():
|
|||||||
print("Hi!")
|
print("Hi!")
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
|
||||||
#set page(width: 180pt)
|
|
||||||
#set text(6pt)
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@ -48,26 +44,28 @@ int main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
```julia
|
||||||
#set page(width: 180pt)
|
# Add two numbers
|
||||||
#set text(6pt)
|
function add(x, y)
|
||||||
|
return x * y
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
#rect(inset: (x: 4pt, y: 5pt), radius: 4pt, fill: rgb(239, 241, 243))[
|
// Try with some indent.
|
||||||
```html
|
```html
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Topic</h1>
|
<h1>Topic</h1>
|
||||||
<p>The Hypertext Markup Language.</p>
|
<p>The Hypertext Markup Language.</p>
|
||||||
<script>
|
<script>
|
||||||
function foo(a, b) {
|
function foo(a, b) {
|
||||||
return a + b + "string";
|
return a + b + "string";
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
```
|
```
|
||||||
]
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user