# Class: YARD::Templates::Helpers::Markup::HybridMarkdown

Inherits:
  Object
  - Object
  - YARD::Templates::Helpers::Markup::HybridMarkdown
  show all

Defined in:
  lib/yard/templates/helpers/markup/hybrid_markdown.rb

## Overview

A built-in formatter that implements a practical subset of GitHub flavored Markdown plus common RDoc markup forms.

## Constant Summary collapse

ATX_HEADING_RE =

      /^\s{0,3}#{Regexp.escape('#')}{1,6}(?=[ \t]|$)/.freeze

RDOC_HEADING_RE =

      /^\s*(=+)[ \t]+(.+?)\s*$/.freeze

SETEXT_HEADING_RE =

      /^\s{0,3}(=+|-+)\s*$/.freeze

FENCE_RE =

      /^(\s{0,3})(`{3,}|~{3,})([^\n]*)$/.freeze

THEMATIC_BREAK_RE =

      /^\s{0,3}(?:(?:-\s*){3,}|(?:\*\s*){3,}|(?:_\s*){3,})\s*$/.freeze

TABLE_SEPARATOR_RE =

      /^\s*\|?(?:\s*:?-+:?\s*\|)+(?:\s*:?-+:?\s*)\|?\s*$/.freeze

UNORDERED_LIST_RE =

      /^\s{0,3}([*+-])[ \t]+(.+?)\s*$/.freeze

ORDERED_LIST_RE =

      /^\s{0,3}(\d+)([.)])[ \t]+(.+?)\s*$/.freeze

RDOC_ORDERED_LIST_RE =

      /^\s{0,3}([A-Za-z])\.[ \t]+(.+?)\s*$/.freeze

LABEL_LIST_BRACKET_RE =

      /^\s*\[([^\]]+)\](?:[ \t]+(.+))?\s*$/.freeze

LABEL_LIST_COLON_RE =

      /^\s*([^\s:][^:]*)::(?:[ \t]+(.*))?\s*$/.freeze

BLOCKQUOTE_RE =

      /^\s{0,3}>\s?(.*)$/.freeze

HTML_BLOCK_RE =

      %r{
        ^\s*(?:
          <!--|
          <\?|
          <![A-Z]|
          <!\[CDATA\[|
          </?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)\b|
          <(?:script|pre|style|textarea)\b|
          </(?:script|pre|style|textarea)\b|
          </?[A-Za-z][A-Za-z0-9-]*(?:\s+[A-Za-z_:][\w:.-]*(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?)*\s*/?>\s*$
        )
      }mx.freeze

HTML_BLOCK_TAGS =

      %w[
        address article aside base basefont blockquote body caption center col
        colgroup dd details dialog dir div dl dt fieldset figcaption figure
        footer form frame frameset h1 h2 h3 h4 h5 h6 head header hr html iframe
        legend li link main menu menuitem nav noframes ol optgroup option p param
        search section summary table tbody td tfoot th thead title tr track ul
      ].freeze

HTML_TAG_RE =

      %r{
          <!--(?:>|->)|
          <!--(?:.*?)-->|
        <\?.*?\?>|
        <![A-Z][^>]*>|
        <!\[CDATA\[.*?\]\]>|
        </[A-Za-z][A-Za-z0-9-]*\s*>|
        <[A-Za-z][A-Za-z0-9-]*
          (?:\s+[A-Za-z_:][\w:.-]*
            (?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?
          )*
          \s*/?>
      }mx.freeze

ENTITY_RE =

      /&(?:[A-Za-z][A-Za-z0-9]+|#\d+|#[xX][0-9A-Fa-f]+);/.freeze

YARD_LINK_RE =

      /(?<!\\)\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=\W|.+<\/|$)/m.freeze

CODE_LANG_RE =

      /\A(?:[ \t]*\n)?[ \t]*!!!([\w.+-]+)[ \t]*\n/.freeze

REFERENCE_DEF_START_RE =

      /^\s{0,3}\[([^\]]+)\]:\s*(.*)$/.freeze

PLACEHOLDER_RE =

      /\0(\d+)\0/.freeze

ESCAPABLE_CHARS_RE =

      /\\([!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~])/.freeze

RDOC_ESCAPED_CAPITALIZED_CROSSREF_RE =

      /\\((?:::)?(?:[A-Z]\w+|[A-Z]\w*::\w+)(?:::\w+)*)/.freeze

AUTOLINK_RE =

      /<([A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\s]*|[A-Za-z0-9.!#$%&'*+\/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+)>/.freeze

TAB_WIDTH =

      4

## Instance Attribute Summary collapse

- #from_path ⇒ Object

  Returns the value of attribute from_path.

## Instance Method Summary collapse

- #initialize(text, options = {}) ⇒ HybridMarkdown constructor

  A new instance of HybridMarkdown.

- #to_html ⇒ String

  The formatted HTML.

## Constructor Details

### #initialize(text, options = {}) ⇒ `HybridMarkdown`

Returns a new instance of HybridMarkdown.

Parameters:

- text (`String`) —

  the Markdown text to format.

- options (`Hash`) (defaults to: `{}`) —

  options for the formatter.

Options Hash (`options`):

- :heading_ids (`Boolean`) —

  whether to generate id attributes for headings.

    74
    75
    76
    77
    78

    # File 'lib/yard/templates/helpers/markup/hybrid_markdown.rb', line 74

    def initialize(text, options = {})
      @heading_ids = options.fetch(:heading_ids, true)
      @references = {}
      @text = extract_reference_definitions(text.to_s.gsub(/\r\n?/, "\n"))
    end

## Instance Attribute Details

### #from_path ⇒ `Object`

Returns the value of attribute from_path.

    15
    16
    17

    # File 'lib/yard/templates/helpers/markup/hybrid_markdown.rb', line 15

    def from_path
      @from_path
    end

## Instance Method Details

### #to_html ⇒ `String`

Returns the formatted HTML.

Returns:

- (`String`) —

  the formatted HTML.

    81
    82
    83

    # File 'lib/yard/templates/helpers/markup/hybrid_markdown.rb', line 81

    def to_html
      parse_blocks(split_lines(@text), 0).join("\n")
    end