Class: Source2MD::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/source2md/element.rb

Constant Summary collapse

KEY_VALUE_REGEXP =

#+key: value

/^(?:#|\/\/)\+(\S+):\s*(.*)\R?/
PLUGINS =
[
  Formatter::TypeHidden,       # #+hidden: true
  Formatter::TypeMdTitle,      # ## foo ##
  Formatter::TypeCodeInclude,  # #+code_include: path/to/foo.html xml:SAMPLE.xml
  Formatter::TypeRawInclude,   # #+raw_include: path/to/file.txt
  Formatter::TypeParseInclude, # #+parse_include: path/to/file.txt
  Formatter::TypeTitle,        # #+title2: foo
  Formatter::TypeWarn,         # #+warn: foo
  Formatter::TypeAlert,        # #+alert: foo
  Formatter::TypeMethod,       # #+name: foo
  Formatter::TypeTable,        # # |-
  Formatter::TypeSourceBlock,  # #+BEGIN_SRC
  Formatter::TypeText,         # # foo
  Formatter::TypePartialCode,  # 1 + 2 # => 3
  Formatter::TypeElse,
]

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Element

Returns a new instance of Element.



22
23
24
# File 'lib/source2md/element.rb', line 22

def initialize(content)
  @content = content
end

Instance Method Details

#bodyObject



36
37
38
# File 'lib/source2md/element.rb', line 36

def body
  @body ||= @content.remove(KEY_VALUE_REGEXP).rstrip.freeze
end

#headObject



32
33
34
# File 'lib/source2md/element.rb', line 32

def head
  @head ||= @content.scan(KEY_VALUE_REGEXP).to_h.freeze
end

#to_mdObject



26
27
28
29
30
# File 'lib/source2md/element.rb', line 26

def to_md
  object = support_klass.new(self)
  debug_log(object)
  object.to_md
end