Class: Creole::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/creole/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Parser

Create a new CreoleParser instance.



57
58
59
60
61
62
# File 'lib/creole/parser.rb', line 57

def initialize(text, options = {})
  @allowed_schemes = %w(http https ftp ftps)
  @text            = text
  @extensions = @no_escape = nil
  options.each_pair {|k,v| send("#{k}=", v) }
end

Instance Attribute Details

#allowed_schemesObject

Allowed url schemes Examples: http https ftp ftps



43
44
45
# File 'lib/creole/parser.rb', line 43

def allowed_schemes
  @allowed_schemes
end

#extensions=(value) ⇒ Object (writeonly)

Non-standard wiki text extensions enabled? E.g. underlined, deleted text etc



47
48
49
# File 'lib/creole/parser.rb', line 47

def extensions=(value)
  @extensions = value
end

#no_escape=(value) ⇒ Object (writeonly)

Disable url escaping for local links Escaping: [[/Test]] –> %2FTest No escaping: [[/Test]] –> Test



53
54
55
# File 'lib/creole/parser.rb', line 53

def no_escape=(value)
  @no_escape = value
end

Instance Method Details

#extensions?Boolean

Returns:

  • (Boolean)


48
# File 'lib/creole/parser.rb', line 48

def extensions?; @extensions; end

#no_escape?Boolean

Returns:

  • (Boolean)


54
# File 'lib/creole/parser.rb', line 54

def no_escape?; @no_escape; end

#to_htmlObject

Convert CCreole text to HTML and return the result. The resulting HTML does not contain <html> and <body> tags.

Example:

parser = CreoleParser.new("**Hello //World//**", :extensions => true)
parser.to_html
   #=> "<p><strong>Hello <em>World</em></strong></p>"


73
74
75
76
77
78
79
# File 'lib/creole/parser.rb', line 73

def to_html
  @out = ''
  @p = false
  @stack = []
  parse_block(@text)
  @out
end