Giter Site home page Giter Site logo

PDF encoding support about coderay HOT 5 CLOSED

rubychan avatar rubychan commented on August 17, 2024
PDF encoding support

from coderay.

Comments (5)

nathany avatar nathany commented on August 17, 2024

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.

metade avatar metade commented on August 17, 2024

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.

korny avatar korny commented on August 17, 2024

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 and end_group with a token kind; this is for nested tokens, like Strings that contain other tokens
  • begin_line and end_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.

tchak avatar tchak commented on August 17, 2024

@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.

korny avatar korny commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.