Sha256: 971e1e9be4d694a0c5188035b30bf9073fff28bed165a63d0fc85f5151eac420

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

module LanguageServer
  module Protocol
    module Interface
      #
      # A `MarkupContent` literal represents a string value which content is interpreted base on its
      # kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds.
      #
      # If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues.
      # See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting
      #
      # Here is an example how such a string can be constructed using JavaScript / TypeScript:
      # ```typescript
      # let markdown: MarkdownContent = {
      # kind: MarkupKind.Markdown,
      # value: [
      # '# Header',
      # 'Some text',
      # '```typescript',
      # 'someCode();',
      # '```'
      # ].join('\n')
      # };
      # ```
      #
      # *Please Note* that clients might sanitize the return markdown. A client could decide to
      # remove HTML from the markdown to avoid script execution.
      #
      class MarkupContent
        def initialize(kind:, value:)
          @attributes = {}

          @attributes[:kind] = kind
          @attributes[:value] = value

          @attributes.freeze
        end

        #
        # The type of the Markup
        #
        # @return [MarkupKind]
        def kind
          attributes.fetch(:kind)
        end

        #
        # The content itself
        #
        # @return [string]
        def value
          attributes.fetch(:value)
        end

        attr_reader :attributes

        def to_hash
          attributes
        end

        def to_json(*args)
          to_hash.to_json(*args)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
language_server-protocol-3.15.0.2 lib/language_server/protocol/interface/markup_content.rb
language_server-protocol-3.15.0.1 lib/language_server/protocol/interface/markup_content.rb
language_server-protocol-3.15.0.0 lib/language_server/protocol/interface/markup_content.rb
language_server-protocol-3.14.0.2 lib/language_server/protocol/interface/markup_content.rb
language_server-protocol-3.14.0.1 lib/language_server/protocol/interface/markup_content.rb
language_server-protocol-3.14.0.0 lib/language_server/protocol/interface/markup_content.rb