Comments (8)
What we can do here is to teach pygments.rb to use preinstalled Pygments (if it is present) instead of the bundled one. This way if user installed Pygments plugins, they will work.
from pygments.rb.
Yeah, this would be great.
from pygments.rb.
I just had to figure this out.. It's actually already possible with some additional work. In my case it was a bit more complicated as I have a language that doesn't have a convenient existing lexer. So here's what I did:
- Created a Pygments lexer locally for my language.
- Created a PIP package from it.. jam_pygments
- Installed with pip by pointing to my local git clone of that.
- Created/registered the plugin lexer in ruby code as
Pygments::Lexer.create name: 'Jam', aliases: ['jam','bjam','b2'], filenames: ['*.jam','Jamfile','Jamroot'], mimetypes: ['text/x-jam']
so that the find function will return it as needed. - Now follow regular use.
For you use case you only need to do steps 3-5 obviously.
HTH
from pygments.rb.
Okay, #46 is about custom styles while this issue is about custom lexers.
from pygments.rb.
Easier workaround:
--- popen.rb.orig 2021-02-17 16:13:18.000000000 +0100
+++ popen.rb 2021-02-17 16:14:02.000000000 +0100
@@ -141,11 +141,7 @@
#
# Returns an array of lexers.
def lexers
- lexer_file = File.expand_path('../../lexers', __dir__)
- raw = File.open(lexer_file, 'rb').read
- Marshal.load(raw)
- rescue Errno::ENOENT
- raise MentosError, 'Error loading lexer file. Was it created and vendored?'
+ lexers!
end
# Public: Get back all available lexers from mentos itself
This makes pygments.rb find lexer plugin installed in this way: https://stackoverflow.com/a/39540683/6013024
The way I found this:
- I've checked which python interpreter is called -> it's normal
python3
- I've checked the lexer plugin is installed for this interpreter -> yes,
from pygments import lexers; lexers.get_lexer_by_name('my')
works - I've added hook to
get_lexer_by_name()
ingems/pygments.rb-2.0.0/vendor/
-> it's not called for "my" language - I've investigated how
pygments.rb
gets the list of lexers -> it reads files in thevendor
version of pygments, ignoring plugins!
Disabling this optimization (listing files instead of asking pygments API) makes normal plugins work.
from pygments.rb.
@rbrich do I understand correctly that you install plugins into Pygments that is bundled inside pygments.rb?
from pygments.rb.
Sort of, but not really. The plugins are standalone Python packages, they don't need to depend on Pygments.
You can have this combination and it works fine:
- python3, without pygments
- a pygments plugin installed in python3's site-packages
- pygments.rb using python3 and its own installation of pygments
The only condition is that python3 is the same interpreter, in all cases. I'm using both Python and Ruby from Homebrew. Pygments.rb was installed with gem, the custom lexer was installed with python3 setup.py install
. The lexer is using plugin structure as described in the SO answer.
from pygments.rb.
Oh, I see. So, bundled Pygments picks up system-wide installed plugins.
from pygments.rb.
Related Issues (20)
- Error installing v1.1.1 on Windows HOT 5
- Mapping for turtle lexer missing in lexers cache file HOT 1
- Broken symlink in gem (find_error.py) HOT 8
- github.py is included in pygments-main HOT 2
- Liquid Exception in markdown format HOT 1
- Reanimate JRuby CI
- Raku support HOT 1
- support pygments >= 2.7.1 HOT 1
- Becoming a maintainer HOT 6
- Set up Rubocop lint checking in CI
- Race condition between watchdog/main thread leads to "Thread killed" on JRuby
- Old-fashioned questions
- Add an API to query underlying Pygments version
- undefined method 'create' HOT 4
- Tests break against python3-pygments (=2.10.0+dfsg-1) HOT 2
- env: python: No such file or directory HOT 2
- Broken pipe error in Mentos HOT 19
- Update pygments to 2.14.0
- Virtual environment Pythons are ignored on Windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygments.rb.