File: manpage.rb

package info (click to toggle)
ruby-github-linguist 7.27.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,204 kB
  • sloc: ruby: 1,872; lex: 173; ansic: 35; makefile: 9
file content (42 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Linguist
  module Strategy
    # Detects man pages based on numeric file extensions with group suffixes.
    class Manpage

      # Public: RegExp for matching conventional manpage extensions
      #
      # This is the same expression as that used by `github/markup`
      MANPAGE_EXTS = /\.(?:[1-9](?![0-9])[a-z_0-9]*|0p|n|man|mdoc)(?:\.in)?$/i

      # Public: Use the file extension to match a possible man page,
      # only if no other candidates were previously identified.
      #
      # blob               - An object that quacks like a blob.
      # candidates         - A list of candidate languages.
      #
      # Examples
      #
      #   Manpage.call(FileBlob.new("path/to/file"))
      #
      # Returns:
      #   1. The list of candidates if it wasn't empty
      #   2. An array of ["Roff", "Roff Manpage"] if the file's
      #      extension matches a valid-looking man(1) section
      #   3. An empty Array for anything else
      #
      def self.call(blob, candidates = [])
        return candidates if candidates.any?

        if blob.name =~ MANPAGE_EXTS
          return [
            Language["Roff Manpage"],
            Language["Roff"],
            # Language["Text"] TODO: Uncomment once #4258 gets merged
          ];
        end

        []
      end
    end
  end
end