镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Add smart detection of input language #111

Open

Description

@hackonteur

I would like for coderay to be able to detect the input format by looking at the contents of the file. This would be particularly helpful in conjunction with #110: Add support for input from STDIN; since coderay can't use the file extension in that case.

I have two ideas for how to support this initially:

  • Detect a unified diff style input, for the example of piping a diff to coderay:
diff -U1 foo.txt bar.txt | coderay
  • Add support for Emacs mode hints. So coderay could understand that this means it should treat the input as C:
/* -*- mode: c -*- */

Activity

  1. korny commented on Feb 13, 2013

    @korny
    Member

    I'm trying to understand how Pygments implements this. They seem to send the input to every possible scanner to check and rate it: https://bitbucket.org/birkenfeld/pygments-main/src/157c9feaccb86ac52da3d6b234cad92c85ee419c/pygments/lexers/agile.py?at=default#cl-1008

    What do you think about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions