Class: Creole::Parser

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Parser) initialize(text, options = {})

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

- (Object) allowed_schemes

Allowed url schemes Examples: http https ftp ftps



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

def allowed_schemes
  @allowed_schemes
end

- (Object) extensions=(value) (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

- (Object) no_escape=(value) (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

- (Boolean) extensions?



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

def extensions?; @extensions; end

- (Boolean) no_escape?



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

def no_escape?; @no_escape; end

- (Object) to_html

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