asciidoc-chroma 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +21 -0
  3. data/README.md +28 -0
  4. data/lib/chroma.rb +44 -0
  5. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa95f7923abbbebd3ac620d8a3ccca2cb46577c89b575818645de2da75d6a0c7
4
- data.tar.gz: cdf96a093182dfb8d8e6ee48d841a734ee79e65ff40ff931e2520eb1719249e4
3
+ metadata.gz: 9218b3730372e8669a8c35d7f5920f84f35ad391f2b58de6d25806c259a3659d
4
+ data.tar.gz: d5f094cd6f6ba3279280873e3548e485bc0af62095718806f4be133bd0fed756
5
5
  SHA512:
6
- metadata.gz: 1b02566b33c28121f9802f51bfb3cdadd2f7e875cbb5c8483a59c29e6bef49e5caf4a562de409a75f079d44a7184bee51c4b664b7e5909e7d3b2f669801502d5
7
- data.tar.gz: e430a2ac209a9d5931c8a3ded2a9a7766d5b0d48ba861827aa94c33b6c3dcbde0c6cadfa724c3b152535184b300493cb36152e6e7611158c88d53ac83c56b2c3
6
+ metadata.gz: 9745f7ddd3695cc30f8b7f640f3f2ab5323a23d918e6a48de673e6297cabc50c2a6e2c4b454ff18ad83f34d1714bfc5893f3e185d04e72713cf588a370d701dd
7
+ data.tar.gz: 4e05d87e895ee2e9f77dd4427e543ff0aaac6aeb80d72660311287271fb8a17500fc5c9f50cb62ac318df00d90a3bbb6bd7405116859519aaf4ef7a960346e0e
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Example Owner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Asciidoc Chroma Syntax Highlighter
2
+
3
+ This repository contains a syntax highlighter for Asciidoc files using [Chroma](https://github.com/alecthomas/chroma).
4
+ It is designed to be used in Hugo static site generator to provide syntax highlighting for Asciidoc code blocks in the same way as Markdown.
5
+
6
+ ## Usage
7
+
8
+ To use the Asciidoc Chroma syntax highlighter, follow these steps:
9
+
10
+ 1. Install the Chroma CLI if you haven't already. You can find installation instructions in the [Chroma repository](https://github.com/alecthomas/chroma).
11
+ 2. Install this gem by running:
12
+ ```
13
+ gem install asciidoc-chroma
14
+ ```
15
+ 3. Use the `asciidoc-chroma` extension in your Hugo site configuration to enable syntax highlighting for Asciidoc files.
16
+ 4. Configure the `chroma` syntax highlighter in your Hugo configuration file as needed.
17
+
18
+ ## Release
19
+
20
+ To release a new version of the gem, follow these steps:
21
+ 1. Update the version number in `asciidoc-chroma.gemspec`.
22
+ 2. Commit your changes and tag the new version in Git.
23
+ 3. Push the changes and tags to the remote repository.
24
+ 4. Build and push the gem to RubyGems.org using:
25
+ ```
26
+ gem build asciidoc-chroma.gemspec
27
+ gem push asciidoc-chroma-<version>.gem
28
+ ```
data/lib/chroma.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tempfile'
4
+
5
+ class ChromaSyntaxHighlighter < Asciidoctor::SyntaxHighlighter::Base
6
+ register_for 'chroma'
7
+
8
+ def initialize *args
9
+ super
10
+ end
11
+
12
+ def format node, lang, opts
13
+ if chroma_available?
14
+ source = node.content
15
+ highlighted = highlight(node, source, lang, opts)
16
+ return "<div class=\"highlight\">#{highlighted}</div>"
17
+ else
18
+ raise "ChromaSyntaxHighlighter: 'chroma' command not found."
19
+ end
20
+ super
21
+ end
22
+
23
+ def chroma_available?
24
+ @chroma_available ||= begin
25
+ system('chroma', '--version', out: File::NULL, err: File::NULL)
26
+ true
27
+ rescue Errno::ENOENT
28
+ false
29
+ end
30
+ end
31
+
32
+ def highlight node, source, lang, opts
33
+ Dir.chdir(Dir.mktmpdir) do
34
+ output = IO.popen(['chroma', '--html', '--html-only', "--lexer=#{lang}"], 'r+') do |io|
35
+ io.write(source)
36
+ io.close_write
37
+ io.read
38
+ end
39
+ raise "Chroma failed with status #{$?.exitstatus}" unless $?.success?
40
+ puts "Output from chroma:\n#{output}"
41
+ return output
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoc-chroma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - twobiers
@@ -15,7 +15,10 @@ email:
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
- files: []
18
+ files:
19
+ - LICENSE.txt
20
+ - README.md
21
+ - lib/chroma.rb
19
22
  homepage: https://github.com/twobiers/asciidoc-chroma
20
23
  licenses:
21
24
  - MIT
@@ -30,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
30
33
  requirements:
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: '3.1'
36
+ version: '3.0'
34
37
  required_rubygems_version: !ruby/object:Gem::Requirement
35
38
  requirements:
36
39
  - - ">="