Comments (5)
Hi Patrick,
You might want to try a tool like PDFkit that will convert HTML into a PDF. I'm not sure how well it will carry over the styling, but it's worth a shot.
Nathan.
from coderay.
Hi,
Sorry if this is a bit of strange request! :)
I'm working on a side project where I want to format PDFs with large chunks of source code (thus why I'm interested in using Coderay to do syntax highlighting) but also bits of text, table of contents, index etc - potentially so it could be printed as a book.
So this is why I'm hooking up Coderay to Prawn - I don't think that PDFkit will give me enough flexibility to format a number of source code files into a single PDF with the control I require.
I accept that it's probably such an odd feature that it might not be appropriate to sit within the Coderay gem - I could create a new gem (e.g. coderay-prawn) for it?
I guess what I'm after is a bit of advice on how to use the Coderay Styles system in my PDF encoder - I haven't really been able to figure out how it works and how it's used with the other encoders (e.g. the html one).
Patrick
from coderay.
I could create a new gem (e.g. coderay-prawn) for it?
Definitely the best idea.
I haven't really been able to figure out how it works and how it's used with the other encoders (e.g. the html one).
It's not simple, that's true.
Basically, Scanners call these methods on the given encoder object:
text_token
with text and token kind (a symbol)begin_group
andend_group
with a token kind; this is for nested tokens, like Strings that contain other tokensbegin_line
andend_line
with a token kind; this is mainly for diffs where you have lines that need a background color
Your encoder only needs to react to these calls correctly. Take a look at https://github.com/rubychan/coderay/blob/master/lib/coderay/encoders/json.rb for a simple example.
from coderay.
@metade have you seen this https://github.com/prawnpdf/prawn/blob/master/manual/syntax_highlight.rb
Are you still interested to work on it? I can help. I need it for one project.
from coderay.
I'll close this issue, but if you need my help for creating a separate gem for PDF output, let me know or ask here :-)
from coderay.
Related Issues (20)
- Could the API for CodeRay.scan(dataset, :python).term also allow for some variant that works on the file extension? (e. g. "rb" for ruby files, "py" or python files etc..)
- ActionView::Template::Error (Symbol or String expected, but NilClass given.)
- Elixir Scanner HOT 1
- Regex with slashes are broken for Javascript
- add 1C Enterprise syntax
- Placeholder $ character in prepared statements (SQL) is marked invalid
- Misaligned line numbers in diff files with `line_numbers: :inline` HOT 1
- Install coderay with permission error in macosx HOT 1
- Invalid rdoc option in gemspec
- CodeRay hangs on multi-code in content
- Add support for CakePHP ctp template
- Support for Kotlin
- Coderay breaks with embedded backticks
- Uninitialized constant Coderay (Redmine 4.1)
- $ method in Groovy code is highlighted as error
- ruby 3.0: test/unit/suite.rb fails due to change in flatten behavior for subclass of Array
- Support for C#
- Support for GraphQL
- License? HOT 1
- Can we easily redefine the colours? HOT 1
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 coderay.