### Home Classes Methods

### In Files

- lib/yard/templates/helpers/markup_helper.rb

### Methods

- ::clear_markup_cache
- #load_markup_provider
- #markup_class
- #markup_file_contents
- #markup_for_file
- #markup_provider

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# YARD::Templates::Helpers::MarkupHelper

Helper methods for loading and managing markup types.

### Constants

MARKUP_EXTENSIONS

  Returns a list of extensions for various markup types. To register extensions for a type, add them to the array of extensions for the type. @since 0.6.0

MARKUP_FILE_SHEBANG

  Contains the Regexp object that matches the shebang line of extra files to detect the markup type.

MARKUP_PROVIDERS

  The default list of markup providers for each markup type

### Attributes

markup_cache[RW]

@return [Hash{Symbol=>{(:provider,:class)=>Object}}] the cached markup providers @private @since 0.6.4

### Public Class Methods

clear_markup_cache() click to toggle source

Clears the markup provider cache information. Mainly used for testing. @return [void]

    # File lib/yard/templates/helpers/markup_helper.rb, line 10
    def clear_markup_cache
      self.markup_cache = {}
    end

### Public Instance Methods

load_markup_provider(type = options.markup) click to toggle source

Attempts to load the first valid markup provider in {MARKUP_PROVIDERS}. If a provider is specified, immediately try to load it.

On success this sets `@markup_provider` and `@markup_class` to the provider name and library constant class/module respectively for the loaded provider.

On failure this method will inform the user that no provider could be found and exit the program.

@return [Boolean] whether the markup provider was successfully loaded.

    # File lib/yard/templates/helpers/markup_helper.rb, line 76
    def load_markup_provider(type = options.markup)
      return true if MarkupHelper.markup_cache[type]
      MarkupHelper.markup_cache[type] ||= {}

      providers = MARKUP_PROVIDERS[type.to_sym]
      return true if providers && providers.empty?
      if providers && options.markup_provider
        providers = providers.select {|p| p[:lib] == options.markup_provider }
      end

      if providers == nil || providers.empty?
        log.error "Invalid markup type '#{type}' or markup provider " +
          "(#{options.markup_provider}) is not registered."
        return false
      end

      # Search for provider, return the library class name as const if found
      providers.each do |provider|
        begin require provider[:lib].to_s; rescue LoadError; next end if provider[:lib]
        begin klass = eval("::" + provider[:const]); rescue NameError; next end
        MarkupHelper.markup_cache[type][:provider] = provider[:lib] # Cache the provider
        MarkupHelper.markup_cache[type][:class] = klass
        return true
      end

      # Show error message telling user to install first potential provider
      name, lib = *[providers.first[:const], providers.first[:lib] || type]
      log.error "Missing '#{lib}' gem for #{type.to_s.capitalize} formatting. Install it with `gem install #{lib}`"
      false
    end

markup_class(type = options.markup) click to toggle source

Gets the markup provider class/module constant for a markup type Call {load_markup_provider} before using this method.

@param [Symbol] type the markup type (:rdoc, :markdown, etc.) @return [Class] the markup class

    # File lib/yard/templates/helpers/markup_helper.rb, line 149
    def markup_class(type = options.markup)
      load_markup_provider(type)
      MarkupHelper.markup_cache[type][:class]
    end

markup_file_contents(contents) click to toggle source

Strips any shebang lines on the file contents that pertain to markup or preprocessing data.

@deprecated Use {CodeObjects::ExtraFileObject#contents} instead @return [String] the file contents minus any preprocessing tags @since 0.6.0

    # File lib/yard/templates/helpers/markup_helper.rb, line 140
    def markup_file_contents(contents)
      contents =~ MARKUP_FILE_SHEBANG ? $' : contents
    end

markup_for_file(contents, filename) click to toggle source

Checks for a shebang or looks at the file extension to determine the markup type for the file contents. File extensions are registered for a markup type in {MARKUP_EXTENSIONS}.

A shebang should be on the first line of a file and be in the form:

    #!markup_type

Standard markup types are text, html, rdoc, markdown, textile

@param [String] contents Unused. Was necessary prior to 0.7.0.

    Newer versions of YARD use {CodeObjects::ExtraFileObject#contents}

@return [Symbol] the markup type recognized for the file @see MARKUP_EXTENSIONS @since 0.6.0

    # File lib/yard/templates/helpers/markup_helper.rb, line 122
    def markup_for_file(contents, filename)
      if contents && contents =~ MARKUP_FILE_SHEBANG # Shebang support
        return $1.to_sym
      end

      ext = (File.extname(filename)[1..-1] || '').downcase
      MARKUP_EXTENSIONS.each do |type, exts|
        return type if exts.include?(ext)
      end
      options.markup
    end

markup_provider(type = options.markup) click to toggle source

Gets the markup provider name for a markup type Call {load_markup_provider} before using this method.

@param [Symbol] type the markup type (:rdoc, :markdown, etc.) @return [Symbol] the markup provider name (usually the gem name of the library)

    # File lib/yard/templates/helpers/markup_helper.rb, line 159
    def markup_provider(type = options.markup)
      MarkupHelper.markup_cache[type][:provider]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.