Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lexer for emails #1567

Merged
merged 7 commits into from
Oct 13, 2020
Merged

Conversation

smokris
Copy link
Contributor

@smokris smokris commented Jul 22, 2020

This adds a lexer that highlights email headers (From, To, Cc, Bcc, Date, Subject), quoted text, unquoted text, and signatures.

Email isn't a programming language, but nevertheless I think it could be useful for Rouge to highlight email messages — for example, GitLab uses Rouge to highlight code blocks in Markdown, and my team sometimes copy-pastes emails into GitLab comments surrounded by triple-backtick code fences; this highlighter would make those emails easier to read.

@pyrmont pyrmont self-assigned this Jul 22, 2020
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jul 22, 2020
lib/rouge/lexers/email.rb Outdated Show resolved Hide resolved
@pyrmont
Copy link
Contributor

pyrmont commented Jul 22, 2020

I haven't had time to check the spec but I think this needs to be refactored to use start to assign some initial states that will check the headers. Presumably once you get past Subject:, the header keywords no longer apply.

@smokris
Copy link
Contributor Author

smokris commented Jul 22, 2020

Thanks for the feedback, @jneen and @pyrmont! I just pushed some changes to address your comments.

Presumably once you get past Subject:, the header keywords no longer apply.

Good point; I changed it to use separate states for the headers and body text. (We can't rely specifically on the Subject: header since RFC 2822 section 3.6 says "header fields are not guaranteed to be in a particular order". If I understand section 3.5 correctly, it's the double-linebreak that separates the headers from the body.)

lib/rouge/lexers/email.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smokris I made some changes to make the lexer better conform with the RFC. Let me know what you think.

lib/rouge/lexers/email.rb Show resolved Hide resolved
lib/rouge/lexers/email.rb Show resolved Hide resolved
lib/rouge/lexers/email.rb Show resolved Hide resolved
lib/rouge/lexers/email.rb Show resolved Hide resolved
lib/rouge/lexers/email.rb Outdated Show resolved Hide resolved
@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Jul 23, 2020
lib/rouge/lexers/email.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to merge.

@smokris Was there there anything else on your end?

@pyrmont pyrmont merged commit d164794 into rouge-ruby:master Oct 13, 2020
@pyrmont pyrmont removed the author-action The PR has been reviewed but action by the author is needed label Oct 13, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Oct 13, 2020

@smokris I assumed there were no problems and have merged this into master. It will be part of the next release of Rouge, v3.24.0. That's scheduled to go out to Ruby Gems tonight/tomorrow (depending on your time zone). Thanks for the submission!

@smokris
Copy link
Contributor Author

smokris commented Oct 13, 2020

Wonderful. Thanks!

@smokris smokris deleted the feature.email-lexer branch October 13, 2020 01:31
mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
This commit adds a lexer for e-mails. It follows RFC 2822 as well as supporting
quoted lines in the form described in RFC 3676.

Co-authored-by: Michael Camilleri <mike@inqk.net>
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.

3 participants