kramdown-syntax_tree_sitter 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,8 @@ crate-type = ["cdylib"]
9
9
 
10
10
  [dependencies]
11
11
  anyhow = "*"
12
+ magnus = { version = "*", features = ["embed"] }
12
13
  tree-sitter = "*"
13
14
  tree-sitter-cli = "*"
14
15
  tree-sitter-highlight = "*"
15
16
  tree-sitter-loader = "*"
16
- rutie = "*"
@@ -1,69 +1,19 @@
1
- #[macro_use]
2
- extern crate rutie;
3
-
4
- use rutie::{AnyException, Boolean, Class, Exception, Object, RString, VM};
1
+ use magnus::{exception, function, Error, Ruby};
5
2
 
6
3
  mod tree_sitter_adapter;
7
4
 
8
- class!(TreeSitterAdapter);
9
-
10
- #[rustfmt::skip]
11
- methods!(
12
- TreeSitterAdapter,
13
- _rtself,
14
- fn pub_highlight(
15
- raw_code: RString,
16
- raw_parsers_dir: RString,
17
- raw_scope: RString,
18
- css_classes: Boolean
19
- ) -> RString {
20
- VM::unwrap_or_raise_ex(
21
- tree_sitter_adapter::highlight(
22
- &raw_code.unwrap().to_string(),
23
- &raw_parsers_dir.unwrap().to_string(),
24
- &raw_scope.unwrap().to_string(),
25
- css_classes.unwrap().to_bool(),
26
- )
27
- .as_ref()
28
- .map(String::as_str)
29
- .map(RString::new_utf8)
30
- .map_err(String::as_str)
31
- .map_err(AnyException::new_runtime_error),
32
- )
33
- }
34
- );
35
-
36
- #[no_mangle]
37
- pub extern "C" fn Init_tree_sitter_adapter() {
38
- Class::new("TreeSitterAdapter", None).define(|class_| {
39
- class_.def_self("highlight", pub_highlight);
40
- });
41
- }
42
-
43
- pub trait VMExt {
44
- fn unwrap_or_raise_ex<T, E>(x: Result<T, E>) -> T
45
- where
46
- E: Into<AnyException>;
47
- }
48
-
49
- impl VMExt for VM {
50
- fn unwrap_or_raise_ex<T, E>(result: Result<T, E>) -> T
51
- where
52
- E: Into<AnyException>,
53
- {
54
- result.unwrap_or_else(|e| {
55
- VM::raise_ex(e);
56
- unreachable!();
57
- })
58
- }
59
- }
60
-
61
- pub trait AnyExceptionExt {
62
- fn new_runtime_error(message: &str) -> Self;
5
+ fn pub_highlight(
6
+ code: String,
7
+ parsers_dir: String,
8
+ scope: String,
9
+ css_classes: bool,
10
+ ) -> Result<String, Error> {
11
+ tree_sitter_adapter::highlight(&code, &parsers_dir, &scope, css_classes)
12
+ .map_err(|message| Error::new(exception::runtime_error(), message))
63
13
  }
64
14
 
65
- impl AnyExceptionExt for AnyException {
66
- fn new_runtime_error(message: &str) -> Self {
67
- AnyException::new("RuntimeError", Some(message))
68
- }
15
+ #[magnus::init]
16
+ fn init(ruby: &Ruby) -> Result<(), Error> {
17
+ ruby.define_module("TreeSitterAdapter")?
18
+ .define_module_function("highlight", function!(pub_highlight, 4))
69
19
  }
@@ -60,7 +60,7 @@ fn highlight_configuration<'a>(
60
60
  scope: &'a str,
61
61
  ) -> Result<&'a HighlightConfiguration> {
62
62
  config
63
- .highlight_config(language)
63
+ .highlight_config(language, None)
64
64
  .transpose()
65
65
  .with_context(|| format!("{NO_HIGHLIGHT_ERROR_MSG} '{scope}'"))
66
66
  .flatten_()
@@ -110,7 +110,11 @@ fn render_html(
110
110
  fn highlight_names_for_language(scope: &str, loader: &Loader) -> Result<Vec<String>> {
111
111
  let (language, config) = language_and_configuration(loader, scope)?;
112
112
  let highlight_config = highlight_configuration(language, config, scope)?;
113
- Ok(highlight_config.names().to_vec())
113
+ Ok(highlight_config
114
+ .names()
115
+ .iter()
116
+ .map(ToString::to_string)
117
+ .collect())
114
118
  }
115
119
 
116
120
  fn highlight_names(parser_directory: PathBuf) -> Result<Vec<String>> {
@@ -130,7 +134,7 @@ fn highlight_name_styles() -> HashMap<String, Style> {
130
134
  theme
131
135
  .highlight_names
132
136
  .into_iter()
133
- .zip(theme.styles.into_iter())
137
+ .zip(theme.styles)
134
138
  .collect()
135
139
  }
136
140
 
@@ -45,7 +45,7 @@ module Kramdown
45
45
  'source.toml' => %w[toml],
46
46
  'source.ts' => %w[ts typescript],
47
47
  'source.vhd' => %w[vhdl],
48
- 'text.html.basic' => %w[html],
48
+ 'source.html' => %w[html],
49
49
  'text.html.erb' => %w[erb eruby rhtml]
50
50
  }
51
51
  .map { |scope, aliases| aliases.map { |alias_| [alias_, scope] } }
@@ -5,7 +5,7 @@ module Kramdown
5
5
  module SyntaxHighlighter
6
6
  module TreeSitter
7
7
  # Version of kramdown-syntax_tree_sitter gem
8
- VERSION = '0.5.0'
8
+ VERSION = '0.6.0'
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Even though this project uses Magnus to handle interoperabilty between Ruby and Rust,
4
+ # the Ruby support library for Rutie still happens to work very well for initializing
5
+ # the internal Rust extension for use by this Ruby library
3
6
  require 'rutie'
4
7
 
5
8
  Rutie.new(:tree_sitter_adapter).init(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-syntax_tree_sitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew T. Biehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-18 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.7'
96
+ version: '3.0'
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
@@ -103,9 +103,9 @@ requirements:
103
103
  - |-
104
104
  This plugin is essentially an adapter for the Tree-sitter highlight library and hence requires a compatible Rust installation to function. It is officially compatible with the following environments:
105
105
 
106
- - Rust: 1.66, 1.67, 1.68, 1.69
106
+ - Rust: 1.75, 1.76, 1.77, 1.78
107
107
  - Platforms: MacOS, Linux
108
- rubygems_version: 3.4.1
108
+ rubygems_version: 3.5.9
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Syntax highlight code with Tree-sitter via Kramdown.