Skip to content

Add PDF syntax to Rouge#2058

Open
petervwyatt wants to merge 16 commits intorouge-ruby:mainfrom
petervwyatt:feature.pdf
Open

Add PDF syntax to Rouge#2058
petervwyatt wants to merge 16 commits intorouge-ruby:mainfrom
petervwyatt:feature.pdf

Conversation

@petervwyatt
Copy link

Please accept this lexer for PDF syntax (a.k.a. "COS syntax").

PDF (Portable Document Format) is an object-based declarative page description language that, in reality, is a random access, binary (non-text) format. It is formally defined by ISO 32000-2:2020 and corrected by errata (please do not refer to outdated legacy Adobe documentation!). However, with care text-centric PDFs (full or portions) can be created such as might be used in documentation. This token-based, forward lexing lexer is not intended to be used with binary real-world PDFs as that is not how real PDFs need to be lexed (this will also likely generate Ruby UTF-8 errors anyway!).

We wish to leverage this Rouge PDF parser upstream in current and future PDF ISO standards and specifications based on AsciiDoc via Metanorma for use with the many code fragment examples in the documentation.

@petervwyatt
Copy link
Author

BTW the PDFs added are fully functional PDFs that will work in products such as Adobe Acrobat Reader. Likely just need to rename with a .pdf extension. Also be careful with EOL conversions out of Github as PDFs are binary files! Normally I'd control this using .gitattributes file with *.pdf binary but because Rouge doesn't use file extensions this isn't possible.

@petervwyatt
Copy link
Author

Failure of linelint is against the 2 different sample functional PDF files in lib/rouge/demos/pdf and spec/visual/samples/pdf. This is because PDFs are not required to have an EOL on their last line (after the %%EOF) and the Rouge grammar must support this, which is why the samples are the way they are. If this is critical to fix then the EOL can be added but there will then be no test to ensure the grammar successfully processes PDFs without the EOL.

Added EOL to last line of PDF to pass linelint CI check used by Rouge. This is not required by real PDF files.
@ronaldtse
Copy link

Maintainers (@pyrmont @tancnle @gfx ), is it possible to help review this? This would greatly help those of us who regularly work with PDF syntaxes.

Thank you!

@pyrmont
Copy link
Contributor

pyrmont commented Sep 10, 2025

I'm sorry, @ronaldtse. I'm no longer a maintainer on this project.

@ronaldtse
Copy link

Apologies for unnecessarily tagging you @pyrmont , thank you for the quick response!

petervwyatt and others added 5 commits March 16, 2026 15:20
Co-authored-by: Jeanine Adkisson <jeanine.adkisson@gmail.com>
Co-authored-by: Jeanine Adkisson <jeanine.adkisson@gmail.com>
Co-authored-by: Jeanine Adkisson <jeanine.adkisson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants